fix(nodes): omit tailLines for file log queries - #1279
Open
ychampion wants to merge 1 commit into
Open
Conversation
Kubelet resolves file paths under /var/log and rejects log options for file queries. Keep tailing for services while allowing file queries to succeed, and publish corrected tool examples. Fixes: containers#1262 Constraint: Kubelet only accepts tailLines for service-style queries. Rejected: Forward tailLines for every query | kubelet returns 406 for files Confidence: high Scope-risk: narrow Directive: Keep file-query detection aligned with kubelet path semantics. Tested: go test -p 1 -count=1 ./...; make lint; make build Not-tested: Full race suite could not link all packages within local disk. Signed-off-by: ychampion <ychampion@users.noreply.github.com>
Collaborator
|
@2uasimojo mind reviewing this one? |
2uasimojo
reviewed
Jul 30, 2026
2uasimojo
left a comment
Contributor
There was a problem hiding this comment.
This looks right to me based on the issue. Couple questions inline.
| // Query parameters for tail | ||
| if tailLines > 0 { | ||
| // The kubelet only supports tailLines for service log queries. | ||
| if tailLines > 0 && !strings.ContainsAny(query, `/\`) { |
Contributor
There was a problem hiding this comment.
Do you think we should at least warn when ignoring an input parameter? (I'm actually curious why we don't just error.)
Comment on lines
+54
to
+58
| if req.URL.Query().Get("tailLines") != "2" { | ||
| w.WriteHeader(http.StatusNotAcceptable) | ||
| return | ||
| } | ||
| logContent = "Line 4\nLine 5\n" |
Contributor
There was a problem hiding this comment.
I'm not fully understanding how this test is structured, but this seems tightly coupled to the test case by requiring an exact tailLines value. Would it be too painful to do something like (pseudo):
logLines = "Line 1\nLine 2\nLine 3\nLine 4\nLine 5\n".Split("\n")
switch tailLines, err := atoi(req.URL.Query().Get("tailLines")) {
case (err != nil, tailLines <= 0): // Is zero acceptable?
w.WriteHeader(http.StatusNotAcceptable) // invalid numeric input
return
case tailLines > len(logLines):
tailLines = len(logLines)
fallthrough
default:
logContent = logLines[len(logLines)-tailLines:].Join("\n") // Possible off-by-one; I didn't try too hard :)
}
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.
Summary
tailLinesfor file-based node log queries/var/logand cover service/file behaviorWhy
The kubelet rejects options on file queries, so
nodes_logreturned 406 whenever a file path was used withtailLines. The existing examples also double-prefixed/var/log.Fixes #1262.
Validation
go test -p 1 ./pkg/mcp -run 'TestNodes/TestNodesLog' -count=1go test -p 1 -count=1 ./...make lintmake build