Having to generate templates based on the existence of certain files in the tree. the best i find to do this is with multiple ranges in the helm file and some ifs to check but it seams that helm does not like this kind of nesting.
Chart tree
├── ms-values
│ ├── shared
│ │ ├── ms1.yml
│ │ └── ms2.yml
│ └── devops
│ ├── test
│ │ └── ms3.yml
│ ├── ms3.yml
│ └── ms4.yml
├── family-values
│ ├── test
│ │ └── shared.yml
│ ├── devops.yml
│ └── shared.yml
├── global-values
│ ├── test.yml
│ └── dev.yml
├── templates
│ └── micoservices.yml
└── values.yml
i have a file microservices.yml in the templates with this content:
{{ $enviroment := trimSuffix ".yml" (base $globalPath) }}
enviroment: {{ $enviroment }}
{{- range $familyPath, $familyBytes := $.Files.Glob "family-values/*.yml" -}}
{{ $family := trimSuffix ".yml" (base $familyPath) }}
{{- $familyMsPath := print "ms-values/" $family "/*.yml" }}
{{- range $microservicePath, $microserviceBytes := $.Files.Glob $familyMsPath -}}
{{- $microservice := trimSuffix ".yml" (base $microservicePath) -}}
{{- $microserviceExt := base $microservicePath -}}
{{- $envMSPath := print "ms-values/" $family "/" $enviroment "/" $microserviceExt -}}
{{- $microserviceEnv := $.Files.Glob $envMSPath }}
familys: {{ $family }}
enviroment: {{ $enviroment }}
MS: {{ $microservice -}}
{{- if $microserviceEnv }}
MS_PATCH: {{- $envMSPath -}}
{{- end -}}
{{- $FamilyENVPath := print "family-values/" $enviroment "/" $family ".yml" -}}
{{- $FamilyENV := $.Files.Glob $FamilyENVPath }}
{{- if $FamilyENV }}
familyENVpatch: {{ $FamilyENVPath }}
{{ end }}
{{ end }}
{{ end }}
{{ end }}
Runing helm template . --debug i
I have the chart rendered but also this error:
helm.go:81: [debug] error converting YAML to JSON: yaml: line 2: mapping values are not allowed in this context
YAML parse error on argo-apps/templates/microservices.yml
helm.sh/helm/v3/pkg/releaseutil.(*manifestFile).sort
/home/circleci/helm.sh/helm/pkg/releaseutil/manifest_sorter.go:146
helm.sh/helm/v3/pkg/releaseutil.SortManifests
/home/circleci/helm.sh/helm/pkg/releaseutil/manifest_sorter.go:106
helm.sh/helm/v3/pkg/action.(*Configuration).renderResources
/home/circleci/helm.sh/helm/pkg/action/action.go:165
helm.sh/helm/v3/pkg/action.(*Install).Run
/home/circleci/helm.sh/helm/pkg/action/install.go:239
main.runInstall
/home/circleci/helm.sh/helm/cmd/helm/install.go:241
main.newTemplateCmd.func2
/home/circleci/helm.sh/helm/cmd/helm/template.go:70
github.com/spf13/cobra.(*Command).execute
/go/pkg/mod/github.com/spf13/cobra@v1.0.0/command.go:842
github.com/spf13/cobra.(*Command).ExecuteC
/go/pkg/mod/github.com/spf13/cobra@v1.0.0/command.go:950
github.com/spf13/cobra.(*Command).Execute
/go/pkg/mod/github.com/spf13/cobra@v1.0.0/command.go:887
main.main
/home/circleci/helm.sh/helm/cmd/helm/helm.go:80
runtime.main
/usr/local/go/src/runtime/proc.go:203
runtime.goexit
/usr/local/go/src/runtime/asm_amd64.s:1373```
Any ideas??