Skip to content

Commit 822b37a

Browse files
committed
feat: handle case when image-spec is chosen
Signed-off-by: Tchoupinax <[email protected]>
1 parent 2cd8a44 commit 822b37a

File tree

2 files changed

+75
-4
lines changed

2 files changed

+75
-4
lines changed

pkg/argocd/argocd.go

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -423,8 +423,19 @@ func SetHelmImage(app *v1alpha1.Application, newImage *image.ContainerImage) err
423423
// we simply ignore any image-name and image-tag parameters that might be
424424
// there.
425425
if hpImageSpec != "" {
426-
p := v1alpha1.HelmParameter{Name: hpImageSpec, Value: newImage.GetFullNameWithTag(), ForceString: true}
427-
mergeParams = append(mergeParams, p)
426+
// Here is the case value1,value2
427+
if strings.Contains(hpImageSpec, ",") {
428+
var parameters = strings.Split(strings.ReplaceAll(hpImageSpec, " ", ""), ",")
429+
for _, parameterName := range parameters {
430+
if parameterName != "" {
431+
p := v1alpha1.HelmParameter{Name: parameterName, Value: newImage.GetFullNameWithTag(), ForceString: true}
432+
mergeParams = append(mergeParams, p)
433+
}
434+
}
435+
} else {
436+
p := v1alpha1.HelmParameter{Name: hpImageSpec, Value: newImage.GetFullNameWithTag(), ForceString: true}
437+
mergeParams = append(mergeParams, p)
438+
}
428439
} else {
429440
if hpImageName != "" {
430441
// Here is the case value1,value2

pkg/argocd/argocd_test.go

Lines changed: 62 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1005,14 +1005,14 @@ func Test_SetHelmImage(t *testing.T) {
10051005
require.Error(t, err)
10061006
})
10071007

1008-
t.Run("Test set Helm image parameters when two paths are provided", func(t *testing.T) {
1008+
t.Run("Test set Helm image parameters when two paths are provided with name and tag", func(t *testing.T) {
10091009
app := &v1alpha1.Application{
10101010
ObjectMeta: v1.ObjectMeta{
10111011
Name: "test-app",
10121012
Namespace: "testns",
10131013
Annotations: map[string]string{
10141014
fmt.Sprintf(common.HelmParamImageNameAnnotation, "foobar"): "foobar.image.name,,, foobar2.image.name",
1015-
fmt.Sprintf(common.HelmParamImageTagAnnotation, "foobar"): "foobar.image.tag,,, foobar2.image.tag", // Space and comma are expected
1015+
fmt.Sprintf(common.HelmParamImageTagAnnotation, "foobar"): "foobar.image.tag,,, foobar2.image.tag",
10161016
},
10171017
},
10181018
Spec: v1alpha1.ApplicationSpec{
@@ -1088,6 +1088,66 @@ func Test_SetHelmImage(t *testing.T) {
10881088
}
10891089
assert.Equal(t, "jannfis/foobar", nameParamTwo.Value)
10901090
})
1091+
1092+
t.Run("Test set Helm image parameters when two paths are provided with image spec", func(t *testing.T) {
1093+
app := &v1alpha1.Application{
1094+
ObjectMeta: v1.ObjectMeta{
1095+
Name: "test-app",
1096+
Namespace: "testns",
1097+
Annotations: map[string]string{
1098+
fmt.Sprintf(common.HelmParamImageSpecAnnotation, "foobar"): "foobar.image.spec,,, foobar2.image.spec",
1099+
},
1100+
},
1101+
Spec: v1alpha1.ApplicationSpec{
1102+
Source: &v1alpha1.ApplicationSource{
1103+
Helm: &v1alpha1.ApplicationSourceHelm{
1104+
Parameters: []v1alpha1.HelmParameter{
1105+
{
1106+
Name: "image.spec",
1107+
Value: "jannfis/dummy:1.0.0",
1108+
},
1109+
},
1110+
},
1111+
},
1112+
},
1113+
Status: v1alpha1.ApplicationStatus{
1114+
SourceType: v1alpha1.ApplicationSourceTypeHelm,
1115+
Summary: v1alpha1.ApplicationSummary{
1116+
Images: []string{
1117+
"jannfis/foobar:1.0.0",
1118+
},
1119+
},
1120+
},
1121+
}
1122+
1123+
img := image.NewFromIdentifier("foobar=jannfis/foobar:1.0.1")
1124+
1125+
err := SetHelmImage(app, img)
1126+
require.NoError(t, err)
1127+
require.NotNil(t, app.Spec.Source.Helm)
1128+
assert.Len(t, app.Spec.Source.Helm.Parameters, 3)
1129+
1130+
// Find first correct parameter
1131+
var specParam v1alpha1.HelmParameter
1132+
for _, p := range app.Spec.Source.Helm.Parameters {
1133+
fmt.Println(p.Name)
1134+
if p.Name == "foobar.image.spec" {
1135+
specParam = p
1136+
break
1137+
}
1138+
}
1139+
assert.Equal(t, "jannfis/foobar:1.0.1", specParam.Value)
1140+
1141+
// Find second correct parameter
1142+
var specParamTwo v1alpha1.HelmParameter
1143+
for _, p := range app.Spec.Source.Helm.Parameters {
1144+
if p.Name == "foobar2.image.spec" {
1145+
specParamTwo = p
1146+
break
1147+
}
1148+
}
1149+
assert.Equal(t, "jannfis/foobar:1.0.1", specParamTwo.Value)
1150+
})
10911151
}
10921152

10931153
func TestKubernetesClient(t *testing.T) {

0 commit comments

Comments
 (0)