diff --git a/pkg/kfapp/kustomize/kustomize.go b/pkg/kfapp/kustomize/kustomize.go index b4d6973068f..5c6d8aa617f 100644 --- a/pkg/kfapp/kustomize/kustomize.go +++ b/pkg/kfapp/kustomize/kustomize.go @@ -26,6 +26,7 @@ import ( "os" "path" "path/filepath" + "regexp" "strconv" "strings" "time" @@ -835,6 +836,30 @@ func WriteKfDef(kfdef *kfdefsv3.KfDef, kfdefpath string) error { return nil } +func getParameterValue(value string) string { + // Check if there is a environment variable + // Supported format: $VAR and {$VAR} + var re = regexp.MustCompile(`(?m)^(\$)|{\$(.*)}`) + envVariable := "" + if re.Match([]byte(value)){ + log.Info("Match made for regex") + if strings.HasPrefix(value, "$"){ + log.Infof("starts with $ : %v", value) + envVariable = value[1:] + }else if strings.HasPrefix(value, "{") { + envVariable = value[2:len(value)-1] + }else { + return value + } + log.Infof("Value of variable :%v", envVariable) + log.Info(os.Getenv(envVariable)) + return os.Getenv(envVariable) + + } + return value +} + + // MergeKustomization will merge the child into the parent // if the child has no bases, then the parent just needs to add the child as base // otherwise the parent needs to merge with behaviors @@ -846,7 +871,7 @@ func MergeKustomization(compDir string, targetDir string, kfDef *kfconfig.KfConf paramMap := make(map[string]string) for _, nv := range params { - paramMap[nv.Name] = nv.Value + paramMap[nv.Name] = getParameterValue(nv.Value) } updateParamFiles := func() error { paramFile := filepath.Join(targetDir, kftypesv3.KustomizationParamFile) diff --git a/pkg/kfconfig/types.go b/pkg/kfconfig/types.go index a2b9dec3ff8..ed7e2acfe1c 100644 --- a/pkg/kfconfig/types.go +++ b/pkg/kfconfig/types.go @@ -21,7 +21,6 @@ import ( "os" "path" "path/filepath" - "regexp" "sigs.k8s.io/kustomize/v3/pkg/types" "strings" ) @@ -1032,31 +1031,13 @@ func IsAppNotFound(e error) bool { func getParameter(parameters []NameValue, paramName string) (string, bool) { for _, p := range parameters { if p.Name == paramName { - return getParameterValue(p.Value), true + return p.Value, true } } return "", false } -func getParameterValue(value string) string { - // Check if there is a environment variable - // Supported format: $VAR and {$VAR} - var re = regexp.MustCompile(`(?m)^(\$)|{\$(.*)}`) - envVariable := "" - if re.Match([]byte(value)){ - if strings.HasPrefix(value, "$"){ - envVariable = value[1:] - }else if strings.HasPrefix(value, "{") { - envVariable = value[2:len(value)-1] - }else { - return value - } - return os.Getenv(envVariable) - } - return value -} - func setParameter(parameters []NameValue, paramName string, value string) []NameValue { pIndex := -1