Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 17 additions & 4 deletions pkg/argocd/argocd.go
Original file line number Diff line number Diff line change
Expand Up @@ -481,19 +481,32 @@ func SetKustomizeImage(app *v1alpha1.Application, newImage *image.ContainerImage
return nil
}

// ImageIsAllowed checks whether img is declared in image-list annotation
func ImageIsAllowed(img *image.ContainerImage, list *image.ContainerImageList) bool {
for _, i := range *list {
if i.ImageName == img.ImageName {
return true
}
}
return false
}

// GetImagesFromApplication returns the list of known images for the given application
func GetImagesFromApplication(app *v1alpha1.Application) image.ContainerImageList {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not really like such approach, because you change total sense of this function. I think it would be better to add validation here. Either you need rename function and change comment

images := make(image.ContainerImageList, 0)
annotations := app.Annotations
imagesFromAnnotations := parseImageList(annotations)

for _, imageStr := range app.Status.Summary.Images {
image := image.NewFromIdentifier(imageStr)
images = append(images, image)
img := image.NewFromIdentifier(imageStr)
if ImageIsAllowed(img, imagesFromAnnotations) {
images = append(images, img)
}
}

// The Application may wish to update images that don't create a container we can detect.
// Check the image list for images with a force-update annotation, and add them if they are not already present.
annotations := app.Annotations
for _, img := range *parseImageList(annotations) {
for _, img := range *imagesFromAnnotations {
if img.HasForceUpdateOptionAnnotation(annotations) {
img.ImageTag = nil // the tag from the image list will be a version constraint, which isn't a valid tag
images = append(images, img)
Expand Down
3 changes: 3 additions & 0 deletions pkg/argocd/argocd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ func Test_GetImagesFromApplication(t *testing.T) {
ObjectMeta: v1.ObjectMeta{
Name: "test-app",
Namespace: "argocd",
Annotations: map[string]string{
common.ImageUpdaterAnnotation: "nginx:1.12.2,that/image,quay.io/dexidp/dex:v1.23.0",
},
},
Spec: v1alpha1.ApplicationSpec{},
Status: v1alpha1.ApplicationStatus{
Expand Down
104 changes: 71 additions & 33 deletions pkg/argocd/update_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,15 @@ func Test_UpdateApplication(t *testing.T) {
kubeClient := kube.KubernetesClient{
Clientset: fake.NewFakeKubeClient(),
}
annotations := map[string]string{
common.ImageUpdaterAnnotation: "jannfis/foobar:1.0.0",
}
appImages := &ApplicationImages{
Application: v1alpha1.Application{
ObjectMeta: v1.ObjectMeta{
Name: "guestbook",
Namespace: "guestbook",
Name: "guestbook",
Namespace: "guestbook",
Annotations: annotations,
},
Spec: v1alpha1.ApplicationSpec{
Source: &v1alpha1.ApplicationSource{
Expand Down Expand Up @@ -167,11 +171,15 @@ func Test_UpdateApplication(t *testing.T) {
kubeClient := kube.KubernetesClient{
Clientset: fake.NewFakeKubeClient(),
}
annotations := map[string]string{
common.ImageUpdaterAnnotation: "jannfis/foobar:1.0.0,jannfis/barbar:1.0.0",
}
appImages := &ApplicationImages{
Application: v1alpha1.Application{
ObjectMeta: v1.ObjectMeta{
Name: "guestbook",
Namespace: "guestbook",
Name: "guestbook",
Namespace: "guestbook",
Annotations: annotations,
},
Spec: v1alpha1.ApplicationSpec{
Source: &v1alpha1.ApplicationSource{
Expand Down Expand Up @@ -354,11 +362,15 @@ func Test_UpdateApplication(t *testing.T) {
kubeClient := kube.KubernetesClient{
Clientset: fake.NewFakeKubeClient(),
}
annotations := map[string]string{
common.ImageUpdaterAnnotation: "jannfis/foobar:1.0.x",
}
appImages := &ApplicationImages{
Application: v1alpha1.Application{
ObjectMeta: v1.ObjectMeta{
Name: "guestbook",
Namespace: "guestbook",
Name: "guestbook",
Namespace: "guestbook",
Annotations: annotations,
},
Spec: v1alpha1.ApplicationSpec{
Source: &v1alpha1.ApplicationSource{
Expand Down Expand Up @@ -412,14 +424,16 @@ func Test_UpdateApplication(t *testing.T) {
kubeClient := kube.KubernetesClient{
Clientset: fake.NewFakeClientsetWithResources(fixture.NewSecret("foo", "bar", map[string][]byte{"creds": []byte("myuser:mypass")})),
}
annotations := map[string]string{
common.ImageUpdaterAnnotation: "jannfis/foobar:1.0.0",
fmt.Sprintf(common.PullSecretAnnotation, "dummy"): "secret:foo/bar#creds",
}
appImages := &ApplicationImages{
Application: v1alpha1.Application{
ObjectMeta: v1.ObjectMeta{
Name: "guestbook",
Namespace: "guestbook",
Annotations: map[string]string{
fmt.Sprintf(common.PullSecretAnnotation, "dummy"): "secret:foo/bar#creds",
},
Name: "guestbook",
Namespace: "guestbook",
Annotations: annotations,
},
Spec: v1alpha1.ApplicationSpec{
Source: &v1alpha1.ApplicationSource{
Expand Down Expand Up @@ -526,11 +540,15 @@ func Test_UpdateApplication(t *testing.T) {
kubeClient := kube.KubernetesClient{
Clientset: fake.NewFakeKubeClient(),
}
annotations := map[string]string{
common.ImageUpdaterAnnotation: "jannfis/foobar:1.0.1",
}
appImages := &ApplicationImages{
Application: v1alpha1.Application{
ObjectMeta: v1.ObjectMeta{
Name: "guestbook",
Namespace: "guestbook",
Name: "guestbook",
Namespace: "guestbook",
Annotations: annotations,
},
Spec: v1alpha1.ApplicationSpec{
Source: &v1alpha1.ApplicationSource{
Expand Down Expand Up @@ -716,15 +734,17 @@ func Test_UpdateApplication(t *testing.T) {
kubeClient := kube.KubernetesClient{
Clientset: fake.NewFakeKubeClient(),
}
annotations := map[string]string{
common.ImageUpdaterAnnotation: "dummy=jannfis/foobar",
fmt.Sprintf(common.AllowTagsOptionAnnotation, "dummy"): "regexp:^foobar$",
fmt.Sprintf(common.UpdateStrategyAnnotation, "dummy"): "name",
}
appImages := &ApplicationImages{
Application: v1alpha1.Application{
ObjectMeta: v1.ObjectMeta{
Name: "guestbook",
Namespace: "guestbook",
Annotations: map[string]string{
fmt.Sprintf(common.AllowTagsOptionAnnotation, "dummy"): "regexp:^foobar$",
fmt.Sprintf(common.UpdateStrategyAnnotation, "dummy"): "name",
},
Name: "guestbook",
Namespace: "guestbook",
Annotations: annotations,
},
Spec: v1alpha1.ApplicationSpec{
Source: &v1alpha1.ApplicationSource{
Expand Down Expand Up @@ -792,15 +812,17 @@ func Test_UpdateApplication(t *testing.T) {
kubeClient := kube.KubernetesClient{
Clientset: fake.NewFakeKubeClient(),
}
annotations := map[string]string{
common.ImageUpdaterAnnotation: "dummy=jannfis/foobar",
fmt.Sprintf(common.IgnoreTagsOptionAnnotation, "dummy"): "*",
fmt.Sprintf(common.UpdateStrategyAnnotation, "dummy"): "name",
}
appImages := &ApplicationImages{
Application: v1alpha1.Application{
ObjectMeta: v1.ObjectMeta{
Name: "guestbook",
Namespace: "guestbook",
Annotations: map[string]string{
fmt.Sprintf(common.IgnoreTagsOptionAnnotation, "dummy"): "*",
fmt.Sprintf(common.UpdateStrategyAnnotation, "dummy"): "name",
},
Name: "guestbook",
Namespace: "guestbook",
Annotations: annotations,
},
Spec: v1alpha1.ApplicationSpec{
Source: &v1alpha1.ApplicationSource{
Expand Down Expand Up @@ -852,11 +874,15 @@ func Test_UpdateApplication(t *testing.T) {
kubeClient := kube.KubernetesClient{
Clientset: fake.NewFakeKubeClient(),
}
annotations := map[string]string{
common.ImageUpdaterAnnotation: "example.io/jannfis/example:1.0.x",
}
appImages := &ApplicationImages{
Application: v1alpha1.Application{
ObjectMeta: v1.ObjectMeta{
Name: "guestbook",
Namespace: "guestbook",
Name: "guestbook",
Namespace: "guestbook",
Annotations: annotations,
},
Spec: v1alpha1.ApplicationSpec{
Source: &v1alpha1.ApplicationSource{
Expand Down Expand Up @@ -905,11 +931,15 @@ func Test_UpdateApplication(t *testing.T) {
kubeClient := kube.KubernetesClient{
Clientset: fake.NewFakeKubeClient(),
}
annotations := map[string]string{
common.ImageUpdaterAnnotation: "jannfis/foobar:1.0.0",
}
appImages := &ApplicationImages{
Application: v1alpha1.Application{
ObjectMeta: v1.ObjectMeta{
Name: "guestbook",
Namespace: "guestbook",
Name: "guestbook",
Namespace: "guestbook",
Annotations: annotations,
},
Spec: v1alpha1.ApplicationSpec{
Source: &v1alpha1.ApplicationSource{
Expand Down Expand Up @@ -961,11 +991,15 @@ func Test_UpdateApplication(t *testing.T) {
kubeClient := kube.KubernetesClient{
Clientset: fake.NewFakeKubeClient(),
}
annotations := map[string]string{
common.ImageUpdaterAnnotation: "jannfis/foobar:1.0.0",
}
appImages := &ApplicationImages{
Application: v1alpha1.Application{
ObjectMeta: v1.ObjectMeta{
Name: "guestbook",
Namespace: "guestbook",
Name: "guestbook",
Namespace: "guestbook",
Annotations: annotations,
},
Spec: v1alpha1.ApplicationSpec{
Source: &v1alpha1.ApplicationSource{
Expand Down Expand Up @@ -1017,11 +1051,15 @@ func Test_UpdateApplication(t *testing.T) {
kubeClient := kube.KubernetesClient{
Clientset: fake.NewFakeKubeClient(),
}
annotations := map[string]string{
common.ImageUpdaterAnnotation: "jannfis/foobar:stable",
}
appImages := &ApplicationImages{
Application: v1alpha1.Application{
ObjectMeta: v1.ObjectMeta{
Name: "guestbook",
Namespace: "guestbook",
Name: "guestbook",
Namespace: "guestbook",
Annotations: annotations,
},
Spec: v1alpha1.ApplicationSpec{
Source: &v1alpha1.ApplicationSource{
Expand Down