Repository navigation
Conversation
Kubernetes mounts a ConfigMap or Secret key with a nested path, such as
"log/level", through a symlink to its first directory ("log ->
..data/log"). fs.WalkDir does not follow symlinks, so the provider never
read the files behind it and the keys were silently missing, although
the docs say they are split into {"log":{"level":...}}.
Walk the directory behind a top-level symlink. The test helper now
creates the same links as the kubelet for nested keys.
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
When a ConfigMap or Secret key is projected at a nested path (
items: - key: level, path: log/level, or a projected volume withpath: certs/ca.crt), the kubelet does not link the file itself at the top of the mount. It links the first directory instead (createUserVisibleFilesin atomic_writer.go):fs.WalkDirdoesn't follow symlinks, sologwas seen as a directory and never walked, andlog.levelwas missing from the result with no error. The provider docs say such a key "will always produce {"log":{"level":"INFO"}}", and that holds for a plain directory but not for a real volume mount.The fix: when
walkDirresolves a top-level symlink to a directory (other than..dataand the timestamped dirs),Readwalks it.fs.WalkDirdoes follow a symlink when it's given as the root. The walk follows only top-level links, because those are the only ones the kubelet creates. A link to a directory further down, such as one pointing back at the mount, is still not followed, so there's no loop.writeVolumeMountAtin the test helper now makes the same links as the kubelet for nested keys (link the first path segment). Before, it couldn't create a nested key at all, becauseos.Symlink("..data/log/level", "log/level")fails without alogdir. There's also a newnested pathcase inTest_K8SMount_Read_WithVolumeMount.Tests (from
providers/k8smount,GOWORK=offbecause the module isn't ingo.work):go test -run Test_K8SMount_Read_WithVolumeMount .without the provider change:nested_pathfails (actual: map[a_foo:foo-value]); with it: passes.go test .,go test -race .,go vet .,gofmt -l .: clean.Not run: Go 1.23/1.24 from the CI matrix, which doesn't cover this module anyway (it needs Go 1.25 and isn't in
go.work). Not tried against a real cluster.