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
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion charts/minecraft/Chart.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
apiVersion: v1
name: minecraft
version: 4.20.0
version: 4.21.0
appVersion: SeeValues
home: https://minecraft.net/
description: Minecraft server
Expand Down
2 changes: 1 addition & 1 deletion charts/minecraft/templates/extraports-ing.yaml
Original file line number Diff line number Diff line change
@@ -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!

{{- $servicePort := .service.port }}
{{- $serviceName := printf "%s-%s" $minecraftFullname .name }}
---
Expand Down
Loading