Fix bad yaml when only secretKeyRef#267
Conversation
| 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.
You need to consider
charts/incubator/monochart/templates/_helpers.tpl
Lines 57 to 63 in 37a41f5
And you can use a more concise syntax like
emptyis redundant, conditionals calculate emptiness for you
There was a problem hiding this comment.
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.
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