使用头盔模板助手创建过滤列表

问题描述 投票:0回答:1

[我正在尝试使用头盔模板助手,根据每个列表成员中一个键的值,从values.yaml文件中的列表中筛选出值。

我的图表目前由这些文件组成-values.yaml-

namespaces:
- name: filter
  profiles:
  - nonProduction
- name: dont-filter
  profiles:
  - production  
clusterProfile: production

templates / namespaces.yaml

apiVersion: v1
kind: List
items:
{{ $filteredList := include "filteredNamespaces" . }}
{{ range $filteredList }}
  {{ .name }}
{{- end -}}

templates / _profile-match.tpl

{{/* vim: set filetype=mustache: */}}
{{- define "filteredNamespaces" -}}
  {{ $newList := list }}
  {{- range .Values.namespaces }}
    {{- if has $.Values.clusterProfile .profiles -}}
      {{ $newList := append $newList . }}
    {{- end -}}
  {{ end -}}
  {{ $newList }}
{{- end -}}

问题是,在我的帮助文件中,$newList变量仅填充在range循环的范围内,最后我得到一个空列表,返回到namespaces.yaml模板。有什么办法可以解决这个问题?我是否采用错误的方法来解决此问题?

kubernetes kubernetes-helm go-templates sprig-template-functions
1个回答
0
投票

对于所有Go模板都是几乎

© www.soinside.com 2019 - 2024. All rights reserved.