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

fix ConfigMap data with leading underscore (#44) #45

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

felixscheinost
Copy link
Contributor

I tried doing the least amount of changes to fix keys with leading underscore in ConfigMap data.

@adrian-gierakowski
Copy link
Contributor

I believe attrs starting with _ are filtered due to some specific “special” attrs which are use throughout the module system. See: https://github.com/search?q=repo%3Ahall%2Fkubenix+._&type=code

It might be better to compile a list of these and only exclude this specific list (everywhere).

Copy link
Owner

@hall hall left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with @adrian-gierakowski that it's probably cleaner to not remove everything beginning with an underscore but instead to remove specifically those keys (from all objects, not just 1 or 2 fields of 1 object) which are not provided by the user.

However, like you, I'm also skeptical why this needs to be done. My guess would be the same as Adrian's but the tests don't fail on main when removing && !(hasPrefix "_" n) and that the test you've added here (which, at a glance, should catch any keys leaked from the module system) doesn't fail without any other change to the k8s module. So it would seem that removing the leading underscore isn't necessary (it very well could've been added while under heavy development then things changed and it was no longer necessary but not removed 🤷). I haven't tested that guess on an actual cluster though.

# => To get a minimal invasive fix we added `objType` and `propertyPath` to make `moduleToAttrs` "context-aware".
# This way we can allow names with leading underscore exactly for ConfigMap -> data/binaryData
allowLeadingUnderscore = objType.group == "core" && objType.version == "v1" && objType.kind == "ConfigMap" &&
(propertyPath == [ "data" ] || propertyPath == [ "binaryData" ]);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The underscore isn't a valid base64 character so we shouldn't need to check binaryData, yeah?

@@ -21,6 +21,7 @@ let
./k8s/defaults.nix
./k8s/order.nix
./k8s/submodule.nix
./k8s/configmap.nix
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💯

moduleToAttrs = objType: propertyPath: value:
if isAttrs value then
let
# Fix https://github.com/hall/kubenix/issues/44
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: I'd argue most of this should comment probably go in the commit message details but I'd rather too many comments than too few so don't let that stop you 🙂

@felixscheinost felixscheinost force-pushed the feature/fix-leading-underscore-configmap branch from 20c66c2 to 242a48d Compare June 26, 2024 05:41
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.

3 participants