rajiv chodisetti
rajiv chodisetti

Reputation: 21

Helm Environment Variables in if else

When am building the image path, this is how I want to build the image Path, where the docker registry address, I want to fetch it from the configMap.

I can't hard code the registry address in the values.yaml file because for each customer the registry address would be different and I don't want to ask customer to enter this input manually. These helm charts are deployed via argoCD, so fetching registryIP via shell and then invoking the helm command is also not an option.

I tried below code, it isn't working because the env variables will not be available in the context where image path is present.

apiVersion: apps/v1
kind: Deployment
metadata:
  name: {{ template "helm-guestbook.fullname" . }}
spec:
  template:
    metadata:
      labels:
        app: {{ template "helm-guestbook.name" . }}
        release: {{ .Release.Name }}
    spec:
      containers:
        - name: {{ .Chart.Name }}
          {{- if eq .Values.isOnPrem "true" }}
          image: {{ printf "%s/%s:%s" $dockerRegistryIP .Values.image.repository .Values.image.tag }}
          {{- else }}
          env:
          - name: DOCKER_REGISTRY_IP
            valueFrom:
              configMapKeyRef:
                name: docker-registry-config
                key: DOCKER_REGISTRY_IP

Any pointers on how can I solve this using helm itself ? Thanks

Upvotes: 1

Views: 3041

Answers (1)

coderanger
coderanger

Reputation: 54249

Check out the lookup function, https://helm.sh/docs/chart_template_guide/functions_and_pipelines/#using-the-lookup-function

Though this could get very complicated very quickly, so be careful to not overuse it.

Upvotes: 1

Related Questions