-
Notifications
You must be signed in to change notification settings - Fork 1.6k
feature/plugins: config layout, --plugins flag, and plugin name validation
#1403
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/plugins: config layout, --plugins flag, and plugin name validation
#1403
Conversation
7b3628b to
98b7b5f
Compare
layout and plugin name validationlayout and plugin name validation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we need to move to scaffold v3 (or v3-alpha) to implement the plugins system. We definetely will need to move to kubebuilder v3.y.z. This will influence some of the following comments.
In order to keep it in v2 we need to make it backwards compatible. Providing a default value for layout in case the project file doesn't have it has already be done for the version field, that defaults to v1 at read time as v1 projects didn't have that field. In this case it will only be needed to set the layout field to the default go plugin when reading a config file that has version: "2" but no layout field.
cmd/edit.go
Outdated
|
|
||
| func (o *editOptions) Validate(c *config.Config) error { | ||
| if !c.IsV2() { | ||
| if c.IsV1() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(Remember I consider we should not use v3-alpha)
Right now they are functionally equivalents but they have different semantics. !c.IsV2() makes no assumption about how following versions will work while c.IsV1() makes the sumption that following versions will implement the multi-group flag.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change is more for convenience, but I'll explicitly check v2 and v3 if we decide to stick with v3.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ditto https://github.com/kubernetes-sigs/kubebuilder/pull/1403/files#r387589683
I do not think that we should add V3 as well.
internal/config/config.go
Outdated
|
|
||
| // Default version if flag not provided | ||
| DefaultVersion = config.Version2 | ||
| DefaultVersion = config.Version3 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(Remember I consider we should not use v3-alpha)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ditto https://github.com/kubernetes-sigs/kubebuilder/pull/1403/files#r387589683
I do not think that we should add V3 as well.
pkg/cli/cli.go
Outdated
| pluginsFromOptions: map[string][]plugin.Base{}, | ||
| cliPluginKeys: map[string]string{}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that linters prefer the following:
| pluginsFromOptions: map[string][]plugin.Base{}, | |
| cliPluginKeys: map[string]string{}, | |
| pluginsFromOptions: make(map[string][]plugin.Base), | |
| cliPluginKeys: make(map[string]string), |
pkg/plugin/v2/init.go
Outdated
| // Only V3 projects get a layout. | ||
| if p.config.IsV3() { | ||
| // Init plugins set the config layout. | ||
| p.config.Layout = plugin.Key(pluginName, pluginVersion) | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(Remember I consider we should not use v3-alpha)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ditto https://github.com/kubernetes-sigs/kubebuilder/pull/1403/files#r387589683
I do not think that we should add V3 as well.
pkg/plugin/v2/plugin.go
Outdated
| pluginVersion = "v2.0.0" | ||
| ) | ||
|
|
||
| var supportedProjectVersions = []string{"2", "3-alpha"} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(Remember I consider we should not use v3-alpha)
|
I'm fine with keeping config version @DirectXMan12 @mengqiy @joelanford thoughts on changing config version to |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some additional questions and thoughts
f7d3815 to
75e1ce8
Compare
8a654d2 to
23415cf
Compare
layout and plugin name validationlayout, --plugins flag, and plugin name validation
layout, --plugins flag, and plugin name validationlayout, --plugins flag, and plugin name validation
234e8ad to
1151b04
Compare
layout, --plugins flag, and plugin name validationlayout, --plugins flag, and plugin name validation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is not againt the master so:
/lgtm
/approve
We will come back to re-check all plugin impl in the PR against master which will be easier to verify all.
|
/assign @mengqiy |
|
/approve |
|
/approve |
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: camilamacedo86, estroz 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 |
da1069b to
2a165d8
Compare
2a165d8 to
6997218
Compare
|
Hi @estroz, It is not passing now, after the rebase, in the testdata check. You need run |
should run for a subcommand. This option is global. Refactoring of
getBaseFlags -> parseBaseFlags allows multiple global flags to be
parsed for a cli struct. plugin filtering considers short names,
ex. --plugins="go" rather than --plugins="go.kubebuilder.io/v2.0.0".
WithDefaultPlugins sets the default plugins a CLi should use in case
--plugins or the config 'layout' are not set
pkg/model/config: Config support the 'layout' key which indicates the
plugin that scaffolded a project, by plugin key
pkg/plugin: SplitKey, KeyFor, Key, GetShortName are utility functions
for plugin keys
* pkg/{cli,plugin}: add plugin name validation
* pkg/plugin/{v1,v2}: set layout key in config
Please enter the commit message for your changes. Lines starting
6997218 to
f460cc7
Compare
|
Hi @estroz, The GH did not get the Travis result. If you close and re-open this one the tests will be re-trigged. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As we spoke:
/lgtm
Since it is to merge in the kubernetes-sigs:feature/plugins-part-2-electric-boogaloo and not master.
And then we can check the tests in a follow-up pr.
505e23d
into
kubernetes-sigs:feature/plugins-part-2-electric-boogaloo
|
|
||
| ```yaml | ||
| version: "3-alpha" | ||
| version: "2" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
??
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@DirectXMan12
I understand that the version here will still be 2 since we have not broken changes in the layout. However, kb tag will need to be bumped to 3.0.0. Am I right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was pushback against upgrading to "3-alpha". Regardless of whether we bump I figured it was better to make the change in a follow-up.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that's ok, but I think if we're gonna make a field mandatory that's a change in version.
| func (c *cli) initialize() error { | ||
| // Initialize cli with globally-relevant flags or flags that determine | ||
| // certain plugin type's configuration. | ||
| if err := c.parseBaseFlags(); err != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why do we need this globally? isn't this just needed on the init invocation?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The CLI needs to pre-parse the --plugins global flag for each command, so I figured wrapping all flag pre-parsing in one method made sense. The cli.doGenericHelp flag is set by cli.parseBaseFlags so init can still print generic help if --project-version is not set.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The CLI needs to pre-parse the --plugins global flag for each command,
wait, does it? I thought we figured out that it didn't...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Summary of discussion: having a global --plugins flag is not in scope for phase 1 since the type of plugin used in init solely determines what plugin is used for subsequent commands (the layout config key). A global --plugins flag will be discussed in phase 2: #1378.
| case len(c.cliPluginKeys) != 0: | ||
| // Filter plugins by keys passed in CLI. | ||
| filterKeys = c.cliPluginKeys | ||
| case c.configured && !projectConfig.IsV1(): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
doesn't this break current v2 projects?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It will, and probably a good reason to upgrade to project version "3-alpha".
| if err != nil { | ||
| return err | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what happens if filterKeys is not set here? (i.e. if there's no plugins set for options)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(if we check elsewhere, add a comment here)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(it's also maybe a good indication that we're failing at the principle of "parse instead of validate")
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cli.resolvedPlugins defaults to the default plugins for a project version if filterKeys is empty. Default plugins are ensured to exist by validating them here. Does this still fail parse instead of validate")? I'll add a comment describing this scenario if not.
Looks like the case when c.configured && projectConfig.IsV1() == true is not validated however. Making a follow-up now.
Description of Change:
--pluginsallows a binary invoker to select which plugins known to aCLIto run; this flag can be set with a shortened (non-fully-qualified) name. Either a plugin name passed to--pluginsor the name set in an initialized project's config layout, in order of precedence, is resolved to a known plugin.layoutkey, containing theInitplugin key that scaffolded a projectlayoutkey in configMotivation for Change: finishes up phase 1 of plugin implementation. The
layoutkey determines which plugin (name and version) initialized a project, useful for a plugin implementation to deduce which post-init plugins should be called.--plugins/layout, in combination with a default plugin, are necessary to select which plugin to use if there are multiple viable plugins per project version.TODO:
*Gettertype, infer by config layout or default (in the case ofInit)pkg/cli/cc @Adirio @hasbro17 @camilamacedo86
/kind feature