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 26, 2022
1 parent 8dddaa3 commit e3072b0
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 4 deletions.
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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
Expand Down
50 changes: 46 additions & 4 deletions shared/argocd/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package argocd
import (
"context"
"fmt"
"k8s.io/apimachinery/pkg/util/yaml"
"strings"

"github.com/argoproj-labs/argocd-notifications/expr/shared"
"github.com/argoproj/argo-cd/v2/common"
Expand Down Expand Up @@ -117,10 +119,8 @@ 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 {
Expand All @@ -132,11 +132,37 @@ func (svc *argoCDService) GetAppDetails(ctx context.Context, appSource *v1alpha1
}
}

if appSource.Helm.Values != "" {
output := map[string]string{}
valuesMap := make(map[string]interface{})
if err := yaml.Unmarshal([]byte(appSource.Helm.Values), valuesMap); err != nil {
return nil, fmt.Errorf("failed to parse : %s, appSource.Helm.Values: %v", err, appSource.Helm.Values)
}
flatVals(valuesMap, output)

fmt.Printf("-------flatVals output: %v", output)
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", output)

for k, v := range output {
appDetail.Helm.Parameters = append(appDetail.Helm.Parameters, &v1alpha1.HelmParameter{Name: k, Value: v})
}

fmt.Printf("-------appDetail.Helm.Parameters: %v", appDetail.Helm.Parameters)
}

has = &shared.HelmAppSpec{
Name: appDetail.Helm.Name,
ValueFiles: appDetail.Helm.ValueFiles,
ValueFiles: appSource.Helm.ValueFiles,
Parameters: appDetail.Helm.Parameters,
Values: appDetail.Helm.Values,
Values: appSource.Helm.Values,
FileParameters: appDetail.Helm.FileParameters,
}
}
Expand All @@ -152,3 +178,19 @@ func (svc *argoCDService) GetAppDetails(ctx context.Context, appSource *v1alpha1
func (svc *argoCDService) Close() {
svc.dispose()
}

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)
}
}

0 comments on commit e3072b0

Please sign in to comment.