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

Commit e3072b0

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

File tree

2 files changed

+47
-4
lines changed

2 files changed

+47
-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: 46 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ package argocd
33
import (
44
"context"
55
"fmt"
6+
"k8s.io/apimachinery/pkg/util/yaml"
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,37 @@ func (svc *argoCDService) GetAppDetails(ctx context.Context, appSource *v1alpha1
132132
}
133133
}
134134

135+
if appSource.Helm.Values != "" {
136+
output := map[string]string{}
137+
valuesMap := make(map[string]interface{})
138+
if err := yaml.Unmarshal([]byte(appSource.Helm.Values), valuesMap); err != nil {
139+
return nil, fmt.Errorf("failed to parse : %s, appSource.Helm.Values: %v", err, appSource.Helm.Values)
140+
}
141+
flatVals(valuesMap, output)
142+
143+
fmt.Printf("-------flatVals output: %v", output)
144+
for i := range appDetail.Helm.Parameters {
145+
if v, ok := output[has.Parameters[i].Name]; ok {
146+
has.Parameters[i].Value = v
147+
delete(output, has.Parameters[i].Name)
148+
break
149+
}
150+
}
151+
152+
fmt.Printf("-------after delete output: %v", output)
153+
154+
for k, v := range output {
155+
appDetail.Helm.Parameters = append(appDetail.Helm.Parameters, &v1alpha1.HelmParameter{Name: k, Value: v})
156+
}
157+
158+
fmt.Printf("-------appDetail.Helm.Parameters: %v", appDetail.Helm.Parameters)
159+
}
160+
135161
has = &shared.HelmAppSpec{
136162
Name: appDetail.Helm.Name,
137-
ValueFiles: appDetail.Helm.ValueFiles,
163+
ValueFiles: appSource.Helm.ValueFiles,
138164
Parameters: appDetail.Helm.Parameters,
139-
Values: appDetail.Helm.Values,
165+
Values: appSource.Helm.Values,
140166
FileParameters: appDetail.Helm.FileParameters,
141167
}
142168
}
@@ -152,3 +178,19 @@ func (svc *argoCDService) GetAppDetails(ctx context.Context, appSource *v1alpha1
152178
func (svc *argoCDService) Close() {
153179
svc.dispose()
154180
}
181+
182+
func flatVals(input interface{}, output map[string]string, prefixes ...string) {
183+
switch i := input.(type) {
184+
case map[string]interface{}:
185+
for k, v := range i {
186+
flatVals(v, output, append(prefixes, k)...)
187+
}
188+
case []interface{}:
189+
p := append([]string(nil), prefixes...)
190+
for j, v := range i {
191+
flatVals(v, output, append(p[0:len(p)-1], fmt.Sprintf("%s[%v]", prefixes[len(p)-1], j))...)
192+
}
193+
default:
194+
output[strings.Join(prefixes, ".")] = fmt.Sprintf("%v", i)
195+
}
196+
}

0 commit comments

Comments
 (0)