-
Notifications
You must be signed in to change notification settings - Fork 31
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
felixscheinost
wants to merge
1
commit into
hall:main
Choose a base branch
from
felixscheinost:feature/fix-leading-underscore-configmap
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+40
−7
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,12 +16,24 @@ with lib; let | |
) | ||
cfg.api.defaults); | ||
|
||
moduleToAttrs = value: | ||
if isAttrs value | ||
then mapAttrs (_n: moduleToAttrs) (filterAttrs (n: v: v != null && !(hasPrefix "_" n)) value) | ||
else if isList value | ||
then map moduleToAttrs value | ||
else value; | ||
moduleToAttrs = objType: propertyPath: value: | ||
if isAttrs value then | ||
let | ||
# Fix https://github.com/hall/kubenix/issues/44 | ||
# The check for names starting with leading '_' has been here since forever. | ||
# Not sure where it makes sense, but it definitely doesn't make sense for ConfigMap -> data/binaryData | ||
# => 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" ]); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
filterName = name: allowLeadingUnderscore || !(hasPrefix "_" name); | ||
filteredAttrs = filterAttrs (n: v: v != null && filterName n) value; | ||
in | ||
mapAttrs (_n: moduleToAttrs objType (propertyPath ++ [ _n ])) filteredAttrs | ||
else if isList value then | ||
map (moduleToAttrs objType propertyPath) value | ||
else | ||
value; | ||
|
||
apiOptions = { config, ... }: { | ||
options = { | ||
|
@@ -536,7 +548,7 @@ in | |
|
||
kubernetes.objects = flatten (mapAttrsToList | ||
(_: type: | ||
mapAttrsToList (_name: moduleToAttrs) | ||
mapAttrsToList (_name: moduleToAttrs type [ ]) | ||
(optionalHashedNames' cfg.api.resources.${type.group}.${type.version}.${type.kind} type.kind) | ||
) | ||
cfg.api.types); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,6 +21,7 @@ let | |
./k8s/defaults.nix | ||
./k8s/order.nix | ||
./k8s/submodule.nix | ||
./k8s/configmap.nix | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💯 |
||
# TODO: `importYaml` uses IFD which fails during `nix flake check` as it evaluates | ||
# for all systems, not only the current one: https://github.com/hall/kubenix/issues/12 | ||
# ./k8s/imports.nix | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{ config, kubenix, ... }: | ||
let | ||
configMapData = (builtins.head config.kubernetes.objects).data; | ||
in | ||
{ | ||
imports = [ kubenix.modules.test kubenix.modules.k8s ]; | ||
|
||
test = { | ||
name = "k8s-simple"; | ||
description = "Test that ConfigMap data keys can have a leading underscore (https://github.com/hall/kubenix/issues/44)"; | ||
assertions = [ | ||
{ | ||
message = "leading underscore in ConfigMap key should be preserved"; | ||
assertion = configMapData == { _FOO = "_bar"; }; | ||
} | ||
]; | ||
}; | ||
|
||
kubernetes.resources.configMaps.foo.data._FOO = "_bar"; | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
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 🙂