From 8dddaa3ec2d963bc821c66c080db4a2ed208b58c Mon Sep 17 00:00:00 2001 From: ss75710541 <75710541@qq.com> Date: Tue, 15 Mar 2022 12:04:54 +0800 Subject: [PATCH 1/3] fix: GetParameterValueByName gets the default value changed to the override value --- shared/argocd/service.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/shared/argocd/service.go b/shared/argocd/service.go index cbc1c670..349fe975 100644 --- a/shared/argocd/service.go +++ b/shared/argocd/service.go @@ -117,8 +117,21 @@ func (svc *argoCDService) GetAppDetails(ctx context.Context, appSource *v1alpha1 if err != nil { return nil, err } + var has *shared.HelmAppSpec if appDetail.Helm != nil { + + if appSource.Helm.Parameters != nil { + for _, overrideParam := range appSource.Helm.Parameters { + for _, defaultParam := range appDetail.Helm.Parameters { + if overrideParam.Name == defaultParam.Name { + defaultParam.Value = overrideParam.Value + defaultParam.ForceString = overrideParam.ForceString + } + } + } + } + has = &shared.HelmAppSpec{ Name: appDetail.Helm.Name, ValueFiles: appDetail.Helm.ValueFiles, From ebecda74ffebf0c30a0733b9090c3db23ef4d207 Mon Sep 17 00:00:00 2001 From: ss75710541 <75710541@qq.com> Date: Wed, 27 Apr 2022 16:14:19 +0800 Subject: [PATCH 2/3] fix: repo.GetAppDetails().Helm.GetParameterValueByName not get helm.values --- Dockerfile | 1 + expr/shared/appdetail.go | 4 ++- shared/argocd/service.go | 64 +++++++++++++++++++++++++++++++++++----- 3 files changed, 61 insertions(+), 8 deletions(-) diff --git a/Dockerfile b/Dockerfile index c3fc826a..1437a1c2 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,3 +1,4 @@ +ARG BUILDPLATFORM=linux/amd64 FROM --platform=$BUILDPLATFORM golang:1.16.2 as builder RUN apt-get update && apt-get install ca-certificates diff --git a/expr/shared/appdetail.go b/expr/shared/appdetail.go index 451fb732..f5fd8fdb 100644 --- a/expr/shared/appdetail.go +++ b/expr/shared/appdetail.go @@ -1,6 +1,8 @@ package shared -import "github.com/argoproj/argo-cd/v2/reposerver/apiclient" +import ( + "github.com/argoproj/argo-cd/v2/reposerver/apiclient" +) type AppDetail struct { // AppDetail Type diff --git a/shared/argocd/service.go b/shared/argocd/service.go index 349fe975..457614a7 100644 --- a/shared/argocd/service.go +++ b/shared/argocd/service.go @@ -3,6 +3,8 @@ package argocd import ( "context" "fmt" + "github.com/ghodss/yaml" + "strings" "github.com/argoproj-labs/argocd-notifications/expr/shared" "github.com/argoproj/argo-cd/v2/common" @@ -120,18 +122,39 @@ func (svc *argoCDService) GetAppDetails(ctx context.Context, appSource *v1alpha1 var has *shared.HelmAppSpec if appDetail.Helm != nil { - + paramsMap := map[string]*v1alpha1.HelmParameter{} if appSource.Helm.Parameters != nil { for _, overrideParam := range appSource.Helm.Parameters { - for _, defaultParam := range appDetail.Helm.Parameters { - if overrideParam.Name == defaultParam.Name { - defaultParam.Value = overrideParam.Value - defaultParam.ForceString = overrideParam.ForceString - } + paramsMap[overrideParam.Name] = &v1alpha1.HelmParameter{ + Name: overrideParam.Name, + Value: overrideParam.Value, + ForceString: overrideParam.ForceString, } } } - + if appSource.Helm.Values != "" { + for _, param := range appDetail.Helm.Parameters { + paramsMap[param.Name] = param + } + valuesParams, err := GetHelmParametersByValues(appSource.Helm.Values) + if err != nil { + return nil, err + } + for k, v := range valuesParams { + paramsMap[k] = &v1alpha1.HelmParameter{ + Name: k, + Value: v, + } + } + appDetail.Helm.Parameters = nil + for k, v := range paramsMap { + appDetail.Helm.Parameters = append(appDetail.Helm.Parameters, &v1alpha1.HelmParameter{ + Name: k, + Value: v.Value, + ForceString: v.ForceString, + }) + } + } has = &shared.HelmAppSpec{ Name: appDetail.Helm.Name, ValueFiles: appDetail.Helm.ValueFiles, @@ -152,3 +175,30 @@ func (svc *argoCDService) GetAppDetails(ctx context.Context, appSource *v1alpha1 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{}: + for k, v := range i { + flatVals(v, output, append(prefixes, k)...) + } + case []interface{}: + p := append([]string(nil), prefixes...) + for j, v := range i { + flatVals(v, output, append(p[0:len(p)-1], fmt.Sprintf("%s[%v]", prefixes[len(p)-1], j))...) + } + default: + output[strings.Join(prefixes, ".")] = fmt.Sprintf("%v", i) + } +} From 62a81a17acda6fe7e39742d4f368231ec3beb559 Mon Sep 17 00:00:00 2001 From: ss75710541 <75710541@qq.com> Date: Wed, 27 Apr 2022 17:00:02 +0800 Subject: [PATCH 3/3] fix: repo.GetAppDetails().Helm.GetParameterValueByName not get helm.values --- expr/shared/appdetail.go | 4 +--- shared/argocd/service.go | 6 +++--- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/expr/shared/appdetail.go b/expr/shared/appdetail.go index f5fd8fdb..451fb732 100644 --- a/expr/shared/appdetail.go +++ b/expr/shared/appdetail.go @@ -1,8 +1,6 @@ package shared -import ( - "github.com/argoproj/argo-cd/v2/reposerver/apiclient" -) +import "github.com/argoproj/argo-cd/v2/reposerver/apiclient" type AppDetail struct { // AppDetail Type diff --git a/shared/argocd/service.go b/shared/argocd/service.go index 457614a7..6ba4d7f4 100644 --- a/shared/argocd/service.go +++ b/shared/argocd/service.go @@ -123,6 +123,9 @@ func (svc *argoCDService) GetAppDetails(ctx context.Context, appSource *v1alpha1 var has *shared.HelmAppSpec if appDetail.Helm != nil { paramsMap := map[string]*v1alpha1.HelmParameter{} + for _, param := range appDetail.Helm.Parameters { + paramsMap[param.Name] = param + } if appSource.Helm.Parameters != nil { for _, overrideParam := range appSource.Helm.Parameters { paramsMap[overrideParam.Name] = &v1alpha1.HelmParameter{ @@ -133,9 +136,6 @@ func (svc *argoCDService) GetAppDetails(ctx context.Context, appSource *v1alpha1 } } if appSource.Helm.Values != "" { - for _, param := range appDetail.Helm.Parameters { - paramsMap[param.Name] = param - } valuesParams, err := GetHelmParametersByValues(appSource.Helm.Values) if err != nil { return nil, err