@@ -3,6 +3,8 @@ package argocd
33import (
44 "context"
55 "fmt"
6+ "github.com/ghodss/yaml"
7+ "strings"
68
79 "github.com/argoproj-labs/argocd-notifications/expr/shared"
810 "github.com/argoproj/argo-cd/v2/common"
@@ -120,18 +122,39 @@ func (svc *argoCDService) GetAppDetails(ctx context.Context, appSource *v1alpha1
120122
121123 var has * shared.HelmAppSpec
122124 if appDetail .Helm != nil {
123-
125+ paramsMap := map [ string ] * v1alpha1. HelmParameter {}
124126 if appSource .Helm .Parameters != nil {
125127 for _ , overrideParam := range appSource .Helm .Parameters {
126- for _ , defaultParam := range appDetail .Helm .Parameters {
127- if overrideParam .Name == defaultParam .Name {
128- defaultParam .Value = overrideParam .Value
129- defaultParam .ForceString = overrideParam .ForceString
130- }
128+ paramsMap [overrideParam .Name ] = & v1alpha1.HelmParameter {
129+ Name : overrideParam .Name ,
130+ Value : overrideParam .Value ,
131+ ForceString : overrideParam .ForceString ,
131132 }
132133 }
133134 }
134-
135+ if appSource .Helm .Values != "" {
136+ for _ , param := range appDetail .Helm .Parameters {
137+ paramsMap [param .Name ] = param
138+ }
139+ valuesParams , err := GetHelmParametersByValues (appSource .Helm .Values )
140+ if err != nil {
141+ return nil , err
142+ }
143+ for k , v := range valuesParams {
144+ paramsMap [k ] = & v1alpha1.HelmParameter {
145+ Name : k ,
146+ Value : v ,
147+ }
148+ }
149+ appDetail .Helm .Parameters = nil
150+ for k , v := range paramsMap {
151+ appDetail .Helm .Parameters = append (appDetail .Helm .Parameters , & v1alpha1.HelmParameter {
152+ Name : k ,
153+ Value : v .Value ,
154+ ForceString : v .ForceString ,
155+ })
156+ }
157+ }
135158 has = & shared.HelmAppSpec {
136159 Name : appDetail .Helm .Name ,
137160 ValueFiles : appDetail .Helm .ValueFiles ,
@@ -152,3 +175,30 @@ func (svc *argoCDService) GetAppDetails(ctx context.Context, appSource *v1alpha1
152175func (svc * argoCDService ) Close () {
153176 svc .dispose ()
154177}
178+
179+ func GetHelmParametersByValues (values string ) (map [string ]string , error ) {
180+ output := map [string ]string {}
181+ valuesMap := map [string ]interface {}{}
182+ if err := yaml .Unmarshal ([]byte (values ), & valuesMap ); err != nil {
183+ return nil , fmt .Errorf ("failed to parse values: %s" , err )
184+ }
185+ flatVals (valuesMap , output )
186+
187+ return output , nil
188+ }
189+
190+ func flatVals (input interface {}, output map [string ]string , prefixes ... string ) {
191+ switch i := input .(type ) {
192+ case map [string ]interface {}:
193+ for k , v := range i {
194+ flatVals (v , output , append (prefixes , k )... )
195+ }
196+ case []interface {}:
197+ p := append ([]string (nil ), prefixes ... )
198+ for j , v := range i {
199+ flatVals (v , output , append (p [0 :len (p )- 1 ], fmt .Sprintf ("%s[%v]" , prefixes [len (p )- 1 ], j ))... )
200+ }
201+ default :
202+ output [strings .Join (prefixes , "." )] = fmt .Sprintf ("%v" , i )
203+ }
204+ }
0 commit comments