Skip to content

Fix raw HTML directory listing output when using --query flag#2

Draft
Copilot wants to merge 2 commits into
mainfrom
copilot/fix-weird-plugin-output
Draft

Fix raw HTML directory listing output when using --query flag#2
Copilot wants to merge 2 commits into
mainfrom
copilot/fix-weird-plugin-output

Conversation

Copy link
Copy Markdown

Copilot AI commented Mar 24, 2026

When --query is 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: --query sets raw=true, routing responses through optionallyDecompressio.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 to outputDirectoryEntriesOrContent instead.

  • 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> (no href), so no entries were ever extracted. Changed to <a[^>]*>([^<]+)</a> to capture tag text content regardless of attributes.

Before (--query=messages on a node where the kubelet returns a directory listing):

<pre>
<a>amazon/</a>
<a>audit/</a>
<a>messages</a>
</pre>

After:

amazon/
audit/
messages

Refactor

Extracted writeToReader(out io.Writer, in io.Reader) from writeTo to 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

This section details on the original issue you should resolve

<issue_title>Weird output of the plugin?</issue_title>
<issue_description>Hello,

This is what I get:

k node-logs ip-10-120-149-23.ec2.internal --query=messages
<pre>
<a href="amazon/">amazon/</a>
<a href="audit/">audit/</a>
<a href="aws-routed-eni/">aws-routed-eni/</a>
<a href="boot.log">boot.log</a>
<a href="btmp">btmp</a>
<a href="btmp-20240401.gz">btmp-20240401.gz</a>
<a href="chrony/">chrony/</a>
<a href="cloud-init-output.log">cloud-init-output.log</a>
<a href="cloud-init.log">cloud-init.log</a>
<a href="containers/">containers/</a>
<a href="cron">cron</a>
<a href="dmesg">dmesg</a>
<a href="dmesg.old">dmesg.old</a>
<a href="grubby">grubby</a>
<a href="grubby_prune_debug">grubby_prune_debug</a>
<a href="journal/">journal/</a>
<a href="lastlog">lastlog</a>
<a href="maillog">maillog</a>
<a href="messages">messages</a>
<a href="pods/">pods/</a>
<a href="secure">secure</a>
<a href="spooler">spooler</a>
<a href="tallylog">tallylog</a>
<a href="wtmp">wtmp</a>
<a href="yum.log">yum.log</a>
</pre>
  • aws eks 1.28
  • kubectl 1.28
  • latest node-logs plugin</issue_description>

Comments on the Issue (you are @copilot in this section)

@aravindhp Thanks for opening the issue. It is a bug with listing the directories. I will take a look when I have some cycles.

BTW, viewing a file like yum.log should work.</comment_new>


⚡ Quickly spin up Copilot coding agent tasks from anywhere on your macOS or Windows machine with Raycast.

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
Copilot AI requested a review from aravindhp March 24, 2026 18:39
@aravindhp
Copy link
Copy Markdown
Owner

aravindhp commented Mar 24, 2026

@jrvaldes please review and test this against an OpenShift cluster when you have the chance.

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.

Weird output of the plugin?

2 participants