Skip to content

fix(volumepath): respect directory boundaries in TopLevelPathList - #2381

Open
amalsaidov wants to merge 1 commit into
kube-logging:masterfrom
amalsaidov:fix/volumepath-sibling-prefix
Open

amalsaidov wants to merge 1 commit into
kube-logging:masterfrom
amalsaidov:fix/volumepath-sibling-prefix

Conversation

@amalsaidov

Copy link
Copy Markdown

Describe your changes

volumepath.List.TopLevelPathList decides whether one path is nested under
another with strings.HasPrefix. That matches on raw string prefixes rather
than on path components, so two sibling directories that merely share a textual
prefix get collapsed onto the shorter one.

For example, given /var/log and /var/logs:

HasPrefix("/var/logs", "/var/log") == true

so /var/logs is reported as living under /var/log and the two are merged.

TopLevelPathList feeds the tailer volume-mount generation used by the pod
mutation webhook (pkg/webhook/podhandler) and the host tailer
(pkg/resources/hosttailer). With the bug, a file under /var/logs would end
up mounted from /var/log, so that path is never mounted and its logs are not
tailed.

The fix adds a small isPathPrefix helper that only treats prefix as a
parent when the match ends at a path separator (or at the end of the path), and
leaves the existing nesting behaviour (/var/log under /var, etc.) unchanged.

How to test

go test ./pkg/resources/volumepath/...

A new siblingPathsSharingPrefix case in TestTopLevelPathList fails before the
change (/var/logs collapsed to /var/log) and passes after it. The existing
TopLevelPathList cases and the pkg/webhook/podhandler tests still pass.

Notes

AI-assisted; directed, reviewed and tested by the author.

TopLevelPathList used strings.HasPrefix to decide whether a path is
nested under another, which matches on raw string prefixes rather than
on path components. Sibling directories that merely share a textual
prefix, such as /var/log and /var/logs, were therefore collapsed onto
the shorter one: /var/logs was reported as living under /var/log.

This feeds the tailer volume-mount generation in the pod webhook and the
host tailer, so a file under /var/logs would end up mounted from
/var/log and never tailed.

Add an isPathPrefix helper that only treats prefix as a parent when the
match ends at a path separator (or at the end of the path), and cover
the sibling case with a test.

AI-assisted; directed, reviewed and tested by the author.

Signed-off-by: Amal Saidov <amalsaidov@users.noreply.github.com>
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.

1 participant