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

Commit

Permalink
fix: repo.GetAppDetails().Helm.GetParameterValueByName not get helm.v…
Browse files Browse the repository at this point in the history
…alues
  • Loading branch information
ss75710541 committed Apr 27, 2022
1 parent a3305aa commit bb46b21
Showing 1 changed file with 45 additions and 36 deletions.
81 changes: 45 additions & 36 deletions shared/argocd/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package argocd
import (
"context"
"fmt"
"github.com/ghodss/yaml"
"strings"

"github.com/argoproj-labs/argocd-notifications/expr/shared"
Expand Down Expand Up @@ -118,15 +119,6 @@ func (svc *argoCDService) GetAppDetails(ctx context.Context, appSource *v1alpha1
if err != nil {
return nil, err
}
data, err := appSource.Helm.Marshal()
if err != nil {
return nil, err
}

fmt.Sprintf("----- appSource: %v", appSource)

appDetail.Helm.Unmarshal(data)
fmt.Sprintf("----- appDetail: %v", appDetail)

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

//if appSource.Helm.Values != "" {
//
// fmt.Printf("-------start output\n")
// output := map[string]string{}
// valuesMap := make(map[interface{}]interface{})
// appSource.Helm.Unmarshal([]byte(appSource.Helm.Values))
//
// fmt.Printf("-------flatVals output\n")
// //for i := range appDetail.Helm.Parameters {
// // if v, ok := output[has.Parameters[i].Name]; ok {
// // has.Parameters[i].Value = v
// // //delete(output, has.Parameters[i].Name)
// // break
// // }
// //}
//
// fmt.Printf("-------after delete output: %v\n", output)
// for i := range appDetail.Helm.Parameters {
// if v, ok := output[appDetail.Helm.Parameters[i].Name]; ok {
// parameter := &v1alpha1.HelmParameter{Name: appDetail.Helm.Parameters[i].Name, Value: v}
// appDetail.Helm.Parameters[i] = parameter
// }
// }
//
// fmt.Printf("-------appSource.Helm.Parameters: %v\n", appSource.Helm.Parameters)
// fmt.Printf("-------appDetail.Helm.Parameters: %v\n", appDetail.Helm.Parameters)
//}
if appSource.Helm.Values != "" {
output := map[string]*v1alpha1.HelmParameter{}
for _, param := range appDetail.Helm.Parameters {
output[param.Name] = param
}
params, err := GetHelmParametersByValues(appSource.Helm.Values)
if err != nil {
return nil, err
}
for k, v := range params {
output[k] = &v1alpha1.HelmParameter{
Name: k,
Value: v,
}
}
appDetail.Helm.Parameters = nil
for k, v := range output {
appDetail.Helm.Parameters = append(appDetail.Helm.Parameters, &v1alpha1.HelmParameter{
Name: k,
Value: v.Value,
ForceString: v.ForceString,
})
}

fmt.Printf("-------flatVals output\n")
//for i := range appDetail.Helm.Parameters {
// if v, ok := output[has.Parameters[i].Name]; ok {
// has.Parameters[i].Value = v
// //delete(output, has.Parameters[i].Name)
// break
// }
//}
}
has = &shared.HelmAppSpec{
Name: appDetail.Helm.Name,
ValueFiles: appDetail.Helm.ValueFiles,
Expand All @@ -189,6 +187,17 @@ func (svc *argoCDService) Close() {
svc.dispose()
}

func GetHelmParametersByValues(values string) (map[string]string, error) {
output := map[string]string{}
valuesMap := map[string]interface{}{}
if err := yaml.Unmarshal([]byte(values), &valuesMap); err != nil {
return nil, fmt.Errorf("failed to parse values: %s", err)
}
flatVals(valuesMap, output)

return output, nil
}

func flatVals(input interface{}, output map[string]string, prefixes ...string) {
switch i := input.(type) {
case map[string]interface{}:
Expand Down

0 comments on commit bb46b21

Please sign in to comment.