访问依赖项的 helm 上下文
Access helm context of dependencies
我们正在使用这张图表:
apiVersion: v2
appVersion: 1.0
version: 0.0.1
description: Helm chart for setting up Kafka platform (Kafka, Zookeeper, Kafka Rest, Kafka Schema Registry, Kafka Connect, KSQL Server)
name: kafka-platform
dependencies:
- name: cp-helm-charts
version: 0.6.0
repository: "https://confluentinc.github.io/cp-helm-charts"
我们需要创建 public 图表中不存在的新本地模板,并且这个新模板应该访问 public 图表中定义的内置变量。例如,.Chart.Name
apiVersion: v1
appVersion: "1.0"
description: A Helm chart for Confluent Kafka on Kubernetes
name: cp-kafka
version: 0.1.0
我们如何从本地 .tpl 命名模板或模板访问“cp-kafka”?我现在设法访问的是类型错误“<.Chart.Name>:无法评估 int 类型的字段图表”或本地图表“kafka-platform”的值。
我已经搜索过这个question/answer,但虽然我看到了相似的东西,但我没有找到完全适合或回答这个确切问题的东西。
可以使用子图映射。
{{ $sub := index .Subcharts "cp-kafka" }}
这将为您提供所有内置变量,甚至是值文件中的 .Values
。
比如我创建一个图表和一个子图表:
helm create foo
helm create foo/charts/bar
rm -rf foo/templates/*
rm -rf foo/charts/bar/templates/*
在条值中,我输入了这个:
some:
values: from
this: subchart
在 foo 模板中,我放置了这个配置映射:
kind: ConfigMap
apiVersion: v1
metadata:
name: example
data:
bar-chart: |
{{- .Subcharts.bar | toYaml | nindent 4 }}
现在,当我使用 helm template foo
渲染图表时,我得到以下输出:
---
# Source: foo/templates/cm.yaml
kind: ConfigMap
apiVersion: v1
metadata:
name: example
data:
bar-chart: |
Capabilities:
APIVersions:
- v1
- admissionregistration.k8s.io/v1
- admissionregistration.k8s.io/v1beta1
- internal.apiserver.k8s.io/v1alpha1
- apps/v1
- apps/v1beta1
- apps/v1beta2
- authentication.k8s.io/v1
- authentication.k8s.io/v1beta1
- authorization.k8s.io/v1
- authorization.k8s.io/v1beta1
- autoscaling/v1
- autoscaling/v2
- autoscaling/v2beta1
- autoscaling/v2beta2
- batch/v1
- batch/v1beta1
- certificates.k8s.io/v1
- certificates.k8s.io/v1beta1
- coordination.k8s.io/v1beta1
- coordination.k8s.io/v1
- discovery.k8s.io/v1
- discovery.k8s.io/v1beta1
- events.k8s.io/v1
- events.k8s.io/v1beta1
- extensions/v1beta1
- flowcontrol.apiserver.k8s.io/v1alpha1
- flowcontrol.apiserver.k8s.io/v1beta1
- flowcontrol.apiserver.k8s.io/v1beta2
- networking.k8s.io/v1
- networking.k8s.io/v1beta1
- node.k8s.io/v1
- node.k8s.io/v1alpha1
- node.k8s.io/v1beta1
- policy/v1
- policy/v1beta1
- rbac.authorization.k8s.io/v1
- rbac.authorization.k8s.io/v1beta1
- rbac.authorization.k8s.io/v1alpha1
- scheduling.k8s.io/v1alpha1
- scheduling.k8s.io/v1beta1
- scheduling.k8s.io/v1
- storage.k8s.io/v1beta1
- storage.k8s.io/v1
- storage.k8s.io/v1alpha1
- apiextensions.k8s.io/v1beta1
- apiextensions.k8s.io/v1
HelmVersion:
git_commit: 6e3701edea09e5d55a8ca2aae03a68917630e91b
git_tree_state: clean
go_version: go1.17.5
version: v3.8.2
KubeVersion:
Major: "1"
Minor: "23"
Version: v1.23.0
Chart:
IsRoot: false
apiVersion: v2
appVersion: 1.16.0
description: A Helm chart for Kubernetes
name: bar
type: application
version: 0.1.0
Files:
.helmignore: IyBQYXR0ZXJucyB0byBpZ25vcmUgd2hlbiBidWlsZGluZyBwYWNrYWdlcy4KIyBUaGlzIHN1cHBvcnRzIHNoZWxsIGdsb2IgbWF0Y2hpbmcsIHJlbGF0aXZlIHBhdGggbWF0Y2hpbmcsIGFuZAojIG5lZ2F0aW9uIChwcmVmaXhlZCB3aXRoICEpLiBPbmx5IG9uZSBwYXR0ZXJuIHBlciBsaW5lLgouRFNfU3RvcmUKIyBDb21tb24gVkNTIGRpcnMKLmdpdC8KLmdpdGlnbm9yZQouYnpyLwouYnpyaWdub3JlCi5oZy8KLmhnaWdub3JlCi5zdm4vCiMgQ29tbW9uIGJhY2t1cCBmaWxlcwoqLnN3cAoqLmJhawoqLnRtcAoqLm9yaWcKKn4KIyBWYXJpb3VzIElERXMKLnByb2plY3QKLmlkZWEvCioudG1wcm9qCi52c2NvZGUvCg==
Release:
IsInstall: true
IsUpgrade: false
Name: release-name
Namespace: default
Revision: 1
Service: Helm
Subcharts: {}
Values:
global: {}
some:
this: subchart
values: from
我们正在使用这张图表:
apiVersion: v2
appVersion: 1.0
version: 0.0.1
description: Helm chart for setting up Kafka platform (Kafka, Zookeeper, Kafka Rest, Kafka Schema Registry, Kafka Connect, KSQL Server)
name: kafka-platform
dependencies:
- name: cp-helm-charts
version: 0.6.0
repository: "https://confluentinc.github.io/cp-helm-charts"
我们需要创建 public 图表中不存在的新本地模板,并且这个新模板应该访问 public 图表中定义的内置变量。例如,.Chart.Name
apiVersion: v1
appVersion: "1.0"
description: A Helm chart for Confluent Kafka on Kubernetes
name: cp-kafka
version: 0.1.0
我们如何从本地 .tpl 命名模板或模板访问“cp-kafka”?我现在设法访问的是类型错误“<.Chart.Name>:无法评估 int 类型的字段图表”或本地图表“kafka-platform”的值。
我已经搜索过这个question/answer,但虽然我看到了相似的东西,但我没有找到完全适合或回答这个确切问题的东西。
可以使用子图映射。
{{ $sub := index .Subcharts "cp-kafka" }}
这将为您提供所有内置变量,甚至是值文件中的 .Values
。
比如我创建一个图表和一个子图表:
helm create foo
helm create foo/charts/bar
rm -rf foo/templates/*
rm -rf foo/charts/bar/templates/*
在条值中,我输入了这个:
some:
values: from
this: subchart
在 foo 模板中,我放置了这个配置映射:
kind: ConfigMap
apiVersion: v1
metadata:
name: example
data:
bar-chart: |
{{- .Subcharts.bar | toYaml | nindent 4 }}
现在,当我使用 helm template foo
渲染图表时,我得到以下输出:
---
# Source: foo/templates/cm.yaml
kind: ConfigMap
apiVersion: v1
metadata:
name: example
data:
bar-chart: |
Capabilities:
APIVersions:
- v1
- admissionregistration.k8s.io/v1
- admissionregistration.k8s.io/v1beta1
- internal.apiserver.k8s.io/v1alpha1
- apps/v1
- apps/v1beta1
- apps/v1beta2
- authentication.k8s.io/v1
- authentication.k8s.io/v1beta1
- authorization.k8s.io/v1
- authorization.k8s.io/v1beta1
- autoscaling/v1
- autoscaling/v2
- autoscaling/v2beta1
- autoscaling/v2beta2
- batch/v1
- batch/v1beta1
- certificates.k8s.io/v1
- certificates.k8s.io/v1beta1
- coordination.k8s.io/v1beta1
- coordination.k8s.io/v1
- discovery.k8s.io/v1
- discovery.k8s.io/v1beta1
- events.k8s.io/v1
- events.k8s.io/v1beta1
- extensions/v1beta1
- flowcontrol.apiserver.k8s.io/v1alpha1
- flowcontrol.apiserver.k8s.io/v1beta1
- flowcontrol.apiserver.k8s.io/v1beta2
- networking.k8s.io/v1
- networking.k8s.io/v1beta1
- node.k8s.io/v1
- node.k8s.io/v1alpha1
- node.k8s.io/v1beta1
- policy/v1
- policy/v1beta1
- rbac.authorization.k8s.io/v1
- rbac.authorization.k8s.io/v1beta1
- rbac.authorization.k8s.io/v1alpha1
- scheduling.k8s.io/v1alpha1
- scheduling.k8s.io/v1beta1
- scheduling.k8s.io/v1
- storage.k8s.io/v1beta1
- storage.k8s.io/v1
- storage.k8s.io/v1alpha1
- apiextensions.k8s.io/v1beta1
- apiextensions.k8s.io/v1
HelmVersion:
git_commit: 6e3701edea09e5d55a8ca2aae03a68917630e91b
git_tree_state: clean
go_version: go1.17.5
version: v3.8.2
KubeVersion:
Major: "1"
Minor: "23"
Version: v1.23.0
Chart:
IsRoot: false
apiVersion: v2
appVersion: 1.16.0
description: A Helm chart for Kubernetes
name: bar
type: application
version: 0.1.0
Files:
.helmignore: IyBQYXR0ZXJucyB0byBpZ25vcmUgd2hlbiBidWlsZGluZyBwYWNrYWdlcy4KIyBUaGlzIHN1cHBvcnRzIHNoZWxsIGdsb2IgbWF0Y2hpbmcsIHJlbGF0aXZlIHBhdGggbWF0Y2hpbmcsIGFuZAojIG5lZ2F0aW9uIChwcmVmaXhlZCB3aXRoICEpLiBPbmx5IG9uZSBwYXR0ZXJuIHBlciBsaW5lLgouRFNfU3RvcmUKIyBDb21tb24gVkNTIGRpcnMKLmdpdC8KLmdpdGlnbm9yZQouYnpyLwouYnpyaWdub3JlCi5oZy8KLmhnaWdub3JlCi5zdm4vCiMgQ29tbW9uIGJhY2t1cCBmaWxlcwoqLnN3cAoqLmJhawoqLnRtcAoqLm9yaWcKKn4KIyBWYXJpb3VzIElERXMKLnByb2plY3QKLmlkZWEvCioudG1wcm9qCi52c2NvZGUvCg==
Release:
IsInstall: true
IsUpgrade: false
Name: release-name
Namespace: default
Revision: 1
Service: Helm
Subcharts: {}
Values:
global: {}
some:
this: subchart
values: from