简体   繁体   中英

How can I check if a k8s secret exists in a Helm chart/k8s template, or use a default value?

I have a template part like:

    spec:
      containers:
        - name: webinspect-runner-{{ .Values.pipeline.sequence }}
          ...
          env:
            - name: wi_base_url
              valueFrom:
                secretKeyRef:
                  name: webinspect
                  key: wi-base-url
            - name: wi_type
              valueFrom:
                secretKeyRef:
                  name: webinspect
                  key: wi-type

The webinspect/wi_type secret may be missing. I want the container also don't have the wi_type envvar or get a default value (better) when the secret is missing, but k8s just reports CreateContainerConfigError: couldn't find key wi-type in Secret namespace/webinspect and the pod fails.

Is there a way to use a default value, or skip the block if the secret does not exist?

Two options, the first is add optional: true to the secretKeyRef block(s) which makes it skip. The second is a much more complex approach using the lookup template function in Helm . Probably go with the first:)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM