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

refactor(plugins): Improved and simplified verifier and plugin list #313

Merged
merged 8 commits into from
Aug 8, 2019

Conversation

rhuss
Copy link
Contributor

@rhuss rhuss commented Jul 27, 2019

First sweep:

  • Added proper executable check for the current user (+ extensive tests for all combinations)
  • Refactor plugin_list to make it more straightforward
  • Separate errors and warnings
  • Don't return an error when no plugin is installed and plugin list is called
  • Simplified tests
  • Check assumption that a prefix is given in verify()
  • Fixed broken homedir expansion ( ~/ (not ~) must be expanded only when at the beginning of a path)

After this:

  • Remove plugin options from the command line
  • Remove multiple prefix support

This PR is a result of the discussion on #249 where we agreed to merge now (as the PR has been aged and grown considerably) but work on improvements right after.

@googlebot googlebot added the cla: yes Indicates the PR's author has signed the CLA. label Jul 27, 2019
@knative-prow-robot knative-prow-robot added approved Indicates a PR has been approved by an approver from all required OWNERS files. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Jul 27, 2019
@rhuss rhuss force-pushed the pr/plugin-improvements branch from 5efbc97 to c2bd8d2 Compare July 27, 2019 14:34
@rhuss
Copy link
Contributor Author

rhuss commented Jul 27, 2019

Note to reviewers: As this a refactoring PR the diff is not easy to read. All changes are confined to the plugin package.

I suggest to start at those files with these entry points:

@rhuss rhuss requested review from sixolet and maximilien and removed request for mattmoor July 28, 2019 06:17
@knative-prow-robot knative-prow-robot added size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. and removed size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Jul 28, 2019
@rhuss rhuss force-pushed the pr/plugin-improvements branch from a07bdb1 to a0ce710 Compare July 28, 2019 08:57
@rhuss
Copy link
Contributor Author

rhuss commented Jul 28, 2019

/retest

1 similar comment
@rhuss
Copy link
Contributor Author

rhuss commented Jul 28, 2019

/retest

@rhuss rhuss force-pushed the pr/plugin-improvements branch 2 times, most recently from 52beec1 to cc7667d Compare July 28, 2019 17:50
@maximilien
Copy link
Contributor

@rhuss I will get to this next week. Lots of things to tie up this week and also taking a few days off for a quick trip to London.

I will move this up my TODO list once I am back or if I have WiFi in plane on Tuesday. Promise :)

@duglin
Copy link
Contributor

duglin commented Aug 6, 2019

Can you also address this:

$ kn --lookup-plugins-in-path=true plugin list
Unable read directory '/root/.kn/plugins' from your plugins path: open /root/.kn/plugins: no such file or directory. Skipping...The following compatible plugins are available, using options:
  - plugins dir: '~/.kn/plugins'
  - lookup plugins in path: 'true'

/root/bin/kn-abc
Unable read directory '/root/src/k8s.io/kubernetes/_output/dockerized/bin/linux/amd64' from your plugins path: open /root/src/k8s.io/kubernetes/_output/dockerized/bin/linux/amd64: no such file or directory. Skipping...

That's just weird output ;-)

and

$ kn --lookup-plugins-in-path=true plugin list
Unable read directory '/root/.kn/plugins' from your plugins path: open /root/.kn/plugins: no such file or directory. Skipping...Unable read directory '/root/src/k8s.io/kubernetes/_output/dockerized/bin/linux/amd64' from your plugins path: open /root/src/k8s.io/kubernetes/_output/dockerized/bin/linux/amd64: no such file or directory. Skipping...
warning: unable to find any kn plugins in your plugin path: '[/root/.kn/plugins /root/bin /usr/local/sbin /usr/local/bin /usr/sbin /usr/bin /sbin /bin /usr/games /usr/local/games /usr/local/go/bin /root/src/bin /root/src/k8s.io/kubernetes/_output/local/go/bin /root/src/k8s.io/kubernetes/_output/dockerized/bin/linux/amd64]'

Should be empty.

$ ./kn plugin list
No plugins found in path /root/.kn/plugins

It should show nothing IMO

@rhuss
Copy link
Contributor Author

rhuss commented Aug 6, 2019

@duglin

  • Non-existing path directories are ignored (like for real path handling), so no output here anymore
  • Configuration of where to lookup configuration is only shown with --verbose
  • For no plugin installed kn plugin list shows
No plugins found in ~/.kn/plugins

The later error message could be improved to say "No plugins are found in ~/.kn/plugins nor in your path" if path lookup is enable

@rhuss
Copy link
Contributor Author

rhuss commented Aug 6, 2019

It should show nothing IMO

Yes, that could be done, too. I suggest to print nothing, but with --verbose we print the line above.

@duglin
Copy link
Contributor

duglin commented Aug 6, 2019

For no plugin installed kn plugin list shows

No plugins found in ~/.kn/plugins

I don't see the value in showing this - let it be controlled via --verbose as you said. But if we MUST show something w/o --verbose then I would suggest you remove the in ~/.kn/plugins since for consistency you should then show the $PATH value when we search $PATH - and that's just annoying. Also, we don't need to remind people where the dir is.

@duglin
Copy link
Contributor

duglin commented Aug 6, 2019

It should show nothing IMO

Yes, that could be done, too. I suggest to print nothing, but with --verbose we print the line above.

Yep. I tend to look at things like this from two perspectives:
1 - a non-day-zero user. Meaning, I've been using the tool for a long time and want "just the facts" - and any noise I have to "skip over" is just annoying. So --verbose makes a lot more sense to me. As an extreme case imagine if ls did that:

$ ls
no files found

yuck!! ;-)
2 - scripting. I tend to bash script a lot of these things and being able to know if there's output via [[ -z ${output} ]] (or wc) is really really handy. Otherwise I have to do ugly grep -v stuff - which is just annoying for something everyone will just ignore.

@rhuss
Copy link
Contributor Author

rhuss commented Aug 6, 2019

/retest

Copy link
Contributor

@sixolet sixolet left a comment

Choose a reason for hiding this comment

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

Actually not bad to review at all :)

pkg/kn/commands/plugin/plugin_verifier.go Outdated Show resolved Hide resolved
rhuss added 2 commits August 7, 2019 08:33
* Added proper executable check for current user
* Refactor plugin_list to make it more straightforward
* Seperate errors and warnings
* Don't return an error when no plugin is installed and `plugin list` is called
* Simplified tests
* Check assumption that a prefix is given in verify()
rhuss added 4 commits August 7, 2019 08:33
@rhuss rhuss force-pushed the pr/plugin-improvements branch from cc7667d to 4cafffd Compare August 7, 2019 07:28
@rhuss
Copy link
Contributor Author

rhuss commented Aug 7, 2019

/retest

pluginsDir = filepath.Join(tmpPathDir, "plugins")
pluginsDirFlag = fmt.Sprintf("--plugins-dir=%s", pluginsDir)
func (ctx *testContext) createTestPluginWithPath(pluginName string, fileMode os.FileMode, path string) error {
if runtime.GOOS == "windows" {
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice. I completely forgot and ignored Windows users. But good on this.

Copy link
Contributor

Choose a reason for hiding this comment

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

Though I have no way to test actual Windows plugin

Copy link
Contributor Author

Choose a reason for hiding this comment

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

same for me ;-( I think we need at least a CI test suite somehow. I wonder how other CLI's like kubectl does it ?

}
}

func printLabelWithConditionalPluralS(out io.Writer, label string, nr int) {
Copy link
Contributor

Choose a reason for hiding this comment

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

...PluralS... why not ...Plurals?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Because I refer to the plural "S" to be added at the end, and I don't refer to the plural of plural ;-) (which would be "plurals", supposed that something like this exists)

Copy link
Contributor

Choose a reason for hiding this comment

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

OK cool... weird, but cool :)

Copy link
Contributor

@maximilien maximilien left a comment

Choose a reason for hiding this comment

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

Overall looks good. Left some comments, mostly minor. I still think we should make plugin list verbose by default since the point of the command in my view is to allow the user to see the various plugins available. It’s important that she knows which plugins are valid, executable, and “ready” versus those that are causing problems since otherwise how would she know? So overall for me errors and warnings are important to give as much info as possible to the user for that command.

@knative-prow-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: maximilien, rhuss, sixolet

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 [maximilien,rhuss,sixolet]

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

@rhuss
Copy link
Contributor Author

rhuss commented Aug 8, 2019

So overall for me errors and warnings are important to give as much info as possible to the user for that command.

warnings and errors are printed even without --verbose. It's only that the static configuration information where plugins are looked up is hidden without --verbose.

@knative-metrics-robot
Copy link

The following is the coverage report on pkg/.
Say /test pull-knative-client-go-coverage to re-run this coverage report

File Old Coverage New Coverage Delta
pkg/kn/commands/plugin/plugin_list.go 78.0% 81.8% 3.8
pkg/kn/commands/plugin/plugin_list_flags.go Do not exist 100.0%
pkg/kn/commands/plugin/plugin_test_helper.go 91.7% 86.7% -5.0
pkg/kn/commands/plugin/plugin_verifier.go Do not exist 78.2%

@rhuss
Copy link
Contributor Author

rhuss commented Aug 8, 2019

/retest

@maximilien
Copy link
Contributor

/lgtm

@knative-prow-robot knative-prow-robot added the lgtm Indicates that a PR is ready to be merged. label Aug 8, 2019
@knative-prow-robot knative-prow-robot merged commit 3594b39 into knative:master Aug 8, 2019
navidshaikh added a commit to navidshaikh/client that referenced this pull request Apr 7, 2020
* Add RPM SPEC file

 Minimize the file diff between midstream and downstream.

* Update RELEASE.md with instructions to update SPEC file

 and Dockerfile.cliartifacts.rhel

* Remove gcc from BuildRequires
coryrc pushed a commit to coryrc/client that referenced this pull request May 14, 2020
* Add image to back up artifacts

This copies images from gcr.io/knative-releases into the
gcr.io/knative-backups registry using gcrane.

This also copies knative release yamls (kube manifests) from
gs://knative-releases to gs://knative-backups using gsutil.

* Add job to back up artifacts

This just wires up the prow config to use the backups image.

* Properly escape $ in shell command in Makefile

Co-Authored-By: jonjohnsonjr <[email protected]>

* Remove resource requests
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. cla: yes Indicates the PR's author has signed the CLA. lgtm Indicates that a PR is ready to be merged. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants