-
-
Notifications
You must be signed in to change notification settings - Fork 64
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
Fix bad yaml when only secretKeyRef #267
base: master
Are you sure you want to change the base?
Conversation
@@ -64,8 +64,9 @@ env: | |||
{{/* | |||
https://kubernetes.io/docs/tasks/inject-data-application/environment-variable-expose-pod-information/#use-pod-fields-as-values-for-environment-variables | |||
*/}} | |||
{{- with $root.Values.envFromFieldRefFieldPath }} | |||
{{- if or (not (empty $root.Values.envFromFieldRefFieldPath)) (not (empty $root.Values.envFromSecretKeyRef)) }} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You need to consider
charts/incubator/monochart/templates/_helpers.tpl
Lines 57 to 63 in 37a41f5
{{- with $root.Values.env }} | |
env: | |
{{- range $name, $value := . }} | |
- name: {{ $name }} | |
value: {{ default "" $value | quote }} | |
{{- end }} | |
{{- end }} |
And you can use a more concise syntax like
{{- if $root.Values.configMaps | or $root.Values.secrets | or $root.Values.envFrom }} |
empty
is redundant, conditionals calculate emptiness for you
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I really didn't like my if
statement there, but missed the better syntax. Updated that.
Is the forced quoting of values for safety? I didn't see it done in the fieldRef feature just above the secretKeyRef feature, so I did not do it. This is all part of the following Kubernetes features:
https://kubernetes.io/docs/concepts/configuration/secret/#using-secrets-as-environment-variables
This should all be Kubernetes field paths and secret names and safe for YAML without unnecessary quoting. I'm always a bit fuzzy on this, the rules around quoting in YAML seem inconsistent to me everytime I read them.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added in the string safety after testing it. Seems Kubernetes doesn't mind the explicit strings there, in my limited testing.
Found a bug with my previous feature.
If you specified only a secretKeyRef, and not an accompanying fieldRef, the
env:
tag would be missing in the yaml section, causing invalid yaml as such:This fixes this bug, so that if either fieldKeyRef or secretKeyRefs are referenced, the env: section will have the appropriate yaml