How to get the name of a child chart with Helm?

落花浮王杯 提交于 2019-12-22 03:56:29

问题


I have a helm chart that requires stable/redis as a child chart. The parent chart needs to expose the redis service as an environment variable.

The redis chart includes a template called redis.fullname. How can I refer to this in my parent chart? I.e. I want something like this in my parent deployment but it doesn't work:

kind: Deployment
spec:
  template:
    containers:
        env:
        - name: REDIS_CLUSTER_SERVICE_HOST
          value: {{ template "redis.fullname" . }}

回答1:


You can use '{{ .Release.Name }}-redis' in your parent chart. I had same requirement. This is my example in case you want to take a look ->https://github.com/kubernetes/charts/tree/master/incubator/distribution




回答2:


Templates are now sharable across parent and child charts. Refer this - https://github.com/kubernetes/helm/blob/master/docs/chart_template_guide/subcharts_and_globals.md#sharing-templates-with-subcharts

Problem that I see will be:

If your redis.fullname template uses a variable (eg: .Values.commonVariable) that has the same name in both the charts but with different value, then, while referencing it in the parent chart, the value that will be used will be of the parent chart and not the child's.

Consider this:

{{- define "zookeeper.fullname" -}}
{{- printf "%s-%s" (.Values.component) (.Values.subcomponent) -}}
{{- end -}}

Although I want my zookeeper.fullname to be referenced in a kafka (parent) chart. But the .Values.component and .Values.subcomponent will be used of kafka and not that for zookeeper (the subchart) in the case, which totally destroys the idea.

The way out in this specific case will be to use Jainish Shah's answer. But if this is not the case, please don't follow that answer. That destroys the idea of templating. If in any way you ought to change the template function in the subchart, you will also need to modify the value {{ .Release.Name }}-redis in your parent chart. This is not templating.

Link for the aforementioned issue - https://github.com/kubernetes/helm/issues/4314



来源:https://stackoverflow.com/questions/47715459/how-to-get-the-name-of-a-child-chart-with-helm

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!