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

feature(kn plugins): Implements Kn plugins re-using some code from kubectl plugins. #249

Merged
merged 5 commits into from
Jul 26, 2019

Conversation

maximilien
Copy link
Contributor

This version contains the following:

  1. wraps the main root Kn command to support plugin
  2. plugins are any executable in kn's config new pluginDir
    variable which defaults to $PATH
  3. plugins must have name kn-*
  4. 'kn plugin list' sub-command to list found kn plugins
  5. skips any kn plugins found with name that match core
    commands, e.g., kn-service would be ignored
  6. can execute any valid kn plugins found, e.g.,
    kn valid where the plugin file kn-valid is in path
    specified in 2.
  7. unit tests (using gotest.tools)

And is missing:

  1. integration tests
  2. plugin install command
  3. plugin repository command
  4. plugin / Knative server version negotiation
  5. anything else we agree on in plugin req doc

I plan to create issues for the things missing so we don't
end up with an even bigger PR. It's already big as is but is a
good MVP as per plugins requirement doc.

Fixes #92

@googlebot googlebot added the cla: yes Indicates the PR's author has signed the CLA. label Jul 9, 2019
@knative-prow-robot knative-prow-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jul 9, 2019
@knative-prow-robot knative-prow-robot added the size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. label Jul 9, 2019
@maximilien
Copy link
Contributor Author

maximilien commented Jul 9, 2019

/assign @duglin @sixolet

@maximilien
Copy link
Contributor Author

OK so pull-knative-client-go-coverage is failing since I don't have any unit tests for:

  • pkg/kn/commands/plugin/plugin_handler.go
  • pkg/kn/commands/plugin/plugin_list.go

Fair and good catch. I will add these tomorrow and update this PR. However, feel free to start your review and/or testing this. Thx.

This version contains the following:

1. wraps the main root Kn command to support plugin
2. plugins are any executable in kn's config new pluginDir
   variable which defaults to $PATH
3. plugins must have name kn-*
4. 'kn plugin list' sub-command to list found kn plugins
5. skips any kn plugins found with name that match core
   commands, e.g., kn-service would be ignored
6. can execute any valid kn plugins found, e.g.,
   `kn valid` where the plugin file `kn-valid` is in path
   specified in 2.
7. unit tests (using gotest.tools)

And is missing:

1. integration tests
2. plugin install command
3. plugin repository command
4. plugin / Knative server version negotiation
5. anything else we agree on in plugin req doc

I plan to create issues for the things missing so we don't
end up with an even bigger PR. It's already big as is but is a
good MVP as per plugins requirement doc.
@maximilien
Copy link
Contributor Author

OK added tests (lots) for pkg/kn/commands/plugin/plugin_list.go.

I'll work on adding for pkg/kn/commands/plugin/plugin_handler.go next.

@rhuss
Copy link
Contributor

rhuss commented Jul 9, 2019

Maybe now it's a good time to move help_testing.go to helper_test.go ? ;-)

@maximilien
Copy link
Contributor Author

maximilien commented Jul 9, 2019

Maybe now it's a good time to move help_testing.go to helper_test.go ? ;-)

OK, we are ping ponging this file, but helper_test.go does not work since it will not compile. I get these failures when I rename:

➜  client git:(kn-plugins4) ✗ ./hack/build.sh
🧽  Format
⚖️  License
📖 Docs
🚧 Compile
🧪  Test
🔥 Failure
=== RUN   TestDummy
--- PASS: TestDummy (0.00s)
PASS
ok  	github.com/knative/client/pkg	(cached)
# github.com/knative/client/pkg/kn/commands/plugin [github.com/knative/client/pkg/kn/commands/plugin.test]
pkg/kn/commands/plugin/path_verifier_test.go:35:18: undefined: commands.CreateTestKnCommand
pkg/kn/commands/plugin/plugin_list_test.go:40:19: undefined: commands.CreateTestKnCommand
[...]

Unless I am missing something, I think the only thing I can do is to have it as test_helper.go if you prefer. Cheers 🍻

@rhuss
Copy link
Contributor

rhuss commented Jul 9, 2019

Ok, I see.

I really talked with some folks who know testing better than me, and they assured me its possible to have _test.go files without any tests which are used only during tests. That's why is so dogged ;)

Let's get the fixed because I really think that these helpers should be reachable only in test scope.

@maximilien
Copy link
Contributor Author

Let's get the fixed because I really think that these helpers should be reachable only in test scope.

Let me push the pkg/kn/commands/plugin/plugin_handler_test.go today. Which completes this PR and we can see what makes sense. Thx.

@maximilien maximilien force-pushed the kn-plugins4 branch 2 times, most recently from d44b95b to 0c6ebac Compare July 10, 2019 23:43
@maximilien
Copy link
Contributor Author

maximilien commented Jul 10, 2019

OK @rhuss and others, this version has all the test but the coverage fails since I have a common testing_helper.go that the coverage tool needs to ignore. I cannot name it helper_test.go since doing so fails compilation.

I think we need to ask the test-infra team if they have a way to flag or tag a file to be skipped in the coverage test. Similar to tagging files for ignoring during golang builds, e.g.:

// +build !linux
...

Perhaps @adrcunha has some magic up his sleeves already... I know he's been super helpful in the past. Hoping.

cmd/kn/main.go Outdated Show resolved Hide resolved
docs/cmd/kn.md Outdated Show resolved Hide resolved
docs/cmd/kn.md Outdated Show resolved Hide resolved
docs/cmd/kn_completion.md Outdated Show resolved Hide resolved
docs/cmd/kn_plugin.md Outdated Show resolved Hide resolved
@adrcunha
Copy link
Contributor

OK @rhuss and others, this version has all the test but the coverage fails since I have a common testing_helper.go that the coverage tool needs to ignore. I cannot name it helper_test.go since doing so fails compilation.

Its current code coverage is at 47%. 3pp more and the code coverage job will pass. If you click the file name in the coverage report above you'll see the methods that weren't tested.

I think I mentioned it in some other PR, but if the requirement of having at least 50% code coverage in PRs is currently too hard, an admin can mark the job optional so it won't block submissions.

docs/cmd/kn_plugin.md Outdated Show resolved Hide resolved
docs/cmd/kn_plugin.md Outdated Show resolved Hide resolved
docs/cmd/kn_plugin_list.md Outdated Show resolved Hide resolved
@maximilien
Copy link
Contributor Author

OK @rhuss and @sixolet. Pushed latest version. It's close but not quite ready as I can see three remaining issues:

  1. using lookupPluginsInPath and pluginsDir options will list correct plugins (for the 4 combinations). However, executing the plugins is trickier. Currently only plugins in pluginsDir is executing. I think I need to remove --lookup-plugins-in-path flag if present to allow current code to work. But I need to test this before committing the change.

  2. Viper loading and saving of config seems broken. Likely how I am using Viper. Essentially, when I change the config and run ./kn ... they are not loaded, so the default is used.

  3. I have some integration tests that I need to also include. However, I need Improves(e2e): improves integration tests and to better run locally #274 to be merged first and simply had not had a chance to rebase 274 so it could be merged. Will do so tonight or tomorrow AM.


That said, one approach if the current code looks good to you is to merge so I can address these issues separately. Otherwise, I'll keep churning tomorrow and get this PR with fixes for above.

Let me know if you also see any additional issues. Thanks.

@rhuss
Copy link
Contributor

rhuss commented Jul 23, 2019

I will have a look tomorrow morning our time (but from my understanding I'm really not sure that (a) we need both options and (b) whether it should be not only configuration variables.

@maximilien
Copy link
Contributor Author

maximilien commented Jul 24, 2019

OK @rhuss and @sixolet this is ready to merge. Assuming I pass CI.

Please note:

  1. I have not added my integration tests since not done, however, manual tests worked. I have lots of plugins on my system in different directories and have a small script (converting to IT) to check.
  2. While your requested changes appear easy, they are not :) but it's done. Pay attention to what I had to do in root.go for instance. Needed since the cobra.Command is actually not executed for a plugin, and thus the flags are not parsed to bound variables. Was fun to discover!
  3. I am sure we can improve things. But I suggest we get this in (assuming no major comments) and we can refine after.

Ping me on Slack if you need my urgent attention on something. Would be good to have this in soon. Thx.

@maximilien
Copy link
Contributor Author

@sixolet see issue #288 for the modifiable prefix for plugins

@maximilien
Copy link
Contributor Author

:) CI green @rhuss @sixolet

@rhuss
Copy link
Contributor

rhuss commented Jul 24, 2019

@sixolet see issue #288 for the modifiable prefix for plugins

I don't think it was about a configurable prefix what @sixolet meant (but to avoid a prefix in ~/.kn/plugins as its redundant). I added my opinion on this in #288 (comment) and why I think this is not a good idea.

@rhuss
Copy link
Contributor

rhuss commented Jul 25, 2019

@maximilien I'm going to make my review later today. sorry for the delay, just tons on my plate right now :(

@maximilien
Copy link
Contributor Author

@maximilien I'm going to make my review later today. sorry for the delay, just tons on my plate right now :(

Fully understood. You are great at reviews so not worried. I’ll submit the kn plugins IT as separate PR that depends on this one.

Thanks!

Copy link
Contributor

@rhuss rhuss left a comment

Choose a reason for hiding this comment

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

Thanks for revisiting this PR ! I'm somewhat fine with this PR (although most of my comments were not addressed) except two things which I consider as blocking issues:

When those two are fixed, IMO we can merge that and I would address then the following concerns:

  • Using os.Separator
  • No global commandline options, just config vars
  • Executable check
  • Only one prefix
  • Dangerous assumption about the first parameter in Verify()

I think it's better now to elaborate on my points in code than in comments.

docs/cmd/kn.md Show resolved Hide resolved
pkg/kn/commands/plugin/path_verifier.go Outdated Show resolved Hide resolved
pkg/kn/commands/plugin/path_verifier.go Show resolved Hide resolved
pkg/kn/commands/plugin/path_verifier.go Show resolved Hide resolved
pkg/kn/commands/plugin/plugin_handler.go Show resolved Hide resolved
pkg/kn/commands/plugin/plugin_handler.go Show resolved Hide resolved
pkg/kn/commands/plugin/plugin_handler.go Show resolved Hide resolved
pkg/kn/commands/plugin/plugin_handler.go Outdated Show resolved Hide resolved
@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/path_verifier.go Do not exist 80.6%
pkg/kn/commands/plugin/plugin.go Do not exist 100.0%
pkg/kn/commands/plugin/plugin_flags.go Do not exist 100.0%
pkg/kn/commands/plugin/plugin_handler.go Do not exist 89.2%
pkg/kn/commands/plugin/plugin_list.go Do not exist 78.0%
pkg/kn/commands/plugin/plugin_test_helper.go Do not exist 91.7%
pkg/kn/commands/testing_helper.go Do not exist 97.4%
pkg/kn/core/root.go 52.5% 56.5% 4.0

@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/path_verifier.go Do not exist 80.6%
pkg/kn/commands/plugin/plugin.go Do not exist 100.0%
pkg/kn/commands/plugin/plugin_flags.go Do not exist 100.0%
pkg/kn/commands/plugin/plugin_handler.go Do not exist 89.2%
pkg/kn/commands/plugin/plugin_list.go Do not exist 78.0%
pkg/kn/commands/plugin/plugin_test_helper.go Do not exist 91.7%
pkg/kn/commands/testing_helper.go Do not exist 97.4%
pkg/kn/core/root.go 52.5% 56.5% 4.0

@maximilien
Copy link
Contributor Author

OK @rhuss see latest update. Passes CI and my local ITs---I will submit different issue/PR for that soon today or Monday worst case. Ping me if any other issues. I'll monitor slack. Thx.

Copy link
Contributor

@rhuss rhuss left a comment

Choose a reason for hiding this comment

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

Thanks a lot for the quick fix ! lgtm and I will follow up with my suggestions which we then can discuss in the next month or so ;-P

/lgtm
/approve

@knative-prow-robot knative-prow-robot added the lgtm Indicates that a PR is ready to be merged. label Jul 26, 2019
@knative-prow-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

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

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:

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

@maximilien
Copy link
Contributor Author

maximilien commented Jul 26, 2019

@sixolet I think you need to also add your lgtm. Or let me know if something urgent is missing. Planning to open issues on items that require more discussions and agreement, e.g., prefix.

@rhuss
Copy link
Contributor

rhuss commented Jul 26, 2019

@sixolet I think you need to also add your lgtm

I think we are good for now, but with some homework left. 'happy to take that over. Thanks a ton to @maximilien for doing the hard work !

@knative-prow-robot knative-prow-robot merged commit 59b2855 into knative:master Jul 26, 2019
maximilien added a commit to maximilien/client that referenced this pull request Jul 26, 2019
…ve#249)

This version contains the following:

1. wraps the main root Kn command to support plugin
2. plugins are any executable in kn's config new pluginDir
   variable which defaults to $PATH
3. plugins must have name kn-*
4. 'kn plugin list' sub-command to list found kn plugins
5. skips any kn plugins found with name that match core
   commands, e.g., kn-service would be ignored
6. can execute any valid kn plugins found, e.g.,
   `kn valid` where the plugin file `kn-valid` is in path
   specified in 2.
7. unit tests (using gotest.tools)

And is missing:

1. integration tests
2. plugin install command
3. plugin repository command
4. plugin / Knative server version negotiation
5. anything else we agree on in plugin req doc

I plan to create issues for the things missing so we don't
end up with an even bigger PR. It's already big as is but is a
good MVP as per plugins requirement doc.
@maximilien maximilien deleted the kn-plugins4 branch December 20, 2019 02:17
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.

kn plugins
8 participants