1

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

  • The only way to get configuration into the Helm templates is via `.Values`; but you can pass those via `helm install --set`, or `helm install -f` with an additional YAML file. Helm (intentionally) does not read environment variables. – David Maze Dec 30 '20 at 12:47

1 Answers1

1

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.

coderanger
  • 52,400
  • 4
  • 52
  • 75
  • but lookup is at runtime right, where as these values are required at the compile time itself i.e. during helm rendering, fetching registryIP isn't a problem as that's already stored in the configMap – rajiv chodisetti Dec 30 '20 at 09:38
  • Runtime of Helm, i.e. when you run `helm install`. The manifest is baked to plain YAML at that point and then applied. Helm does not have a runtime component. – coderanger Dec 30 '20 at 12:26
  • got it, thanks for letting me know, but lookup also doesn't solve the issue here, looks like something else is needed, trying to figure out what it is ... the problem is I will be using argo CD app-of-apps concept where the parent workflow triggers the install of child workflows and each workflow is backed by an helm chart and there is no variable sharing mechanism between parent and child chart application, so even if I pass registry IP via parent , it doesn't gets percolated to child helm chart, the only way to share the config here is via config Maps – rajiv chodisetti Dec 30 '20 at 16:22