Got a list of config files that reside outside of templates folder that we feed into a helm chart like the following:
├── configs
│ ├── AllEnvironments
│ │ ├── Infrastructure
│ │ └── Services
│ │ ├── ConfigFile1
│ │ ├── ConfigFile2
│ ├── Apps
│ │ ├── App1
│ │ ├── App2
│ │ └── App3
│ ├── ManagementEnvironments
│ │ ├── Database
│ │ │ ├── DbFile1
│ │ │ └── DbFile2
│ │ ├── Infrastructure
│ ├── TestEnvironments
│ │ ├── Pipeline
│ │ │ └── Pipeline1
│ │ ├── Database
│ │ │ ├── Pipeline2
│ ├── Console
│ │ ├── Console1
│ │ ├── Console2
It works out good for us so far. Now we need to parse the folders and get a list of all the folders under configs that do not end with Environments. So basically a range that would include Apps and Console in this case.
Doing the following I get a repetition of Apps 3 times as that many files are under it and also Console 2 times.
I would like to get a list of folders that do not end with Environments only once.
I tried to look at the Go templates and some helm chart toolkits but I have no experience in Go which seems like a requirement to make this happen and I will probably take on the next few days. But for now I'm stuck, so any help is appreciated.
{{- range $path, $bytes := $.Files.Glob "configs/**" }}
{{- if not (or (dir $path | regexFind "configs.*Environments.*") (dir $path | regexFind "configsquot;)) }}
{{ base (dir $path) }}
{{- end }}
{{- end }}
Here is a way to do it if it will help anyone else:
Helm charts uses Go template and Sprig library. So using a dict from Sprig we can keep the previous value of the folder that we are listing and we print it out only if the current folder is different from the previous one. Now this works as the files are listed in alphabetical order so files on the same folder will be consecutive. If they were to be read without order these approach would not work.
{{- $localDict := dict "previous" "-"}}
{{- range $path, $bytes := $.Files.Glob "configs/**" }}
{{- if not (or (dir $path | regexFind "configs.*Environments.*") (dir $path | regexFind "configsquot;)) }}
{{- $folder := base (dir $path) }}
{{- if not (eq $folder $localDict.previous)}}
{{$folder -}}
{{- end }}
{{- $_ := set $localDict "previous" $folder -}}
{{- end }}
{{- end }}