kubernetes: KUBE_EDITOR path with spaces on Windows doesn't work
What happened:
I’m trying to configure kubectl to edit files using Sublime Text 3. My Sublime Text is installed in the default location (C:\Program files\Sublime Text 3\sublime_text.exe), which contains spaces.
I cannot seem to find the correct syntax for defining the KUBE_EDITOR environment variable, which works with this path.
Error produced:
PS C:\dev> $Env:KUBE_EDITOR="C:\Program Files\Sublime Text 3\sublime_text.exe" ; kubectl edit svc myservice
'C:\Program' is not recognized as an internal or external command,
operable program or batch file.
error: there was a problem with the editor "cmd /C C:\\Program Files\\Sublime Text 3\\sublime_text.exe"
What you expected to happen:
kubectl edit <resource> starts Sublime Text with the given resource yaml, either in CMD or PowerShell.
How to reproduce it (as minimally and precisely as possible):
# Powershell!
# Define the environment variable through system settings and run `kubetl edit <resource>`, or use this one-liner in Powershell:
# See also: https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_environment_variables?view=powershell-7.3#using-the-variable-syntax
$Env:KUBE_EDITOR="C:\Program Files\Sublime Text 3\sublime_text.exe" ; kubectl edit svc myservice
# CMD
# Define the environment variable through system settings and run `kubetl edit <resource>`, or use this syntax in CMD:
# See also: https://learn.microsoft.com/en-us/windows-server/administration/windows-commands/set_1
set KUBE_CONFIG="C:\Program Files\Sublime Text 3\sublime_text.exe"
kubectl edit svc myservice
Anything else we need to know?:
I’ve tried the following values, none of these work:
C:\Program Files\Sublime Text 3\sublime_text.exe(This is the correct path.)"C:\Program Files\Sublime Text 3\sublime_text.exe"'C:\Program Files\Sublime Text 3\sublime_text.exe'C:\\Program Files\\Sublime Text 3\\sublime_text.exefile://C:/Program%20Files/Sublime%20Text%203/sublime_text.exeC:\Program^ Files\Sublime^ Text^ 3\sublime_text.exeC:\Program` Files\Sublime` Text` 3\sublime_text.exe
I have tried all variantions in both CMD and PowerShell.
Environment:
- Kubernetes client and server versions (use
kubectl version):
PS C:\dev> kubectl version --output=yaml
clientVersion:
buildDate: "2023-04-14T13:21:19Z"
compiler: gc
gitCommit: 4c9411232e10168d7b050c49a1b59f6df9d7ea4b
gitTreeState: clean
gitVersion: v1.27.1
goVersion: go1.20.3
major: "1"
minor: "27"
platform: windows/amd64
kustomizeVersion: v5.0.1
serverVersion:
buildDate: "2023-04-20T00:33:18Z"
compiler: gc
gitCommit: 8d0255af07e95b841952563253d27b0d10bd72f0
gitTreeState: clean
gitVersion: v1.26.4+k3s1
goVersion: go1.19.8
major: "1"
minor: "26"
platform: linux/amd64
- Cloud provider or hardware configuration: n/a
- OS (e.g:
cat /etc/os-release):
OS Name: Microsoft Windows 11 Pro
OS Version: 10.0.22621 N/A Build 22621
PowerShell 6.2.1
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 17 (13 by maintainers)
Fixed in #112104 (not yet merged). Just keep in mind that double-quotes need to be preserved when setting the
KUBE_EDITORfrom PowerShell - PowerShell removes them (unlike cmd.exe), so those two lines are equivalent:And with the fix from #112104 it will be possible to pass additional arguments like this (example for Notepad++):
or
The fix fill be part of v1.31.