Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: envVars as array or as dict #24

Merged
merged 4 commits into from
Oct 11, 2023
Merged

Conversation

zevisert
Copy link
Contributor

@zevisert zevisert commented Sep 28, 2023

I know #20 is open still, but it needed changes to support valuesFrom. I want to use that feature now, so I put together a new MR for that.

Also in this version, the template I made can handle envVars in either array or dictionary format, so no user-migrations are needed.. You may choose to deprecate the array format at a later date.

I tested by replacing the values.yaml file in the examples directory with these two files:

values.yaml to test map envVars with
# file: charts/helmet/examples/simple/values.yaml
nameOverride: testingenvvars

image:
  repository: hello-world

envVars:
  BASIC: value

  BASIC_VALUE:
    value: basic value

  BASIC_NAME_IGNORED:
    name: should not see this
    value: basic value name ignored

  BASIC_TEMPLATE:
    value: "{{ .Values.nameOverride }}"

  CONFIGMAP:
    valueFrom:
      configMapRef:
        name: my-config-map
        key: my-key

  CONFIGMAP_WITH_OPTIONAL:
    valueFrom:
      configMapRef:
        name: my-config-map
        key: my-key
        optional: true

  CONFIGMAP_TEMPLATE:
    valueFrom:
      configMapRef:
        name: "{{ .Values.nameOverride | lower }}"
        key: "{{ .Values.nameOverride | upper }}"
        optional: '{{ hasPrefix "test" .Values.nameOverride }}'

  SECRET:
    valueFrom:
      secretKeyRef:
        name: my-secret
        key: my-key

  SECRET_WITH_OPTIONAL:
    valueFrom:
      secretKeyRef:
        name: my-secret
        key: my-key
        optional: true

  SECRET_TEMPLATE:
    valueFrom:
      secretKeyRef:
        name: "{{ .Values.nameOverride | lower }}"
        key: "{{ .Values.nameOverride | upper }}"
        optional: '{{ hasPrefix "test" .Values.nameOverride }}'

  FIELDREF:
    valueFrom:
      fieldRef:
        fieldPath: metadata.namespace

  FIELDREF_WITH_OPTIONAL:
    valueFrom:
      fieldRef:
        fieldPath: metadata.namespace
        optional: true

  FIELDREF_TEMPLATE:
    valueFrom:
      fieldRef:
        fieldPath: '{{ default "metadata.namespace" .Values.missing }}'
        optional: '{{ hasPrefix "test" .Values.nameOverride }}'

  RESOURCE:
    valueFrom:
      resourceFieldRef:
        containerName: my-container
        resource: limits.cpu

  RESOURCE_WITH_OPTIONAL:
    valueFrom:
      resourceFieldRef:
        containerName: my-container
        resource: limits.cpu
        optional: true

  RESOURCE_TEMPLATE:
    valueFrom:
      resourceFieldRef:
        containerName: "{{ .Values.nameOverride }}-{{ randAlphaNum 5 }}"
        resource: '{{ lower "LIMITS.MEMORY" }}'
        optional: '{{ hasPrefix "test" .Values.nameOverride }}'
values.yaml to test list envVars with
# file: charts/helmet/examples/simple/values.yaml
nameOverride: testingenvvars

image:
  repository: hello-world

envVars:
  - name: BASIC
    value: value

  - name: BASIC_TEMPLATE
    value: "{{ .Values.nameOverride }}"

  - name: CONFIGMAP
    valueFrom:
      configMapRef:
        name: my-config-map
        key: my-key

  - name: CONFIGMAP_WITH_OPTIONAL
    valueFrom:
      configMapRef:
        name: my-config-map
        key: my-key
        optional: true

  - name: CONFIGMAP_TEMPLATE
    valueFrom:
      configMapRef:
        name: "{{ .Values.nameOverride | lower }}"
        key: "{{ .Values.nameOverride | upper }}"
        optional: '{{ hasPrefix "test" .Values.nameOverride }}'

  - name: SECRET
    valueFrom:
      secretKeyRef:
        name: my-secret
        key: my-key

  - name: SECRET_WITH_OPTIONAL
    valueFrom:
      secretKeyRef:
        name: my-secret
        key: my-key
        optional: true

  - name: SECRET_TEMPLATE
    valueFrom:
      secretKeyRef:
        name: "{{ .Values.nameOverride | lower }}"
        key: "{{ .Values.nameOverride | upper }}"
        optional: '{{ hasPrefix "test" .Values.nameOverride }}'

  - name: FIELDREF
    valueFrom:
      fieldRef:
        fieldPath: metadata.namespace

  - name: FIELDREF_WITH_OPTIONAL
    valueFrom:
      fieldRef:
        fieldPath: metadata.namespace
        optional: true

  - name: FIELDREF_TEMPLATE
    valueFrom:
      fieldRef:
        fieldPath: '{{ default "metadata.namespace" .Values.missing }}'
        optional: '{{ hasPrefix "test" .Values.nameOverride }}'

  - name: RESOURCE
    valueFrom:
      resourceFieldRef:
        containerName: my-container
        resource: limits.cpu

  - name: RESOURCE_WITH_OPTIONAL
    valueFrom:
      resourceFieldRef:
        containerName: my-container
        resource: limits.cpu
        optional: true

  - name: RESOURCE_TEMPLATE
    valueFrom:
      resourceFieldRef:
        containerName: "{{ .Values.nameOverride }}-{{ randAlphaNum 5 }}"
        resource: '{{ lower "LIMITS.MEMORY" }}'
        optional: '{{ hasPrefix "test" .Values.nameOverride }}'

I bumped the chart version from 0.9.1 to 0.10.0 here for the new envVars-as-map feature, but no breaking changes are expected since arrays of envVars are still tested to be working as before.

@zevisert
Copy link
Contributor Author

zevisert commented Oct 6, 2023

@atkrad Can you take a look at this? It would be a really helpful addition to helmet for me and others

charts/helmet/templates/_helpers.tpl Outdated Show resolved Hide resolved
charts/helmet/templates/_helpers.tpl Outdated Show resolved Hide resolved
@atkrad atkrad self-requested a review October 9, 2023 13:26
@atkrad atkrad added the enhancement New feature or request label Oct 9, 2023
charts/helmet/values.yaml Outdated Show resolved Hide resolved
@atkrad atkrad merged commit 78803f2 into companyinfo:main Oct 11, 2023
2 checks passed
@zevisert
Copy link
Contributor Author

@atkrad Thank you for the review and release! This should help clean up a few of my charts quite a bit!

@atkrad
Copy link
Member

atkrad commented Oct 11, 2023

@zevisert You're welcome, Thanks for your contribution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants