Repository navigation
Fix corrupted Windows k0s install command (Flags double-unquote, --kubelet-extra-args double-quote) - #1120
Merged
Conversation
…belet-extra-args double-quote) On Windows hosts the rig/v2 SingleQuote quoter wraps every value, exposing two bugs in Flags: AddOrReplace/AddUnlessExist unquote a second time via Add and strip backslashes from paths (C:\var\lib\k0s -> C:varlibk0s), and Each unquotes bare values with the same hazard. K0sInstallFlags also double-quoted --kubelet-extra-args by wrapping extra.Join in a redundant quote(). Append already-unquoted values directly, only unquote genuinely quoted values in Each (new isQuoted helper), and drop the redundant outer quote. Add a table test covering both a POSIX quoter and a Windows SingleQuote quoter. Fixes k0sproject#1114 Signed-off-by: Vikram bir Singh <vsingh@mirantis.com> Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
vikramhh
force-pushed
the
fix/windows-flags-unquote-1114
branch
from
July 23, 2026 15:42
9f71168 to
3430dbb
Compare
There was a problem hiding this comment.
Pull request overview
Fixes Windows-specific corruption in the rendered k0s install worker ... command by preventing repeated/unconditional unquoting from consuming backslashes in paths and by removing redundant quoting of --kubelet-extra-args. This change sits in the config API layer (cluster.Flags and Host.K0sInstallFlags), which is responsible for constructing safe CLI flag strings across platforms.
Changes:
- Prevent
Flags.AddOrReplace/AddUnlessExistfrom unquoting the same token twice (avoids backslash loss on Windows paths). - Make
Flags.Eachonly unquote values that are actually wrapped in matching quotes (avoids corrupting bareC:\...values). - Remove redundant quoting around
extra.Join(...)when setting--kubelet-extra-args, avoiding Windows PowerShell quote-escaping mangling. - Add table-driven tests covering both POSIX and Windows quoting behaviors.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| pkg/apis/k0sctl.k0sproject.io/v1beta1/cluster/host.go | Avoids double-quoting --kubelet-extra-args when composing worker install flags. |
| pkg/apis/k0sctl.k0sproject.io/v1beta1/cluster/flags.go | Prevents double-unquoting and avoids unquoting bare values in Each to preserve Windows backslashes. |
| pkg/apis/k0sctl.k0sproject.io/v1beta1/cluster/flags_quoting_test.go | Adds regression tests for Windows/POSIX quoting and single-unquote invariants. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+14
to
+24
| // isQuoted reports whether s is wrapped in a matching pair of single or double | ||
| // quotes. Only such values are safe to pass to shellescape.Unquote; a bare | ||
| // value must be left untouched so that literal backslashes (Windows paths) are | ||
| // not consumed as escape sequences. | ||
| func isQuoted(s string) bool { | ||
| if len(s) < 2 { | ||
| return false | ||
| } | ||
| c := s[0] | ||
| return (c == '\'' || c == '"') && s[len(s)-1] == c | ||
| } |
social4hyq
pushed a commit
to social4hyq/homebrew-core
that referenced
this pull request
Sep 20, 2026
k0sctl 0.32.2 Created-by: HarmonybrewBot Commit-by: HarmonybrewBot Merged-by: HarmonybrewBot Description: Created by `brew bump` --- Created with `brew bump-formula-pr`.<details> <summary>release notes</summary> <pre>## What's Changed * Remove long-removed podSecurityPolicy from k0sctl's init default config by @twz123 in k0sproject/k0sctl#1126 * Fix corrupted Windows k0s install command (Flags double-unquote, --kubelet-extra-args double-quote) by @vikramhh in k0sproject/k0sctl#1120 * build(deps): bump actions/setup-go from 6 to 7 by @dependabot[bot] in k0sproject/k0sctl#1115 * build(deps): bump actions/setup-python from 6 to 7 by @dependabot[bot] in k0sproject/k0sctl#1119 * build(deps): bump k8s.io/client-go from 0.36.2 to 0.36.3 by @dependabot[bot] in k0sproject/k0sctl#1123 * build(deps): bump github.com/mattn/go-isatty from 0.0.22 to 0.0.24 by @dependabot[bot] in k0sproject/k0sctl#1125 * build(deps): bump golang.org/x/text from 0.38.0 to 0.40.0 by @dependabot[bot] in k0sproject/k0sctl#1113 * build(deps): bump github.com/k0sproject/rig/v2 from 2.1.0 to 2.1.1 by @dependabot[bot] in k0sproject/k0sctl#1127 ## New Contributors * @vikramhh made their first contribution in k0sproject/k0sctl#1120 **Full Changelog**: k0sproject/k0sctl@v0.32.1...v0.32.2 ### SHA256 Checksums ``` cb40948151451c68dfca16de000cf990ee112fb2ffb4f6a5d103e665cbb43d5e *k0sctl-linux-amd64 b8de441f03ba8b53dee590d675caba1c0508ba05c53d2c77a841d31959a12ca7 *k0sctl-linux-arm64 8c05e5793da7d9e463844e075156f9c544b40088a856b9c77387971a18b23195 *k0sctl-linux-arm 65f7de2b295578d60ac7019b2131052ac2151a8416d495ccc7ea1a988bce0e26 *k0sctl-linux-riscv64 3d06cca961ba0bd2571836a19f6a67a9c2b44fe0d5684944028393265562b467 *k0sctl-win-amd64.exe 1124a07e18831bcc6df442593dde15f3c2a149060a42c05001ba59c58120a2c9 *k0sctl-darwin-amd64 cee6db821bd255e67052e00fd054ed89e1a2421a05326686ed576210caf1ffdd *k0sctl-darwin-arm64 ``` </pre> <p>View the full release notes at <a href="https://github.com/k0sproject/k0sctl/releases/tag/v0.32.2">https://github.com/k0sproject/k0sctl/releases/tag/v0.32.2</a>.</p> </details> <hr> See merge request: Harmonybrew/homebrew-core!15395
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.
On a Windows worker host (
Host.FS()is rig/v2WinFS, whoseShellQuoteispowershell.SingleQuoteand always wraps its argument in single quotes), thegenerated
k0s install worker …command is corrupted two ways:--data-dir/--token-file/--kubelet-root-dirlose their backslashes(
C:\var\lib\k0s→C:varlibk0s), so k0s resolves them as relative paths.--kubelet-extra-argsis double-quoted and backtick-mangled(
'--cluster-dns=``10.96.0.10`` …').Root cause:
Flags.AddOrReplace/AddUnlessExistunquote their argument, then callFlags.Add, which unquotes again.shellescape.Unquoteis not idempotenton backslashes — the second pass treats
\as an escape and eats it.Flags.Each(used byJoin) unquotes the value part unconditionally, withthe same hazard for a bare backslash value.
Host.K0sInstallFlagswrapsextra.Join(h.FS())in an extraquote(...),but the final
flags.Joinalready quotes once; on WindowsSingleQuotewraps every value, so this double-quotes.
All three are Windows-specific because rig/v2's
SingleQuotewraps every value,unlike POSIX
shellescape.Quotewhich leaves simple tokens bare.Fix:
AddOrReplace/AddUnlessExistappend the already-unquoted value directlyinstead of routing through
Add(which would unquote a second time).Flags.Eachonly unquotes a value actually wrapped in matching quotes (newisQuotedhelper), leaving bare backslash values intact.K0sInstallFlagsdrops the redundant outerquote(...); the finalflags.JoininK0sInstallCommandquotes once, cleanly.Per review on the issue, the standalone repro is now a table test run against
both a POSIX quoter and a Windows
SingleQuotequoter:TestK0sInstallFlagsQuotingasserts the full rendered command tail for both, and
TestFlagsUnquoteOnceguards the
Flagsprimitives against backslash corruption on both. Both fail onthe pre-fix code and pass after; existing
host_posix_test.gosuites areunchanged.
go vetandgofmtare clean.Fixes #1114