Skip to content
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

Spawn protection setting bugged #227

Open
alexyao2015 opened this issue Aug 26, 2024 · 8 comments
Open

Spawn protection setting bugged #227

alexyao2015 opened this issue Aug 26, 2024 · 8 comments

Comments

@alexyao2015
Copy link

alexyao2015 commented Aug 26, 2024

The spawn protection config setting cannot be set to "0" as mentioned in the docs as it is currently bugged. Setting it to 0 will cause the envmap to evaluate to false and instead exclude the SPAWN_PROTECTION environment variable rather than including it as intended.

{{- define "minecraft.envMap" }}

{{- template "minecraft.envMap" list "SPAWN_PROTECTION" .Values.minecraftServer.spawnProtection }}

@itzg
Copy link
Owner

itzg commented Aug 26, 2024

Probably need to introduce an envIntMap similar to the envBoolMap template function.

@github-staff github-staff deleted a comment from Lxx-c Oct 23, 2024
@github-staff github-staff deleted a comment from Lxx-c Oct 23, 2024
@thomascizeron
Copy link
Contributor

Hi,
I think it would be easier to modify the if statement in the minecraft.envMap template function to check if the value exists or the value is 0, allowing a value of 0 to render the template.
This way, you can use the envMap template function to render integer values as well.
Something like this:
{{- if or (index . 1) (and (int (index . 1 | toString)) (eq (int (index . 1 | toString)) 0)) }}
Maybe there is a better way to do this, but i think it's simpler than creating a new template function for integer values.
Happy to make a PR if you think this is a good idea.

@itzg
Copy link
Owner

itzg commented Nov 19, 2024

I'm worried that still wouldn't work. A zero is just as "false-y" as the absence of a value, so I'm not sure how your snippet can differentiate and might coerce all absent values into zero integers.

@thomascizeron
Copy link
Contributor

Right, after some tests the snippet don't work because of string casting. But this one works:
{{- if or (index . 1) (kindIs "float64" (index . 1)) }}
Either the value is true-y or it's a number (float64) (including 0).

Tested with:

Type index . 1 Render
No value false
Null value null false
Empty string "" false
Empty array [] false
Empty map {} false
Zero integer 0 true
Non-zero integer 1 true
String "string" true
Array [1, 2] true
Map {key: value} true

@itzg
Copy link
Owner

itzg commented Nov 21, 2024

Ah yes, the kindIs approach looks very promising. I wonder if that would have worked for checking existence of boolean values vs absence being false-y?

@thomascizeron
Copy link
Contributor

yeah it could work to also resorb envBoolMap with an additional clause on the or

@itzg
Copy link
Owner

itzg commented Nov 21, 2024

A PR would be great if you wanted to switch it to that.

@thomascizeron
Copy link
Contributor

#241

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

No branches or pull requests

4 participants
@itzg @alexyao2015 @thomascizeron and others