summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYuta Nishimori <nyuta2048@gmail.com>2021-09-09 18:12:26 +0900
committerGitHub <noreply@github.com>2021-09-09 11:12:26 +0200
commit0dbd6cd55972ab9ffbd85db1cb4ce855e23b8fdd (patch)
treeba0b87d9b98bdbf48d6ab457416ed6395b4f0798
parent81d551b3a41f765b705df7efec40f734409e116b (diff)
fix: modify SetKustomizeImage logic when use alias-image (#251)
-rw-r--r--pkg/argocd/argocd.go11
-rw-r--r--pkg/argocd/argocd_test.go35
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) {