jfrog / charts

JFrog official Helm Charts
https://jfrog.com/integration/helm-repository/
Apache License 2.0
254 stars 439 forks source link

Distribution chart is unable to use Pod fields as values for environment variables with extraEnvironmentVariables #1814

Open mikeycmccarthy opened 12 months ago

mikeycmccarthy commented 12 months ago

Is this a request for help?:

YES


Is this a BUG REPORT or FEATURE REQUEST? (choose one):

FEATURE REQUEST

Version of Helm and Kubernetes:

Kubernetes: 1.21.2 Helm: 3.10.3

Which chart:

Distribution

Which product license (Enterprise/Pro/oss):

Entreprise+

JFrog support reference (if already raised with support team):

N/A

What happened:

I tried to set an environment variable using the extraEnvironmentVariables property of the Distribution chart. This was not a simple value but a 'valueFrom' with a fieldRef. Specifically this was to support Dynatrace version detection strategies (https://www.dynatrace.com/support/help/platform-modules/cloud-automation/release-monitoring/version-detection-strategies) but really this is for any environment variable that is not a simple value based one.

What you expected to happen:

I expected the environment variable to be set in the resulting manifest for the stateful set, but it wasn't, and instead Helm through an error.

The explanation is quite simple - the way the Distribution chart works is that the extraEnvironmentVariables property always expects a key and a value, and when it gets templated out it is very specific about this, see https://github.com/jfrog/charts/blob/master/stable/distribution/templates/distribution-statefulset.yaml#L339-L342.

        {{- range .Values.distribution.extraEnvironmentVariables }}
        - name: {{ .name }}
          value: '{{ tpl .value $ }}'
        {{- end }}

This is different to the way this works within the Artifactory chart:

https://github.com/jfrog/charts/blob/master/stable/artifactory/templates/artifactory-statefulset.yaml#L442C1-L444C11

{{- with .Values.artifactory.extraEnvironmentVariables }}
{{ tpl (toYaml .) $ | indent 8 }}
{{- end }}

The Artifactory chart supports all types of environment variables, so you can set them in your values file exactly as they would turn up in the manifest.

How to reproduce it (as minimally and precisely as possible):

Set the extraEnvironmentVariables within the Distribution Helm chart to use a pod field (https://kubernetes.io/docs/tasks/inject-data-application/environment-variable-expose-pod-information/#use-pod-fields-as-values-for-environment-variables)

Anything else we need to know: