Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix editor launch with Windows cmd.exe when KUBE_EDITOR has spaces in path #112104

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

oldium
Copy link

@oldium oldium commented Aug 29, 2022

What type of PR is this?

/kind bug

What this PR does / why we need it:

When on Windows and cmd.exe and we are not able to parse the EDITOR/KUBE_EDITOR environmental variables into arguments, the Go language documentation mentions that when executing cmd.exe, special care needs to be taken regarding arguments - pass whole command line as a string and not as separate arguments with SysProcAttr.CmdLine.

Moreover, when doing this, the whole string after cmd /C needs to be double-quoted.

Which issue(s) this PR fixes:

Fixes #72734

Special notes for your reviewer:

Does this PR introduce a user-facing change?

Fixed EDITOR/KUBE_EDITOR with double-quoted paths with spaces when on Windows cmd.exe.

Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.:


@k8s-ci-robot k8s-ci-robot added release-note Denotes a PR that will be considered when it comes time to generate release notes. kind/bug Categorizes issue or PR as related to a bug. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. do-not-merge/needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. labels Aug 29, 2022
@k8s-ci-robot
Copy link
Contributor

Welcome @oldium!

It looks like this is your first PR to kubernetes/kubernetes 🎉. Please refer to our pull request process documentation to help your PR have a smooth ride to approval.

You will be prompted by a bot to use commands during the review process. Do not be afraid to follow the prompts! It is okay to experiment. Here is the bot commands documentation.

You can also check if kubernetes/kubernetes has its own contribution guidelines.

You may want to refer to our testing guide if you run into trouble with your tests not passing.

If you are having difficulty getting your pull request seen, please follow the recommended escalation practices. Also, for tips and tricks in the contribution process you may want to read the Kubernetes contributor cheat sheet. We want to make sure your contribution gets all the attention it needs!

Thank you, and welcome to Kubernetes. 😃

@k8s-ci-robot k8s-ci-robot added needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Aug 29, 2022
@k8s-ci-robot
Copy link
Contributor

Hi @oldium. Thanks for your PR.

I'm waiting for a kubernetes member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@k8s-ci-robot k8s-ci-robot added needs-priority Indicates a PR lacks a `priority/foo` label and requires one. area/kubectl labels Aug 29, 2022
@k8s-ci-robot k8s-ci-robot added sig/cli Categorizes an issue or PR as relevant to SIG CLI. and removed do-not-merge/needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. labels Aug 29, 2022
@oldium oldium changed the title Fix editor launch with Windows cmd.exe when KUBE_EDITOR has spaces Fix editor launch with Windows cmd.exe when KUBE_EDITOR has spaces in path Aug 29, 2022
@k8s-triage-robot
Copy link

The Kubernetes project currently lacks enough contributors to adequately respond to all issues and PRs.

This bot triages issues and PRs according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the issue is closed

You can:

  • Mark this issue or PR as fresh with /remove-lifecycle stale
  • Mark this issue or PR as rotten with /lifecycle rotten
  • Close this issue or PR with /close
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/lifecycle stale

@k8s-ci-robot k8s-ci-robot added the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Nov 27, 2022
@oldium
Copy link
Author

oldium commented Nov 27, 2022

/remove-lifecycle stale

@k8s-ci-robot k8s-ci-robot removed the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Nov 27, 2022
@k8s-triage-robot
Copy link

The Kubernetes project currently lacks enough contributors to adequately respond to all PRs.

This bot triages PRs according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the PR is closed

You can:

  • Mark this PR as fresh with /remove-lifecycle stale
  • Close this PR with /close
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/lifecycle stale

@k8s-ci-robot k8s-ci-robot added the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Feb 25, 2023
@oldium
Copy link
Author

oldium commented Feb 25, 2023

/remove-lifecycle stale

@k8s-ci-robot k8s-ci-robot removed the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Feb 25, 2023
@dims
Copy link
Member

dims commented May 3, 2023

@marosset @jsturtevant Can you PTAL / find someone to kick the tires of this change?

@marosset
Copy link
Contributor

marosset commented May 3, 2023

/sig windows

@k8s-ci-robot k8s-ci-robot added the sig/windows Categorizes an issue or PR as relevant to SIG Windows. label May 3, 2023
@marosset
Copy link
Contributor

marosset commented May 3, 2023

@marosset @jsturtevant Can you PTAL / find someone to kick the tires of this change?

I can try it out

@dims
Copy link
Member

dims commented May 4, 2023

@claudiubelu
Copy link
Contributor

Mark said that it worked for him, so LGTM.

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Apr 23, 2024
@k8s-ci-robot
Copy link
Contributor

LGTM label has been added.

Git tree hash: 3e075b7ef78bf57a9ce59944620d001b4291f5fd

@aravindhp
Copy link
Contributor

/triage accepted

@k8s-ci-robot k8s-ci-robot added triage/accepted Indicates an issue or PR is ready to be actively worked on. and removed needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. labels Apr 23, 2024
@aravindhp
Copy link
Contributor

/priority important-soon

@k8s-ci-robot k8s-ci-robot added priority/important-soon Must be staffed and worked on either currently, or very soon, ideally in time for the next release. and removed needs-priority Indicates a PR lacks a `priority/foo` label and requires one. labels Apr 23, 2024
@aravindhp
Copy link
Contributor

/ok-to-test

@k8s-ci-robot k8s-ci-robot removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Apr 24, 2024
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: oldium
Once this PR has been reviewed and has the lgtm label, please assign seans3 for approval. For more information see the Kubernetes Code Review Process.

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@oldium
Copy link
Author

oldium commented Apr 24, 2024

Fixed CI findings, rebased.

/retest

@marosset
Copy link
Contributor

Sorry - this feel off my radar - i'll take a look

@marosset
Copy link
Contributor

I tried this again in powershell and hit an issue when the path had a space in it.

PS C:\temp> .\kubectl.exe version
Client Version: v1.31.0-alpha.0.379+df71672e579896
Kustomize Version: v5.0.4-0.20230601165947-6ce0bf390ce3
Server Version: v1.31.0-alpha.0.403+bc05bef903c063

(the client should be from head of PR branch)

I copied notepad.exe to c:\temp\has space\notepad.exe
and ran

PS C:\temp> $env:KUBE_EDITOR="C:\temp\has space\notepad.exe"
PS C:\temp> .\kubectl.exe edit ds -n kube-system kube-proxy-windows
'C:\temp\has' 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:\\temp\\has space\\notepad.exe"

@marosset
Copy link
Contributor

it i set KUBE_EDITOR like this it works in powershell

$env:KUBE_EDITOR='"C:\temp\has space\notepad.exe"'

I think we should try and handle setting the ENV VAR not wrapped in single quotes if possible

@oldium
Copy link
Author

oldium commented Apr 26, 2024

I tried this again in powershell and hit an issue when the path had a space in it.

PS C:\temp> .\kubectl.exe version
Client Version: v1.31.0-alpha.0.379+df71672e579896
Kustomize Version: v5.0.4-0.20230601165947-6ce0bf390ce3
Server Version: v1.31.0-alpha.0.403+bc05bef903c063

(the client should be from head of PR branch)

I copied notepad.exe to c:\temp\has space\notepad.exe and ran

PS C:\temp> $env:KUBE_EDITOR="C:\temp\has space\notepad.exe"
PS C:\temp> .\kubectl.exe edit ds -n kube-system kube-proxy-windows
'C:\temp\has' 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:\\temp\\has space\\notepad.exe"

This is expected. PowerShell removes the double-quotes, so you actually have KUBE_EDITOR set without double-quotes. The following does the trick in PowerShell:

$env:KUBE_EDITOR="`"C:\temp\has space\notepad.exe`""
$env:KUBE_EDITOR='"C:\temp\has space\notepad.exe"'

@oldium
Copy link
Author

oldium commented Apr 26, 2024

Please see #117781 (comment)

@oldium
Copy link
Author

oldium commented Apr 26, 2024

If you would like to interpret KUBE_EDITOR literally (i.e. as a path only), this would be a behaviour change.

@oldium
Copy link
Author

oldium commented Apr 26, 2024

it i set KUBE_EDITOR like this it works in powershell

$env:KUBE_EDITOR='"C:\temp\has space\notepad.exe"'

I think we should try and handle setting the ENV VAR not wrapped in single quotes if possible

Single-quotes in your example just ensured that double-quotes are part of KUBE_EDITOR environment variable. Single-quotes are not part of the value set to env var. Trying to interpret values in any way could lead to errors - compare the following and try to infer what is a path and what is an argument:

Without spaces (groups are functionally equivalent, each 2 lines represent equivalent values):

# Value: C:\temp\nospace\notepad++.exe
# cmd.exe: set KUBE_EDITOR=C:\temp\nospace\notepad++.exe
$env:KUBE_EDITOR='C:\temp\nospace\notepad++.exe'
$env:KUBE_EDITOR="C:\temp\nospace\notepad++.exe"
# Value: "C:\temp\nospace\notepad++.exe"
# cmd.exe: set KUBE_EDITOR="C:\temp\nospace\notepad++.exe"
$env:KUBE_EDITOR='"C:\temp\nospace\notepad++.exe"'
$env:KUBE_EDITOR="`"C:\temp\nospace\notepad++.exe`""

# Value: C:\temp\nospace\notepad++.exe -multiInst -notabbar -nosession
# cmd.exe: set KUBE_EDITOR=C:\temp\nospace\notepad++.exe -multiInst -notabbar -nosession
$env:KUBE_EDITOR='C:\temp\nospace\notepad++.exe -multiInst -notabbar -nosession'
$env:KUBE_EDITOR="C:\temp\nospace\notepad++.exe -multiInst -notabbar -nosession"
# Value: "C:\temp\nospace\notepad++.exe" -multiInst -notabbar -nosession
# cmd.exe: set KUBE_EDITOR="C:\temp\nospace\notepad++.exe" -multiInst -notabbar -nosession
$env:KUBE_EDITOR='"C:\temp\nospace\notepad++.exe" -multiInst -notabbar -nosession'
$env:KUBE_EDITOR="`"C:\temp\nospace\notepad++.exe`" -multiInst -notabbar -nosession"

With spaces:

# Value: "C:\temp\has space\notepad++.exe"
# cmd.exe: set KUBE_EDITOR="C:\temp\has space\notepad++.exe"
$env:KUBE_EDITOR='"C:\temp\has space\notepad++.exe"'
$env:KUBE_EDITOR="`"C:\temp\has space\notepad++.exe`""
# Value: "C:\temp\has space\notepad++.exe" -multiInst -notabbar -nosession'
# cmd.exe: set KUBE_EDITOR="C:\temp\has space\notepad++.exe" -multiInst -notabbar -nosession
$env:KUBE_EDITOR='"C:\temp\has space\notepad++.exe" -multiInst -notabbar -nosession'
$env:KUBE_EDITOR="`"C:\temp\has space\notepad++.exe`" -multiInst -notabbar -nosession"

@oldium
Copy link
Author

oldium commented Apr 26, 2024

Updated previous comment with all variants of setting the KUBE_EDITOR value in cmd.exe and in PowerShell. I do not think the current rules need any revision :-)

@marosset
Copy link
Contributor

Thanks for the links to the comments.
I'm OK with these changes.
Maybe we can update some of the kubectl docs for how to handle paths with spaces on Windows but everything is functional.

/lgtm

thanks @oldium

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Apr 26, 2024
@k8s-ci-robot
Copy link
Contributor

LGTM label has been added.

Git tree hash: 236c7c8f62edfb262e3ed31cca2f7207b6cffcd8

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/kubectl cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/bug Categorizes issue or PR as related to a bug. lgtm "Looks good to me", indicates that a PR is ready to be merged. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. priority/important-soon Must be staffed and worked on either currently, or very soon, ideally in time for the next release. release-note Denotes a PR that will be considered when it comes time to generate release notes. sig/cli Categorizes an issue or PR as relevant to SIG CLI. sig/windows Categorizes an issue or PR as relevant to SIG Windows. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. triage/accepted Indicates an issue or PR is ready to be actively worked on.
Projects
Status: Needs Triage
Status: In Review
Development

Successfully merging this pull request may close these issues.

not obvious (or possible) how to use an editor with spaces in the command
9 participants