Skip to content

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

Merged
merged 3 commits into from
Aug 18, 2024
Merged

Allow optional definition of ingress #222

merged 3 commits into from
Aug 18, 2024

Conversation

drewburr
Copy link
Contributor

Removes the requirement of setting ingress.enabled: false for extraPorts. For example, an item in extraPorts[] needing no ingress currently requires:

extraPorts:
  - name: map
    protocol: TCP
    ingress:
      enabled: false
    ...

If ingress is omitted, the following error is thrown:

Error: template: minecraft-toiletbowl/charts/minecraft/templates/extraports-ing.yaml:3:26: executing "minecraft-toiletbowl/charts/minecraft/templates/extraports-ing.yaml" at <.ingress.enabled>: nil pointer evaluating interface {}.enabled

With this update, we can safely omit the ingress object entirely:

extraPorts:
  - name: map
    protocol: TCP
    ...

Removes the requirement of setting `ingress.enabled: false` for extraPorts
drewburr added a commit to drewburr-labs/drewburr-documentation that referenced this pull request Aug 18, 2024
Copy link
Owner

@itzg itzg left a 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 }}
Copy link
Owner

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?

Copy link
Contributor Author

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!

@drewburr
Copy link
Contributor Author

Thanks! Can you also bump the chart's minor version? (PR/merge process currently requires it 😞)

Good catch! Thanks for the heads up, I'll keep this in mind in the future

@itzg itzg merged commit bb9dcf4 into itzg:master Aug 18, 2024
1 check passed
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