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 8dddaa3 commit ebecda7
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 8 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
4 changes: 3 additions & 1 deletion expr/shared/appdetail.go
Original file line number Diff line number Diff line change
@@ -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
Expand Down
64 changes: 57 additions & 7 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 @@ -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,
Expand All @@ -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)
}
}

0 comments on commit ebecda7

Please sign in to comment.