only update same tag if poll trigger is used on new event

pull/167/head
Karolis Rusenas 2018-03-25 23:25:59 +01:00
parent 0d0432bb48
commit a3e59bba18
2 changed files with 46 additions and 1 deletions

View File

@ -11,7 +11,6 @@ import (
log "github.com/sirupsen/logrus"
)
// func (p *Provider) checkUnversionedDeployment(policy types.PolicyType, repo *types.Repository, deployment v1beta1.Deployment) (updated v1beta1.Deployment, shouldUpdateDeployment bool, err error) {
func (p *Provider) checkUnversionedDeployment(policy types.PolicyType, repo *types.Repository, deployment v1beta1.Deployment) (updatePlan *UpdatePlan, shouldUpdateDeployment bool, err error) {
updatePlan = &UpdatePlan{}
@ -28,6 +27,8 @@ func (p *Provider) checkUnversionedDeployment(policy types.PolicyType, repo *typ
"policy": policy,
}).Info("provider.kubernetes.checkVersionedDeployment: keel policy found, checking deployment...")
annotations := deployment.GetAnnotations()
shouldUpdateDeployment = false
for idx, c := range deployment.Spec.Template.Spec.Containers {
@ -61,6 +62,13 @@ func (p *Provider) checkUnversionedDeployment(policy types.PolicyType, repo *typ
continue
}
// if poll trigger is used, also checking for matching versions
if _, ok := annotations[types.KeelPollScheduleAnnotation]; ok {
if eventRepoRef.Tag() != containerImageRef.Tag() {
continue
}
}
// updating image
if containerImageRef.Registry() == image.DefaultRegistryHostname {
c.Image = fmt.Sprintf("%s:%s", containerImageRef.ShortName(), repo.Tag)

View File

@ -121,6 +121,43 @@ func TestProvider_checkUnversionedDeployment(t *testing.T) {
wantShouldUpdateDeployment: false,
wantErr: false,
},
{
name: "different tag name for poll image",
args: args{
policy: types.PolicyTypeForce,
repo: &types.Repository{Name: "gcr.io/v2-namespace/hello-world", Tag: "master"},
deployment: v1beta1.Deployment{
meta_v1.TypeMeta{},
meta_v1.ObjectMeta{
Name: "dep-1",
Namespace: "xxxx",
Annotations: map[string]string{
types.KeelPollScheduleAnnotation: types.KeelPollDefaultSchedule,
},
Labels: map[string]string{
types.KeelPolicyLabel: "all",
},
},
v1beta1.DeploymentSpec{
Template: v1.PodTemplateSpec{
Spec: v1.PodSpec{
Containers: []v1.Container{
v1.Container{
Image: "gcr.io/v2-namespace/hello-world:alpha",
},
},
},
},
},
v1beta1.DeploymentStatus{},
},
},
wantUpdatePlan: &UpdatePlan{
Deployment: v1beta1.Deployment{},
},
wantShouldUpdateDeployment: false,
wantErr: false,
},
{
name: "dockerhub short image name ",
args: args{