diff options
| -rw-r--r-- | pkg/argocd/argocd.go | 11 | ||||
| -rw-r--r-- | pkg/argocd/argocd_test.go | 35 |
2 files changed, 46 insertions, 0 deletions
diff --git a/pkg/argocd/argocd.go b/pkg/argocd/argocd.go index ac353f5..b23a234 100644 --- a/pkg/argocd/argocd.go +++ b/pkg/argocd/argocd.go @@ -414,6 +414,17 @@ func SetKustomizeImage(app *v1alpha1.Application, newImage *image.ContainerImage app.Spec.Source.Kustomize = &v1alpha1.ApplicationSourceKustomize{} } + for i, kImg := range app.Spec.Source.Kustomize.Images { + curr := image.NewFromIdentifier(string(kImg)) + override := image.NewFromIdentifier(ksImageParam) + + if curr.ImageName == override.ImageName { + curr.ImageAlias = override.ImageAlias + } + + app.Spec.Source.Kustomize.Images[i] = v1alpha1.KustomizeImage(curr.String()) + } + app.Spec.Source.Kustomize.MergeImage(v1alpha1.KustomizeImage(ksImageParam)) return nil diff --git a/pkg/argocd/argocd_test.go b/pkg/argocd/argocd_test.go index 019fb7b..07fdde7 100644 --- a/pkg/argocd/argocd_test.go +++ b/pkg/argocd/argocd_test.go @@ -466,6 +466,41 @@ func Test_SetKustomizeImage(t *testing.T) { require.Error(t, err) }) + t.Run("Test set Kustomize image parameters with alias name on Kustomize app with param already set", func(t *testing.T) { + app := &v1alpha1.Application{ + ObjectMeta: v1.ObjectMeta{ + Name: "test-app", + Namespace: "testns", + Annotations: map[string]string{ + fmt.Sprintf(common.KustomizeApplicationNameAnnotation, "foobar"): "foobar", + }, + }, + Spec: v1alpha1.ApplicationSpec{ + Source: v1alpha1.ApplicationSource{ + Kustomize: &v1alpha1.ApplicationSourceKustomize{ + Images: v1alpha1.KustomizeImages{ + "jannfis/foobar:1.0.0", + }, + }, + }, + }, + Status: v1alpha1.ApplicationStatus{ + SourceType: v1alpha1.ApplicationSourceTypeKustomize, + Summary: v1alpha1.ApplicationSummary{ + Images: []string{ + "jannfis/foobar:1.0.0", + }, + }, + }, + } + img := image.NewFromIdentifier("foobar=jannfis/foobar:1.0.1") + err := SetKustomizeImage(app, img) + require.NoError(t, err) + require.NotNil(t, app.Spec.Source.Kustomize) + assert.Len(t, app.Spec.Source.Kustomize.Images, 1) + assert.Equal(t, v1alpha1.KustomizeImage("foobar=jannfis/foobar:1.0.1"), app.Spec.Source.Kustomize.Images[0]) + }) + } func Test_SetHelmImage(t *testing.T) { |
