首页 文章

获取Helm Charts中的文件夹列表

提问于
浏览
0

获得了位于templates文件夹之外的配置文件列表,我们将其输入到如下的helm图表中:

├── configs
│   ├── AllEnvironments
│   │   ├── Infrastructure
│   │   └── Services
│   │       ├── ConfigFile1
│   │       ├── ConfigFile2
│   ├── Apps
│   │   ├── App1
│   │   ├── App2
│   │   └── App3
│   ├── ManagementEnvironments
│   │   ├── Database
│   │   │   ├── DbFile1
│   │   │   └── DbFile2
│   │   ├── Infrastructure
│   ├── TestEnvironments
│   │   ├── Pipeline
│   │   │   └── Pipeline1
│   │   ├── Database
│   │   │   ├── Pipeline2
│   ├── Console
│   │   ├── Console1
│   │   ├── Console2

到目前为止,它对我们有益 . 现在我们需要解析文件夹并获取配置文件中不以环境结尾的所有文件夹的列表 . 因此,在这种情况下,基本上包括应用程序和控制台 .

执行以下操作时,我会重复应用3次,因为许多文件都在其下面,而控制台则是2次 .

我想获得一个文件夹列表,这些文件夹不会仅以环境结束一次 .

我试着看看Go模板和一些掌舵图工具包,但我没有Go的经验,这似乎是要求实现这一点,我可能会接下来的几天 . 但是现在我被困住了,所以任何帮助都会受到赞赏 .

{{- range $path, $bytes  := $.Files.Glob "configs/**" }}
{{- if not (or (dir $path | regexFind "configs.*Environments.*")  (dir $path | regexFind "configs$")) }}
 {{ base (dir $path) }}

{{- end }}
{{- end }}

1 回答

  • 0

    如果它可以帮助其他任何人,这是一种方法:

    Helm图表使用Go模板和Sprig库 . 因此,使用Sprig的dict,我们可以保留我们列出的文件夹的先前值,只有当前文件夹与前一个文件夹不同时才打印出来 . 现在这可以工作,因为文件按字母顺序列出,因此同一文件夹上的文件将是连续的 . 如果要在没有订单的情况下阅读它们,这些方法将无效 .

    {{- $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 }}
    

相关问题