-
Notifications
You must be signed in to change notification settings - Fork 158
Allow optional definition of ingress #222
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
Conversation
Removes the requirement of setting `ingress.enabled: false` for extraPorts
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.
Thanks! Can you also bump the chart's minor version? (PR/merge process currently requires it 😞)
@@ -1,6 +1,6 @@ | |||
{{- $minecraftFullname := include "minecraft.fullname" . }} | |||
{{- range .Values.minecraftServer.extraPorts }} | |||
{{- if default "" .ingress.enabled }} | |||
{{- if default "" (.ingress).enabled }} |
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.
Very interesting. So this allows for nil-safe access to objects? So you happen to know where in the helm docs they describe that?
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 actually found this while poking through Google, with this StackOverflow post leading me to the right answer.
In Helm we can wrap a value that we might consider optional in brackets.
type: {{ (.Values.fpm.service).type | default "NodePort" }}
Now when we try to run a helm template / install, it will consider .Values.fpm.service to be optional. We would still run into a Nil pointer if .Values.fpm is not set. So you must ensure to encapsulate up until where should be considered optional, as you can see in the example I provided, I did not place brackets around .type otherwise, it would try to find service which may not exist.
Digging into this further, another StackOverflow post notes that this behavior comes from Go's text/template
library. It seems that something like {{ if default "" .ingress.enabled }}
is called a "pipeline" and adding the parenthesis makes a pipeline within the pipeline, like nested operators if default "" (.ingress).enabled
. The nested pipeline returns a nil value under a suite of negative circumstances, which is then used instead of a nil pointer when accessing .enabled
(docs).
If the value of the pipeline is empty, no output is generated
...
The empty values are false, 0, any nil pointer or interface value, and any array, slice, map, or string of length zero.
Very interesting!
Good catch! Thanks for the heads up, I'll keep this in mind in the future |
Removes the requirement of setting
ingress.enabled: false
for extraPorts. For example, an item inextraPorts[]
needing no ingress currently requires:If
ingress
is omitted, the following error is thrown:With this update, we can safely omit the
ingress
object entirely: