Fix raw HTML directory listing output when using --query flag#2
Draft
Copilot wants to merge 2 commits into
Draft
Fix raw HTML directory listing output when using --query flag#2Copilot wants to merge 2 commits into
Copilot wants to merge 2 commits into
Conversation
Two bugs caused kubectl node-logs to print raw HTML when a kubelet directory listing was returned: 1. When --query is specified, raw=true was set, bypassing HTML parsing entirely via optionallyDecompress/io.Copy. Fix: peek at the first bytes in raw mode; if the response starts with <pre>, route to outputDirectoryEntriesOrContent instead. 2. The regex href="([^"]+)" only matched old-style <a href="…">…</a> tags. Kubernetes 1.28+ kubelet returns <a>name/</a> (no href). Fix: change regex to <a[^>]*>([^<]+)</a> to extract tag text content, covering both old and new formats. Also extracted writeToReader() from writeTo() for unit testability and added 5 unit tests covering all affected code paths. Co-authored-by: aravindhp <11638995+aravindhp@users.noreply.github.com> Agent-Logs-Url: https://github.com/aravindhp/kubectl-node-logs/sessions/9c505dec-5e0b-4850-96ef-b3e834206aa3
Copilot
AI
changed the title
[WIP] Fix weird output of the plugin
Fix raw HTML directory listing output when using --query flag
Mar 24, 2026
Owner
|
@jrvaldes please review and test this against an OpenShift cluster when you have the chance. |
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
--queryis used, the kubelet can return an HTML directory listing instead of log content. Two bugs caused this to render as raw HTML rather than a clean file list.Bugs fixed
Raw mode bypassed HTML parsing:
--querysetsraw=true, routing responses throughoptionallyDecompress→io.Copy, which blindly copies any HTML directory listing to stdout. Fixed by peeking at the response in the raw path — if it starts with<pre>, route tooutputDirectoryEntriesOrContentinstead.Regex didn't match new kubelet format: The original regex
href="([^"]+)"only matched the old<a href="name/">name/</a>link style. Kubernetes 1.28+ kubelet returns<a>name/</a>(nohref), so no entries were ever extracted. Changed to<a[^>]*>([^<]+)</a>to capture tag text content regardless of attributes.Before (
--query=messageson a node where the kubelet returns a directory listing):After:
Refactor
Extracted
writeToReader(out io.Writer, in io.Reader)fromwriteToto make the core dispatch logic unit-testable without a live API server. Added tests covering old-href HTML, no-href HTML, prefix handling, plain-text passthrough, and raw-mode HTML detection.Original prompt
⚡ Quickly spin up Copilot coding agent tasks from anywhere on your macOS or Windows machine with Raycast.