Skip to content

Commit 0dbd6cd

Browse files
authored
fix: modify SetKustomizeImage logic when use alias-image (#251)
1 parent 81d551b commit 0dbd6cd

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed

pkg/argocd/argocd.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,17 @@ func SetKustomizeImage(app *v1alpha1.Application, newImage *image.ContainerImage
414414
app.Spec.Source.Kustomize = &v1alpha1.ApplicationSourceKustomize{}
415415
}
416416

417+
for i, kImg := range app.Spec.Source.Kustomize.Images {
418+
curr := image.NewFromIdentifier(string(kImg))
419+
override := image.NewFromIdentifier(ksImageParam)
420+
421+
if curr.ImageName == override.ImageName {
422+
curr.ImageAlias = override.ImageAlias
423+
}
424+
425+
app.Spec.Source.Kustomize.Images[i] = v1alpha1.KustomizeImage(curr.String())
426+
}
427+
417428
app.Spec.Source.Kustomize.MergeImage(v1alpha1.KustomizeImage(ksImageParam))
418429

419430
return nil

pkg/argocd/argocd_test.go

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -466,6 +466,41 @@ func Test_SetKustomizeImage(t *testing.T) {
466466
require.Error(t, err)
467467
})
468468

469+
t.Run("Test set Kustomize image parameters with alias name on Kustomize app with param already set", func(t *testing.T) {
470+
app := &v1alpha1.Application{
471+
ObjectMeta: v1.ObjectMeta{
472+
Name: "test-app",
473+
Namespace: "testns",
474+
Annotations: map[string]string{
475+
fmt.Sprintf(common.KustomizeApplicationNameAnnotation, "foobar"): "foobar",
476+
},
477+
},
478+
Spec: v1alpha1.ApplicationSpec{
479+
Source: v1alpha1.ApplicationSource{
480+
Kustomize: &v1alpha1.ApplicationSourceKustomize{
481+
Images: v1alpha1.KustomizeImages{
482+
"jannfis/foobar:1.0.0",
483+
},
484+
},
485+
},
486+
},
487+
Status: v1alpha1.ApplicationStatus{
488+
SourceType: v1alpha1.ApplicationSourceTypeKustomize,
489+
Summary: v1alpha1.ApplicationSummary{
490+
Images: []string{
491+
"jannfis/foobar:1.0.0",
492+
},
493+
},
494+
},
495+
}
496+
img := image.NewFromIdentifier("foobar=jannfis/foobar:1.0.1")
497+
err := SetKustomizeImage(app, img)
498+
require.NoError(t, err)
499+
require.NotNil(t, app.Spec.Source.Kustomize)
500+
assert.Len(t, app.Spec.Source.Kustomize.Images, 1)
501+
assert.Equal(t, v1alpha1.KustomizeImage("foobar=jannfis/foobar:1.0.1"), app.Spec.Source.Kustomize.Images[0])
502+
})
503+
469504
}
470505

471506
func Test_SetHelmImage(t *testing.T) {

0 commit comments

Comments
 (0)