获取 Helm Charts 中的文件夹列表
getting a list of folders in Helm Charts
获得了位于模板文件夹之外的配置文件列表,我们将其输入到 helm chart 中,如下所示:
├── configs
│ ├── AllEnvironments
│ │ ├── Infrastructure
│ │ └── Services
│ │ ├── ConfigFile1
│ │ ├── ConfigFile2
│ ├── Apps
│ │ ├── App1
│ │ ├── App2
│ │ └── App3
│ ├── ManagementEnvironments
│ │ ├── Database
│ │ │ ├── DbFile1
│ │ │ └── DbFile2
│ │ ├── Infrastructure
│ ├── TestEnvironments
│ │ ├── Pipeline
│ │ │ └── Pipeline1
│ │ ├── Database
│ │ │ ├── Pipeline2
│ ├── Console
│ │ ├── Console1
│ │ ├── Console2
到目前为止对我们来说效果很好。现在我们需要解析文件夹并获取 configs 下不以 Environments 结尾的所有文件夹的列表。在这种情况下,基本上是一个包括应用程序和控制台的范围。
执行以下操作后,我重复了 3 次 Apps,因为它下面有很多文件,还有 2 次 Console。
我想获得一个不以环境结尾的文件夹列表。
我试图查看 Go 模板和一些 helm chart 工具包,但我没有 Go 方面的经验,这似乎是实现这一目标的必要条件,我可能会在接下来的几天内完成。但现在我卡住了,所以任何帮助表示赞赏。
{{- range $path, $bytes := $.Files.Glob "configs/**" }}
{{- if not (or (dir $path | regexFind "configs.*Environments.*") (dir $path | regexFind "configs$")) }}
{{ base (dir $path) }}
{{- end }}
{{- end }}
如果对其他人有帮助的话,这里有一个方法:
Helm 图表使用 Go 模板和 Sprig 库。因此,使用来自 Sprig 的字典,我们可以保留我们列出的文件夹的先前值,并且仅当当前文件夹与前一个文件夹不同时才将其打印出来。现在这是可行的,因为文件按字母顺序列出,因此同一文件夹中的文件将是连续的。如果不按顺序阅读它们,这些方法将行不通。
{{- $localDict := dict "previous" "-"}}
{{- range $path, $bytes := $.Files.Glob "configs/**" }}
{{- if not (or (dir $path | regexFind "configs.*Environments.*") (dir $path | regexFind "configs$")) }}
{{- $folder := base (dir $path) }}
{{- if not (eq $folder $localDict.previous)}}
{{$folder -}}
{{- end }}
{{- $_ := set $localDict "previous" $folder -}}
{{- end }}
{{- end }}
今天,使用 Helm v3.3,您仍然无法使用图表文件夹外的文件。
这是一个大问题,您可以在这里关注:
获得了位于模板文件夹之外的配置文件列表,我们将其输入到 helm chart 中,如下所示:
├── configs
│ ├── AllEnvironments
│ │ ├── Infrastructure
│ │ └── Services
│ │ ├── ConfigFile1
│ │ ├── ConfigFile2
│ ├── Apps
│ │ ├── App1
│ │ ├── App2
│ │ └── App3
│ ├── ManagementEnvironments
│ │ ├── Database
│ │ │ ├── DbFile1
│ │ │ └── DbFile2
│ │ ├── Infrastructure
│ ├── TestEnvironments
│ │ ├── Pipeline
│ │ │ └── Pipeline1
│ │ ├── Database
│ │ │ ├── Pipeline2
│ ├── Console
│ │ ├── Console1
│ │ ├── Console2
到目前为止对我们来说效果很好。现在我们需要解析文件夹并获取 configs 下不以 Environments 结尾的所有文件夹的列表。在这种情况下,基本上是一个包括应用程序和控制台的范围。
执行以下操作后,我重复了 3 次 Apps,因为它下面有很多文件,还有 2 次 Console。
我想获得一个不以环境结尾的文件夹列表。
我试图查看 Go 模板和一些 helm chart 工具包,但我没有 Go 方面的经验,这似乎是实现这一目标的必要条件,我可能会在接下来的几天内完成。但现在我卡住了,所以任何帮助表示赞赏。
{{- range $path, $bytes := $.Files.Glob "configs/**" }}
{{- if not (or (dir $path | regexFind "configs.*Environments.*") (dir $path | regexFind "configs$")) }}
{{ base (dir $path) }}
{{- end }}
{{- end }}
如果对其他人有帮助的话,这里有一个方法:
Helm 图表使用 Go 模板和 Sprig 库。因此,使用来自 Sprig 的字典,我们可以保留我们列出的文件夹的先前值,并且仅当当前文件夹与前一个文件夹不同时才将其打印出来。现在这是可行的,因为文件按字母顺序列出,因此同一文件夹中的文件将是连续的。如果不按顺序阅读它们,这些方法将行不通。
{{- $localDict := dict "previous" "-"}}
{{- range $path, $bytes := $.Files.Glob "configs/**" }}
{{- if not (or (dir $path | regexFind "configs.*Environments.*") (dir $path | regexFind "configs$")) }}
{{- $folder := base (dir $path) }}
{{- if not (eq $folder $localDict.previous)}}
{{$folder -}}
{{- end }}
{{- $_ := set $localDict "previous" $folder -}}
{{- end }}
{{- end }}
今天,使用 Helm v3.3,您仍然无法使用图表文件夹外的文件。
这是一个大问题,您可以在这里关注: