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

Check whether PATH has been set up correctly #489

Merged
merged 2 commits into from
Feb 5, 2020

Conversation

corneliusweig
Copy link
Contributor

Fixes #485
Related Homebrew/homebrew-core#49547

Homebrew refuses to add a post-install message for setting up
the PATH variable with krew's plugin store. Therefore we need
to check this on our side to warn users about an incomplete
setup. The goal is to

  • print specific instructions for each shell/OS.
  • not print the instructions when krew installs itself.

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Feb 1, 2020
@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. approved Indicates a PR has been approved by an approver from all required OWNERS files. labels Feb 1, 2020
@codecov-io
Copy link

codecov-io commented Feb 1, 2020

Codecov Report

Merging #489 into master will increase coverage by 0.52%.
The diff coverage is 91.66%.

Impacted file tree graph

@@           Coverage Diff            @@
##           master   #489      +/-   ##
========================================
+ Coverage   56.47%    57%   +0.52%     
========================================
  Files          19     21       +2     
  Lines         926    956      +30     
========================================
+ Hits          523    545      +22     
- Misses        350    357       +7     
- Partials       53     54       +1
Impacted Files Coverage Δ
cmd/krew/cmd/internal/setup_check.go 91.66% <91.66%> (ø)
cmd/krew/cmd/internal/security_notice.go 0% <0%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 4303b6a...b9675e8. Read the comment docs.

internal/assertion/setup.go Outdated Show resolved Hide resolved
internal/assertion/setup.go Outdated Show resolved Hide resolved
internal/assertion/setup.go Outdated Show resolved Hide resolved
internal/assertion/setup.go Outdated Show resolved Hide resolved
internal/assertion/setup.go Outdated Show resolved Hide resolved
export PATH="${PATH}:${HOME}/.krew/bin"`
)

func CheckSetup(w io.Writer, paths environment.Paths) {
Copy link
Member

@ahmetb ahmetb Feb 2, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tbh the "assert" in the package name could make one think this works like "assert" keyword, but it doesn't. maybe pkg internal/platform?

Copy link
Contributor Author

@corneliusweig corneliusweig Feb 2, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm struggling with a good package name. installation and environment would make most sense to me, but those are taken already. platform doesn't quite ring the right bells to me (although it's better than assertion).
What do you think about internal/setup.WarnIfBinDirNotInPATH?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I went with setup for now. Let me know your thoughts.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe shouldnt be in a separate pkg :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😃 That could simplify the naming. How about the environment package?

internal/assertion/setup.go Outdated Show resolved Hide resolved
internal/assertion/setup.go Outdated Show resolved Hide resolved
internal/assertion/setup.go Outdated Show resolved Hide resolved
@corneliusweig
Copy link
Contributor Author

Thanks for your comments! PTAL

}

krewPluginPath := paths.BinPath()
return strings.Contains(os.Getenv("PATH"), krewPluginPath)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's use if there's an utility in kubectl plugin PATH scanning logic.

If not, please separate by os.PathListSeparator, and do a == check; not Contains.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't really look like they have a dedicated util for that: https://github.com/kubernetes/kubernetes/blob/5cc945ad0d2fad2bdde7591490fcf0401fa335aa/staging/src/k8s.io/kubectl/pkg/cmd/plugin/plugin.go#L105

But checking for equality sounds right.

"sigs.k8s.io/krew/internal/testutil"
)

func TestCheckSetup_firstRun(t *testing.T) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rm test func names :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess you meant the forgotten rename?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know what I was saying above.
I think I meant make sure Test names are the same as func name.

@ahmetb
Copy link
Member

ahmetb commented Feb 3, 2020

This PR is getting too large.
We're just supposed to split env and print a message. :) We don't even need this level of excessive testing. Plus now the environment package got refactored further.

Can we split that out to a different PR so that I don't lose context?

IMO this functionality can be in main package, doesn't warrant its own pkg.

Homebrew refuses to add a post-install message for setting up
the PATH variable with krew's plugin store. Therefore we need
to check this on our side to warn users about an incomplete
setup. The goal is to
- print specific instructions for each shell/OS.
- not print the instructions when krew installs itself.
@corneliusweig
Copy link
Contributor Author

Err.. I agree. This has gotten a little out of hand. It should be simpler now. PTAL

paths := environment.NewPaths(tempDir.Path("does-not-exist"))
res := IsBinDirInPATH(paths)
if res == false {
t.Errorf("Expected positive result on first run")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: start error messages lowercase

Comment on lines 40 to 42
if err := os.Mkdir(tempDir.Path("exists"), os.ModePerm); err != nil {
t.Fatal(err)
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we just pass tempDir as path, instead of creating a dir called "exists"?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure. I wanted to make it more explicit that the directory is there vs. the non-existent case. But I guess this will do as well.

@ahmetb
Copy link
Member

ahmetb commented Feb 4, 2020

/lgtm
just some nits
/hold
feel free to cancel if not worth fixing.

I think it's gotten to 200 lines mostly because we added shell-specific handling, which is a better UX anyway.

@k8s-ci-robot k8s-ci-robot added do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. lgtm "Looks good to me", indicates that a PR is ready to be merged. labels Feb 4, 2020
@k8s-ci-robot k8s-ci-robot removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Feb 4, 2020
@ahmetb
Copy link
Member

ahmetb commented Feb 4, 2020

/lgtm
/approve
thanks much!

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

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: ahmetb, corneliusweig

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

The pull request process is described here

Needs approval from an approver in each of these files:
  • OWNERS [ahmetb,corneliusweig]

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

@corneliusweig
Copy link
Contributor Author

/hold cancel

@k8s-ci-robot k8s-ci-robot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Feb 5, 2020
@k8s-ci-robot k8s-ci-robot merged commit 7ec26f6 into kubernetes-sigs:master Feb 5, 2020
@corneliusweig corneliusweig deleted the w/PATH-check branch February 5, 2020 20:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Print warning on every command if PATH does not have KREW_ROOT/bin
4 participants