Skip to content
This repository was archived by the owner on Oct 19, 2024. It is now read-only.

Commit 4161034

Browse files
committed
fix: repo.GetAppDetails().Helm.GetParameterValueByName not get helm.values
1 parent 8dddaa3 commit 4161034

File tree

2 files changed

+42
-4
lines changed

2 files changed

+42
-4
lines changed

Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
ARG BUILDPLATFORM=linux/amd64
12
FROM --platform=$BUILDPLATFORM golang:1.16.2 as builder
23

34
RUN apt-get update && apt-get install ca-certificates

shared/argocd/service.go

Lines changed: 41 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ package argocd
22

33
import (
44
"context"
5+
"encoding/json"
56
"fmt"
7+
"strings"
68

79
"github.com/argoproj-labs/argocd-notifications/expr/shared"
810
"github.com/argoproj/argo-cd/v2/common"
@@ -117,10 +119,8 @@ func (svc *argoCDService) GetAppDetails(ctx context.Context, appSource *v1alpha1
117119
if err != nil {
118120
return nil, err
119121
}
120-
121122
var has *shared.HelmAppSpec
122123
if appDetail.Helm != nil {
123-
124124
if appSource.Helm.Parameters != nil {
125125
for _, overrideParam := range appSource.Helm.Parameters {
126126
for _, defaultParam := range appDetail.Helm.Parameters {
@@ -132,11 +132,32 @@ func (svc *argoCDService) GetAppDetails(ctx context.Context, appSource *v1alpha1
132132
}
133133
}
134134

135+
if appSource.Helm.Values != "" {
136+
output := map[string]string{}
137+
var valuesMap map[string]interface{}
138+
if err := json.Unmarshal([]byte(appSource.Helm.Values), valuesMap); err != nil {
139+
return nil, fmt.Errorf("failed to parse appSource.Helm.Values: %s", err)
140+
}
141+
flatVals(valuesMap, output)
142+
143+
for i := range has.Parameters {
144+
if v, ok := output[has.Parameters[i].Name]; ok {
145+
has.Parameters[i].Value = v
146+
delete(output, has.Parameters[i].Name)
147+
break
148+
}
149+
}
150+
151+
for k, v := range output {
152+
appDetail.Helm.Parameters = append(appDetail.Helm.Parameters, &v1alpha1.HelmParameter{Name: k, Value: v})
153+
}
154+
}
155+
135156
has = &shared.HelmAppSpec{
136157
Name: appDetail.Helm.Name,
137-
ValueFiles: appDetail.Helm.ValueFiles,
158+
ValueFiles: appSource.Helm.ValueFiles,
138159
Parameters: appDetail.Helm.Parameters,
139-
Values: appDetail.Helm.Values,
160+
Values: appSource.Helm.Values,
140161
FileParameters: appDetail.Helm.FileParameters,
141162
}
142163
}
@@ -152,3 +173,19 @@ func (svc *argoCDService) GetAppDetails(ctx context.Context, appSource *v1alpha1
152173
func (svc *argoCDService) Close() {
153174
svc.dispose()
154175
}
176+
177+
func flatVals(input interface{}, output map[string]string, prefixes ...string) {
178+
switch i := input.(type) {
179+
case map[string]interface{}:
180+
for k, v := range i {
181+
flatVals(v, output, append(prefixes, k)...)
182+
}
183+
case []interface{}:
184+
p := append([]string(nil), prefixes...)
185+
for j, v := range i {
186+
flatVals(v, output, append(p[0:len(p)-1], fmt.Sprintf("%s[%v]", prefixes[len(p)-1], j))...)
187+
}
188+
default:
189+
output[strings.Join(prefixes, ".")] = fmt.Sprintf("%v", i)
190+
}
191+
}

0 commit comments

Comments
 (0)