English 中文(简体)
helm with if condition and its scope for the value set
原标题:

I would like to overwrite the user template with .Values.userTemplate if it exist. But I always get $user as undefined when the .Vaues.userTemplate exist. If i remove if condition and use {{- $user := tpl .Values.userTemplate . -}}, it gives right value. But inside if codition it is not setting the value for $user.

Is there anything was doing wrong? Was the scope of $user will be only retained inside the if condition? Was there a way to overwrite the $user if .Values.userTemplate exist.

    # values
    user: "default"
       # somewhere in other chart we define the  template
    userTemplate:  {{ include "username" . }} 

    # template
    {{- define "user" -}}
    {{- if .Values.userTemplate -}}
    {{- $user := tpl .Values.userTemplate . -}}
    {{- else -}}
    {{- $user := .Values.user -}}
    {{- end -}}
    {{- $user -}}

    # output of `{{ template "user" . }}` should be the value set in `{{ template "username" . }} in different chart. 

Tom
问题回答

I use helm 2.10. I did a small test. If I understand correctly it is what you want:

values.yml:

user: "default"
userTemplate:  {{ include "userName" . }} 
otherName: "john"

_helpers.tpl:

{{- define "userName" -}}
{{- .Values.otherName -}}
{{- end -}}

{{- define "user" -}}
{{- if .Values.userTemplate -}}
{{- tpl .Values.userTemplate . -}}
{{- else -}}
{{- .Values.user -}}
{{- end -}}
{{- end -}}

test.yml:

name: {{ template "user" . }}

With a userTemplate, I got john, without userTemplate I got default.





相关问题
HTTP call from Celery worker

I am running a Flask-Celery server in docker desktop Kubernetes. It uses a Redis Result Backend. I want to use a Celery Task to make an HTTP call to a program that might take a while. This program ...

Why my website cookies are not being set on my browser?

Hello I am developing a web app, with a microservices architecture. I am using golang (Fiber) on the backend and Next.js on the frontend. When I send a request from restaurant.quiqr.co/signin to api....

我如何终止Kubernetes的名称空间?

我正试图终止Kubernetes的名称空间。 过去,我uc切地遵循了在库韦涅斯这里发现的在终止地位方面摇摇摇欲坠的空地。

helm with if condition and its scope for the value set

I would like to overwrite the user template with .Values.userTemplate if it exist. But I always get $user as undefined when the .Vaues.userTemplate exist. If i remove if condition and use {{- $user := ...

热门标签