@@ -2,7 +2,9 @@ package argocd
2
2
3
3
import (
4
4
"context"
5
+ "encoding/json"
5
6
"fmt"
7
+ "strings"
6
8
7
9
"github.com/argoproj-labs/argocd-notifications/expr/shared"
8
10
"github.com/argoproj/argo-cd/v2/common"
@@ -117,10 +119,8 @@ func (svc *argoCDService) GetAppDetails(ctx context.Context, appSource *v1alpha1
117
119
if err != nil {
118
120
return nil , err
119
121
}
120
-
121
122
var has * shared.HelmAppSpec
122
123
if appDetail .Helm != nil {
123
-
124
124
if appSource .Helm .Parameters != nil {
125
125
for _ , overrideParam := range appSource .Helm .Parameters {
126
126
for _ , defaultParam := range appDetail .Helm .Parameters {
@@ -132,11 +132,32 @@ func (svc *argoCDService) GetAppDetails(ctx context.Context, appSource *v1alpha1
132
132
}
133
133
}
134
134
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
+
135
156
has = & shared.HelmAppSpec {
136
157
Name : appDetail .Helm .Name ,
137
- ValueFiles : appDetail .Helm .ValueFiles ,
158
+ ValueFiles : appSource .Helm .ValueFiles ,
138
159
Parameters : appDetail .Helm .Parameters ,
139
- Values : appDetail .Helm .Values ,
160
+ Values : appSource .Helm .Values ,
140
161
FileParameters : appDetail .Helm .FileParameters ,
141
162
}
142
163
}
@@ -152,3 +173,19 @@ func (svc *argoCDService) GetAppDetails(ctx context.Context, appSource *v1alpha1
152
173
func (svc * argoCDService ) Close () {
153
174
svc .dispose ()
154
175
}
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