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: allow merge on extra env vars #78

Closed
wants to merge 1 commit into from

Conversation

omidasadpour
Copy link
Contributor

@omidasadpour omidasadpour commented Jan 4, 2024

In fact, only list does not support merge. We agree that all list is rewritten as map, (list in k8s generally has a key called name, and this name can be used as the key of the map)

value.yaml before

# value.yaml 

env:
  - name: NODE_ENV
    value: production
  - name: PORT
    value: "3333"
  - name: SOME_SECRET
    valueFrom:
      secretKeyRef:
        key: SOME_SECRET
        name: some-secret

value.yaml after

# value.yaml

env:
  NODE_ENV:
    - name: NODE_ENV
      value: production
  PORT:
    - name: PORT
      value: "3333"
  SOME_SECRET:
    - name: SOME_SECRET
      valueFrom:
        secretKeyRef:
          key: SOME_SECRET
          name: some-secret

deployment.yaml

{{- with .Values.env }}
    env:
    {{- range $key, $value := . }}
    {{- toYaml $value | nindent 8 }}
    {{- end }}
{{- end }}

This will support the merge of list.

@omidasadpour omidasadpour self-assigned this Jan 4, 2024
@endersonmaia
Copy link
Collaborator

I don't like the duplication of NODE_ENV in the following sample:

env:
  NODE_ENV:
    - name: NODE_ENV
      value: production

Also, if we wanna go that path, we'd need to update documentation, and since it's possible to merge env: also we could get rid of extraEnvVars.

But I'm still not convinced. 🤔

@omidasadpour
Copy link
Contributor Author

I don't like the duplication of NODE_ENV in the following sample:

Me either. but the good news is it works in this way.

@omidasadpour
Copy link
Contributor Author

omidasadpour commented Jan 5, 2024

I don't like the duplication of NODE_ENV in the following sample:

env:
  NODE_ENV:
    - name: NODE_ENV
      value: production

Also, if we wanna go that path, we'd need to update documentation, and since it's possible to merge env: also we could get rid of extraEnvVars.

But I'm still not convinced. 🤔

@endersonmaia
Helm treats lists as replacing the previous list, not merging them. In Kubernetes Helm charts, lists often represent an array of items, and Helm's default behavior is to replace the entire list with the new one from the values file.

One potential approach is to structure them as a map with unique keys for each item, and then merge these maps. (Like what I did in PR)

@endersonmaia
Copy link
Collaborator

This should be solved with #79

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

Successfully merging this pull request may close these issues.

2 participants