@@ -3,6 +3,8 @@ package argocd
3
3
import (
4
4
"context"
5
5
"fmt"
6
+ "k8s.io/apimachinery/pkg/util/yaml"
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,37 @@ 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
+ 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
+
135
161
has = & shared.HelmAppSpec {
136
162
Name : appDetail .Helm .Name ,
137
- ValueFiles : appDetail .Helm .ValueFiles ,
163
+ ValueFiles : appSource .Helm .ValueFiles ,
138
164
Parameters : appDetail .Helm .Parameters ,
139
- Values : appDetail .Helm .Values ,
165
+ Values : appSource .Helm .Values ,
140
166
FileParameters : appDetail .Helm .FileParameters ,
141
167
}
142
168
}
@@ -152,3 +178,19 @@ func (svc *argoCDService) GetAppDetails(ctx context.Context, appSource *v1alpha1
152
178
func (svc * argoCDService ) Close () {
153
179
svc .dispose ()
154
180
}
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