Skip to content

Commit ab7e45d

Browse files
fix(notifications): Helm.GetParameterValueByName should take helm.parametes first (#17472) (#17512)
* fix: Helm.GetParameterValueByName should take helm.parametes first * fix linters --------- Signed-off-by: pashakostohrys <pavel@codefresh.io> Co-authored-by: pasha-codefresh <pavel@codefresh.io>
1 parent a8ae929 commit ab7e45d

File tree

3 files changed

+57
-15
lines changed

3 files changed

+57
-15
lines changed

util/notification/argocd/service.go

+8-5
Original file line numberDiff line numberDiff line change
@@ -107,11 +107,14 @@ func (svc *argoCDService) GetAppDetails(ctx context.Context, appSource *v1alpha1
107107
var has *shared.CustomHelmAppSpec
108108
if appDetail.Helm != nil {
109109
has = &shared.CustomHelmAppSpec{
110-
Name: appDetail.Helm.Name,
111-
ValueFiles: appDetail.Helm.ValueFiles,
112-
Parameters: appDetail.Helm.Parameters,
113-
Values: appDetail.Helm.Values,
114-
FileParameters: appDetail.Helm.FileParameters,
110+
HelmAppSpec: apiclient.HelmAppSpec{
111+
Name: appDetail.Helm.Name,
112+
ValueFiles: appDetail.Helm.ValueFiles,
113+
Parameters: appDetail.Helm.Parameters,
114+
Values: appDetail.Helm.Values,
115+
FileParameters: appDetail.Helm.FileParameters,
116+
},
117+
HelmParameterOverrides: appSource.Helm.Parameters,
115118
}
116119
}
117120
return &shared.AppDetail{

util/notification/expression/shared/appdetail.go

+19-10
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package shared
22

33
import (
4+
"github.com/argoproj/argo-cd/v2/pkg/apis/application/v1alpha1"
45
"time"
56

67
"github.com/argoproj/argo-cd/v2/reposerver/apiclient"
@@ -28,24 +29,32 @@ type AppDetail struct {
2829
Directory *apiclient.DirectoryAppSpec
2930
}
3031

31-
type CustomHelmAppSpec apiclient.HelmAppSpec
32+
type CustomHelmAppSpec struct {
33+
HelmAppSpec apiclient.HelmAppSpec
34+
HelmParameterOverrides []v1alpha1.HelmParameter
35+
}
3236

3337
func (has CustomHelmAppSpec) GetParameterValueByName(Name string) string {
34-
var value string
35-
for i := range has.Parameters {
36-
if has.Parameters[i].Name == Name {
37-
value = has.Parameters[i].Value
38-
break
38+
// Check in overrides first
39+
for i := range has.HelmParameterOverrides {
40+
if has.HelmParameterOverrides[i].Name == Name {
41+
return has.HelmParameterOverrides[i].Value
42+
}
43+
}
44+
45+
for i := range has.HelmAppSpec.Parameters {
46+
if has.HelmAppSpec.Parameters[i].Name == Name {
47+
return has.HelmAppSpec.Parameters[i].Value
3948
}
4049
}
41-
return value
50+
return ""
4251
}
4352

4453
func (has CustomHelmAppSpec) GetFileParameterPathByName(Name string) string {
4554
var path string
46-
for i := range has.FileParameters {
47-
if has.FileParameters[i].Name == Name {
48-
path = has.FileParameters[i].Path
55+
for i := range has.HelmAppSpec.FileParameters {
56+
if has.HelmAppSpec.FileParameters[i].Name == Name {
57+
path = has.HelmAppSpec.FileParameters[i].Path
4958
break
5059
}
5160
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package shared
2+
3+
import (
4+
"github.com/argoproj/argo-cd/v2/pkg/apis/application/v1alpha1"
5+
"github.com/argoproj/argo-cd/v2/reposerver/apiclient"
6+
"github.com/stretchr/testify/assert"
7+
"testing"
8+
)
9+
10+
func TestGetParameterValueByName(t *testing.T) {
11+
helmAppSpec := CustomHelmAppSpec{
12+
HelmAppSpec: apiclient.HelmAppSpec{
13+
Parameters: []*v1alpha1.HelmParameter{
14+
{
15+
Name: "param1",
16+
Value: "value1",
17+
},
18+
},
19+
},
20+
HelmParameterOverrides: []v1alpha1.HelmParameter{
21+
{
22+
Name: "param1",
23+
Value: "value-override",
24+
},
25+
},
26+
}
27+
28+
value := helmAppSpec.GetParameterValueByName("param1")
29+
assert.Equal(t, "value-override", value)
30+
}

0 commit comments

Comments
 (0)