Skip to content

Commit

Permalink
fix: Correctly consider image with force-update set and semver strate…
Browse files Browse the repository at this point in the history
…gy (#192)

* fix issue with force-update and semver

* simplify by just removing the invalid tag
  • Loading branch information
iamnoah committed Apr 15, 2021
1 parent 93d76f9 commit 37433e4
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 0 deletions.
1 change: 1 addition & 0 deletions pkg/argocd/argocd.go
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,7 @@ func GetImagesFromApplication(app *v1alpha1.Application) image.ContainerImageLis
annotations := app.Annotations
if updateImage, ok := annotations[common.ImageUpdaterAnnotation]; ok {
for _, img := range *parseImageList(updateImage) {
img.ImageTag = nil // the tag from the image list will be a version constraint, which isn't a valid tag
if forceStr, force := annotations[fmt.Sprintf(common.ForceUpdateOptionAnnotation, img.ImageAlias)]; force && strings.ToLower(forceStr) == "true" {
if images.ContainsImage(img, false) == nil {
images = append(images, img)
Expand Down
59 changes: 59 additions & 0 deletions pkg/argocd/update_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,65 @@ func Test_UpdateApplication(t *testing.T) {
assert.Equal(t, 0, res.NumImagesUpdated)
})

t.Run("Test update because of image registry changed", func(t *testing.T) {
mockClientFn := func(endpoint *registry.RegistryEndpoint, username, password string) (registry.RegistryClient, error) {
regMock := regmock.RegistryClient{}
regMock.On("Tags", mock.Anything).Return([]string{"1.0.1"}, nil)
return &regMock, nil
}

argoClient := argomock.ArgoCD{}
argoClient.On("UpdateSpec", mock.Anything, mock.Anything).Return(nil, nil)

kubeClient := kube.KubernetesClient{
Clientset: fake.NewFakeKubeClient(),
}
imageList := "foobar=gcr.io/jannfis/foobar:>=1.0.1"
appImages := &ApplicationImages{
Application: v1alpha1.Application{
ObjectMeta: v1.ObjectMeta{
Name: "guestbook",
Namespace: "guestbook",
Annotations: map[string]string{
common.ImageUpdaterAnnotation: imageList,
fmt.Sprintf(common.KustomizeApplicationNameAnnotation, "foobar"): "jannfis/foobar",
fmt.Sprintf(common.ForceUpdateOptionAnnotation, "foobar"): "true",
},
},
Spec: v1alpha1.ApplicationSpec{
Source: v1alpha1.ApplicationSource{
Kustomize: &v1alpha1.ApplicationSourceKustomize{
Images: v1alpha1.KustomizeImages{
"jannfis/foobar:1.0.1",
},
},
},
},
Status: v1alpha1.ApplicationStatus{
SourceType: v1alpha1.ApplicationSourceTypeKustomize,
Summary: v1alpha1.ApplicationSummary{
Images: []string{
"jannfis/foobar:1.0.1",
},
},
},
},
Images: *parseImageList(imageList),
}
res := UpdateApplication(&UpdateConfiguration{
NewRegFN: mockClientFn,
ArgoClient: &argoClient,
KubeClient: &kubeClient,
UpdateApp: appImages,
DryRun: false,
}, NewSyncIterationState())
assert.Equal(t, 0, res.NumErrors)
assert.Equal(t, 0, res.NumSkipped)
assert.Equal(t, 1, res.NumApplicationsProcessed)
assert.Equal(t, 1, res.NumImagesConsidered)
assert.Equal(t, 1, res.NumImagesUpdated)
})

t.Run("Test skip because of match-tag pattern doesn't match", func(t *testing.T) {
meta := make([]*schema1.SignedManifest, 4)
for i := 0; i < 4; i++ {
Expand Down

0 comments on commit 37433e4

Please sign in to comment.