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

Commit bb46b21

Browse files
committed
fix: repo.GetAppDetails().Helm.GetParameterValueByName not get helm.values
1 parent a3305aa commit bb46b21

File tree

1 file changed

+45
-36
lines changed

1 file changed

+45
-36
lines changed

shared/argocd/service.go

Lines changed: 45 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package argocd
33
import (
44
"context"
55
"fmt"
6+
"github.com/ghodss/yaml"
67
"strings"
78

89
"github.com/argoproj-labs/argocd-notifications/expr/shared"
@@ -118,15 +119,6 @@ func (svc *argoCDService) GetAppDetails(ctx context.Context, appSource *v1alpha1
118119
if err != nil {
119120
return nil, err
120121
}
121-
data, err := appSource.Helm.Marshal()
122-
if err != nil {
123-
return nil, err
124-
}
125-
126-
fmt.Sprintf("----- appSource: %v", appSource)
127-
128-
appDetail.Helm.Unmarshal(data)
129-
fmt.Sprintf("----- appDetail: %v", appDetail)
130122

131123
var has *shared.HelmAppSpec
132124
if appDetail.Helm != nil {
@@ -141,33 +133,39 @@ func (svc *argoCDService) GetAppDetails(ctx context.Context, appSource *v1alpha1
141133
}
142134
}
143135

144-
//if appSource.Helm.Values != "" {
145-
//
146-
// fmt.Printf("-------start output\n")
147-
// output := map[string]string{}
148-
// valuesMap := make(map[interface{}]interface{})
149-
// appSource.Helm.Unmarshal([]byte(appSource.Helm.Values))
150-
//
151-
// fmt.Printf("-------flatVals output\n")
152-
// //for i := range appDetail.Helm.Parameters {
153-
// // if v, ok := output[has.Parameters[i].Name]; ok {
154-
// // has.Parameters[i].Value = v
155-
// // //delete(output, has.Parameters[i].Name)
156-
// // break
157-
// // }
158-
// //}
159-
//
160-
// fmt.Printf("-------after delete output: %v\n", output)
161-
// for i := range appDetail.Helm.Parameters {
162-
// if v, ok := output[appDetail.Helm.Parameters[i].Name]; ok {
163-
// parameter := &v1alpha1.HelmParameter{Name: appDetail.Helm.Parameters[i].Name, Value: v}
164-
// appDetail.Helm.Parameters[i] = parameter
165-
// }
166-
// }
167-
//
168-
// fmt.Printf("-------appSource.Helm.Parameters: %v\n", appSource.Helm.Parameters)
169-
// fmt.Printf("-------appDetail.Helm.Parameters: %v\n", appDetail.Helm.Parameters)
170-
//}
136+
if appSource.Helm.Values != "" {
137+
output := map[string]*v1alpha1.HelmParameter{}
138+
for _, param := range appDetail.Helm.Parameters {
139+
output[param.Name] = param
140+
}
141+
params, err := GetHelmParametersByValues(appSource.Helm.Values)
142+
if err != nil {
143+
return nil, err
144+
}
145+
for k, v := range params {
146+
output[k] = &v1alpha1.HelmParameter{
147+
Name: k,
148+
Value: v,
149+
}
150+
}
151+
appDetail.Helm.Parameters = nil
152+
for k, v := range output {
153+
appDetail.Helm.Parameters = append(appDetail.Helm.Parameters, &v1alpha1.HelmParameter{
154+
Name: k,
155+
Value: v.Value,
156+
ForceString: v.ForceString,
157+
})
158+
}
159+
160+
fmt.Printf("-------flatVals output\n")
161+
//for i := range appDetail.Helm.Parameters {
162+
// if v, ok := output[has.Parameters[i].Name]; ok {
163+
// has.Parameters[i].Value = v
164+
// //delete(output, has.Parameters[i].Name)
165+
// break
166+
// }
167+
//}
168+
}
171169
has = &shared.HelmAppSpec{
172170
Name: appDetail.Helm.Name,
173171
ValueFiles: appDetail.Helm.ValueFiles,
@@ -189,6 +187,17 @@ func (svc *argoCDService) Close() {
189187
svc.dispose()
190188
}
191189

190+
func GetHelmParametersByValues(values string) (map[string]string, error) {
191+
output := map[string]string{}
192+
valuesMap := map[string]interface{}{}
193+
if err := yaml.Unmarshal([]byte(values), &valuesMap); err != nil {
194+
return nil, fmt.Errorf("failed to parse values: %s", err)
195+
}
196+
flatVals(valuesMap, output)
197+
198+
return output, nil
199+
}
200+
192201
func flatVals(input interface{}, output map[string]string, prefixes ...string) {
193202
switch i := input.(type) {
194203
case map[string]interface{}:

0 commit comments

Comments
 (0)