Skip to content

Commit 8b13249

Browse files
committed
fix: filter images by image-list annotation
Signed-off-by: Cyril MARIN <marin.cyril@gmail.com>
1 parent 7d93c7a commit 8b13249

File tree

4 files changed

+93
-43
lines changed

4 files changed

+93
-43
lines changed

Dockerfile

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,9 @@ FROM alpine:latest
1414

1515
RUN apk update && \
1616
apk upgrade && \
17-
apk add ca-certificates git openssh-client python3 py3-pip tini && \
18-
pip3 install --upgrade pip && \
19-
pip3 install awscli && \
20-
rm -rf /var/cache/apk/*
17+
apk add --no-cache aws-cli ca-certificates git openssh-client tini
2118

22-
RUN mkdir -p /usr/local/bin
23-
RUN mkdir -p /app/config
19+
RUN mkdir -p /usr/local/bin /app/config
2420
RUN adduser --home "/app" --disabled-password --uid 1000 argocd
2521

2622
COPY --from=builder /src/argocd-image-updater/dist/argocd-image-updater /usr/local/bin/

pkg/argocd/argocd.go

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -481,19 +481,32 @@ func SetKustomizeImage(app *v1alpha1.Application, newImage *image.ContainerImage
481481
return nil
482482
}
483483

484+
// ImageIsAllowed checks whether img is declared in image-list annotation
485+
func ImageIsAllowed(img *image.ContainerImage, list *image.ContainerImageList) bool {
486+
for _, i := range *list {
487+
if i.ImageName == img.ImageName {
488+
return true
489+
}
490+
}
491+
return false
492+
}
493+
484494
// GetImagesFromApplication returns the list of known images for the given application
485495
func GetImagesFromApplication(app *v1alpha1.Application) image.ContainerImageList {
486496
images := make(image.ContainerImageList, 0)
497+
annotations := app.Annotations
498+
imagesFromAnnotations := parseImageList(annotations)
487499

488500
for _, imageStr := range app.Status.Summary.Images {
489-
image := image.NewFromIdentifier(imageStr)
490-
images = append(images, image)
501+
img := image.NewFromIdentifier(imageStr)
502+
if ImageIsAllowed(img, imagesFromAnnotations) {
503+
images = append(images, img)
504+
}
491505
}
492506

493507
// The Application may wish to update images that don't create a container we can detect.
494508
// Check the image list for images with a force-update annotation, and add them if they are not already present.
495-
annotations := app.Annotations
496-
for _, img := range *parseImageList(annotations) {
509+
for _, img := range *imagesFromAnnotations {
497510
if img.HasForceUpdateOptionAnnotation(annotations) {
498511
img.ImageTag = nil // the tag from the image list will be a version constraint, which isn't a valid tag
499512
images = append(images, img)

pkg/argocd/argocd_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ func Test_GetImagesFromApplication(t *testing.T) {
2727
ObjectMeta: v1.ObjectMeta{
2828
Name: "test-app",
2929
Namespace: "argocd",
30+
Annotations: map[string]string{
31+
common.ImageUpdaterAnnotation: "nginx:1.12.2,that/image,quay.io/dexidp/dex:v1.23.0",
32+
},
3033
},
3134
Spec: v1alpha1.ApplicationSpec{},
3235
Status: v1alpha1.ApplicationStatus{

pkg/argocd/update_test.go

Lines changed: 71 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -109,11 +109,15 @@ func Test_UpdateApplication(t *testing.T) {
109109
kubeClient := kube.KubernetesClient{
110110
Clientset: fake.NewFakeKubeClient(),
111111
}
112+
annotations := map[string]string{
113+
common.ImageUpdaterAnnotation: "jannfis/foobar:1.0.0",
114+
}
112115
appImages := &ApplicationImages{
113116
Application: v1alpha1.Application{
114117
ObjectMeta: v1.ObjectMeta{
115-
Name: "guestbook",
116-
Namespace: "guestbook",
118+
Name: "guestbook",
119+
Namespace: "guestbook",
120+
Annotations: annotations,
117121
},
118122
Spec: v1alpha1.ApplicationSpec{
119123
Source: &v1alpha1.ApplicationSource{
@@ -167,11 +171,15 @@ func Test_UpdateApplication(t *testing.T) {
167171
kubeClient := kube.KubernetesClient{
168172
Clientset: fake.NewFakeKubeClient(),
169173
}
174+
annotations := map[string]string{
175+
common.ImageUpdaterAnnotation: "jannfis/foobar:1.0.0,jannfis/barbar:1.0.0",
176+
}
170177
appImages := &ApplicationImages{
171178
Application: v1alpha1.Application{
172179
ObjectMeta: v1.ObjectMeta{
173-
Name: "guestbook",
174-
Namespace: "guestbook",
180+
Name: "guestbook",
181+
Namespace: "guestbook",
182+
Annotations: annotations,
175183
},
176184
Spec: v1alpha1.ApplicationSpec{
177185
Source: &v1alpha1.ApplicationSource{
@@ -354,11 +362,15 @@ func Test_UpdateApplication(t *testing.T) {
354362
kubeClient := kube.KubernetesClient{
355363
Clientset: fake.NewFakeKubeClient(),
356364
}
365+
annotations := map[string]string{
366+
common.ImageUpdaterAnnotation: "jannfis/foobar:1.0.x",
367+
}
357368
appImages := &ApplicationImages{
358369
Application: v1alpha1.Application{
359370
ObjectMeta: v1.ObjectMeta{
360-
Name: "guestbook",
361-
Namespace: "guestbook",
371+
Name: "guestbook",
372+
Namespace: "guestbook",
373+
Annotations: annotations,
362374
},
363375
Spec: v1alpha1.ApplicationSpec{
364376
Source: &v1alpha1.ApplicationSource{
@@ -412,14 +424,16 @@ func Test_UpdateApplication(t *testing.T) {
412424
kubeClient := kube.KubernetesClient{
413425
Clientset: fake.NewFakeClientsetWithResources(fixture.NewSecret("foo", "bar", map[string][]byte{"creds": []byte("myuser:mypass")})),
414426
}
427+
annotations := map[string]string{
428+
common.ImageUpdaterAnnotation: "jannfis/foobar:1.0.0",
429+
fmt.Sprintf(common.PullSecretAnnotation, "dummy"): "secret:foo/bar#creds",
430+
}
415431
appImages := &ApplicationImages{
416432
Application: v1alpha1.Application{
417433
ObjectMeta: v1.ObjectMeta{
418-
Name: "guestbook",
419-
Namespace: "guestbook",
420-
Annotations: map[string]string{
421-
fmt.Sprintf(common.PullSecretAnnotation, "dummy"): "secret:foo/bar#creds",
422-
},
434+
Name: "guestbook",
435+
Namespace: "guestbook",
436+
Annotations: annotations,
423437
},
424438
Spec: v1alpha1.ApplicationSpec{
425439
Source: &v1alpha1.ApplicationSource{
@@ -526,11 +540,15 @@ func Test_UpdateApplication(t *testing.T) {
526540
kubeClient := kube.KubernetesClient{
527541
Clientset: fake.NewFakeKubeClient(),
528542
}
543+
annotations := map[string]string{
544+
common.ImageUpdaterAnnotation: "jannfis/foobar:1.0.1",
545+
}
529546
appImages := &ApplicationImages{
530547
Application: v1alpha1.Application{
531548
ObjectMeta: v1.ObjectMeta{
532-
Name: "guestbook",
533-
Namespace: "guestbook",
549+
Name: "guestbook",
550+
Namespace: "guestbook",
551+
Annotations: annotations,
534552
},
535553
Spec: v1alpha1.ApplicationSpec{
536554
Source: &v1alpha1.ApplicationSource{
@@ -716,15 +734,17 @@ func Test_UpdateApplication(t *testing.T) {
716734
kubeClient := kube.KubernetesClient{
717735
Clientset: fake.NewFakeKubeClient(),
718736
}
737+
annotations := map[string]string{
738+
common.ImageUpdaterAnnotation: "dummy=jannfis/foobar",
739+
fmt.Sprintf(common.AllowTagsOptionAnnotation, "dummy"): "regexp:^foobar$",
740+
fmt.Sprintf(common.UpdateStrategyAnnotation, "dummy"): "name",
741+
}
719742
appImages := &ApplicationImages{
720743
Application: v1alpha1.Application{
721744
ObjectMeta: v1.ObjectMeta{
722-
Name: "guestbook",
723-
Namespace: "guestbook",
724-
Annotations: map[string]string{
725-
fmt.Sprintf(common.AllowTagsOptionAnnotation, "dummy"): "regexp:^foobar$",
726-
fmt.Sprintf(common.UpdateStrategyAnnotation, "dummy"): "name",
727-
},
745+
Name: "guestbook",
746+
Namespace: "guestbook",
747+
Annotations: annotations,
728748
},
729749
Spec: v1alpha1.ApplicationSpec{
730750
Source: &v1alpha1.ApplicationSource{
@@ -792,15 +812,17 @@ func Test_UpdateApplication(t *testing.T) {
792812
kubeClient := kube.KubernetesClient{
793813
Clientset: fake.NewFakeKubeClient(),
794814
}
815+
annotations := map[string]string{
816+
common.ImageUpdaterAnnotation: "dummy=jannfis/foobar",
817+
fmt.Sprintf(common.IgnoreTagsOptionAnnotation, "dummy"): "*",
818+
fmt.Sprintf(common.UpdateStrategyAnnotation, "dummy"): "name",
819+
}
795820
appImages := &ApplicationImages{
796821
Application: v1alpha1.Application{
797822
ObjectMeta: v1.ObjectMeta{
798-
Name: "guestbook",
799-
Namespace: "guestbook",
800-
Annotations: map[string]string{
801-
fmt.Sprintf(common.IgnoreTagsOptionAnnotation, "dummy"): "*",
802-
fmt.Sprintf(common.UpdateStrategyAnnotation, "dummy"): "name",
803-
},
823+
Name: "guestbook",
824+
Namespace: "guestbook",
825+
Annotations: annotations,
804826
},
805827
Spec: v1alpha1.ApplicationSpec{
806828
Source: &v1alpha1.ApplicationSource{
@@ -852,11 +874,15 @@ func Test_UpdateApplication(t *testing.T) {
852874
kubeClient := kube.KubernetesClient{
853875
Clientset: fake.NewFakeKubeClient(),
854876
}
877+
annotations := map[string]string{
878+
common.ImageUpdaterAnnotation: "example.io/jannfis/example:1.0.x",
879+
}
855880
appImages := &ApplicationImages{
856881
Application: v1alpha1.Application{
857882
ObjectMeta: v1.ObjectMeta{
858-
Name: "guestbook",
859-
Namespace: "guestbook",
883+
Name: "guestbook",
884+
Namespace: "guestbook",
885+
Annotations: annotations,
860886
},
861887
Spec: v1alpha1.ApplicationSpec{
862888
Source: &v1alpha1.ApplicationSource{
@@ -905,11 +931,15 @@ func Test_UpdateApplication(t *testing.T) {
905931
kubeClient := kube.KubernetesClient{
906932
Clientset: fake.NewFakeKubeClient(),
907933
}
934+
annotations := map[string]string{
935+
common.ImageUpdaterAnnotation: "jannfis/foobar:1.0.0",
936+
}
908937
appImages := &ApplicationImages{
909938
Application: v1alpha1.Application{
910939
ObjectMeta: v1.ObjectMeta{
911-
Name: "guestbook",
912-
Namespace: "guestbook",
940+
Name: "guestbook",
941+
Namespace: "guestbook",
942+
Annotations: annotations,
913943
},
914944
Spec: v1alpha1.ApplicationSpec{
915945
Source: &v1alpha1.ApplicationSource{
@@ -961,11 +991,15 @@ func Test_UpdateApplication(t *testing.T) {
961991
kubeClient := kube.KubernetesClient{
962992
Clientset: fake.NewFakeKubeClient(),
963993
}
994+
annotations := map[string]string{
995+
common.ImageUpdaterAnnotation: "jannfis/foobar:1.0.0",
996+
}
964997
appImages := &ApplicationImages{
965998
Application: v1alpha1.Application{
966999
ObjectMeta: v1.ObjectMeta{
967-
Name: "guestbook",
968-
Namespace: "guestbook",
1000+
Name: "guestbook",
1001+
Namespace: "guestbook",
1002+
Annotations: annotations,
9691003
},
9701004
Spec: v1alpha1.ApplicationSpec{
9711005
Source: &v1alpha1.ApplicationSource{
@@ -1017,11 +1051,15 @@ func Test_UpdateApplication(t *testing.T) {
10171051
kubeClient := kube.KubernetesClient{
10181052
Clientset: fake.NewFakeKubeClient(),
10191053
}
1054+
annotations := map[string]string{
1055+
common.ImageUpdaterAnnotation: "jannfis/foobar:stable",
1056+
}
10201057
appImages := &ApplicationImages{
10211058
Application: v1alpha1.Application{
10221059
ObjectMeta: v1.ObjectMeta{
1023-
Name: "guestbook",
1024-
Namespace: "guestbook",
1060+
Name: "guestbook",
1061+
Namespace: "guestbook",
1062+
Annotations: annotations,
10251063
},
10261064
Spec: v1alpha1.ApplicationSpec{
10271065
Source: &v1alpha1.ApplicationSource{

0 commit comments

Comments
 (0)