kiemon
kiemon

Reputation: 31

Could I use variables in helm chart in script?

I have something like this

args: ["-c", "while [ $(curl -sw '%{http_code}' "http://{{ include "backend.name" . }}-{{ .Release.Namespace }}:80/actuator/health"-o /dev/null) -ne 200 ]; do sleep 30; done"

Should it run correctly? Or is there any chance I can check it without deploying it?

Upvotes: 0

Views: 580

Answers (1)

z.x
z.x

Reputation: 2527

There are two options you can use.

As follows:

  1. Variables and structures are defined in values.yaml, and then directly introduced where they need to be used

deployment.yaml

apiVersion: apps/v1
kind: Deployment
metadata:
  name: "test"
spec:
  template:
    spec:
      containers:
        - name: "test"
          image: "test:v1.0"
          {{- if .Values.args }}
          args:
            {{ toYaml .Values.args | nindent 12 }}
          {{- end }}

values.yaml

args:
  - -c
  - while [ $(curl -sw 'http://xx.xx.xx.xx' "http://xx.xx.xx.xx:80/actuator/health"-o /dev/null) -ne 200 ]; do sleep 30; done
  1. Define the structure in deployment.yaml, then define variables in values.yaml, and then deployment references values

deployment.yaml

apiVersion: apps/v1
kind: Deployment
metadata:
  name: "test"
spec:
  template:
    spec:
      containers:
        - name: "test"
          image: "test:v1.0"
          {{- if .Values.args }}
          args:
            - {{ .Values.args.lv }}
            - while [ $(curl -sw '{{ .Values.args.code }}' "http://{{ include "backend.name" . }}-{{ .Release.Namespace }}:80/actuator/health"-o /dev/null) -ne 200 ]; do sleep 30; done
          {{- end }}

values.yaml

args:
  lv: -c
  code: http://0.0.0.0

Upvotes: 1

Related Questions