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

fix: repo.GetAppDetails().Helm.parameters not get argocd override value #392

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
63 changes: 63 additions & 0 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"
"github.com/ghodss/yaml"
"strings"

"github.com/argoproj-labs/argocd-notifications/expr/shared"
"github.com/argoproj/argo-cd/v2/common"
Expand Down Expand Up @@ -117,8 +119,42 @@ func (svc *argoCDService) GetAppDetails(ctx context.Context, appSource *v1alpha1
if err != nil {
return nil, err
}

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{
Name: overrideParam.Name,
Value: overrideParam.Value,
ForceString: overrideParam.ForceString,
}
}
}
if appSource.Helm.Values != "" {
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,
Expand All @@ -139,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)
}
}