-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
✨ pass config between KB and external plugin #3526
base: master
Are you sure you want to change the base?
Conversation
Skipping CI for Draft Pull Request. |
func (p *initSubcommand) InjectConfig(c config.Config) error { | ||
p.config = c | ||
return 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.
However, to ensure that works could we add some tests to this one?
In the e2e test that we have now, could we not validate the config is filled and with the data that is expected?
Also, could we try to pass a value unto the config and see if that will be persisted in the PROJECT file?
See here how we update the config with the data to have it in tracked in the PROJECT file: https://github.com/kubernetes-sigs/kubebuilder/blob/master/pkg/plugins/golang/deploy-image/v1alpha1/api.go#L221-L247
Note that this code is reponsable for we track: https://github.com/kubernetes-sigs/kubebuilder/blob/master/testdata/project-v4-with-deploy-image/PROJECT#L8-L25
afbb077
to
d8df5ac
Compare
d8df5ac
to
18627f0
Compare
8fac0bf
to
b5a1d16
Compare
docs/book/src/simple-external-plugin-tutorial/testdata/sampleexternalplugin/v1/cmd/flags.go
Outdated
Show resolved
Hide resolved
docs/book/src/simple-external-plugin-tutorial/testdata/sampleexternalplugin/v1/cmd/metadata.go
Outdated
Show resolved
Hide resolved
.../book/src/simple-external-plugin-tutorial/testdata/sampleexternalplugin/v1/external/types.go
Outdated
Show resolved
Hide resolved
pkg/plugin/external/types.go
Outdated
@@ -35,6 +35,9 @@ type PluginRequest struct { | |||
// Universe represents the modified file contents that gets updated over a series of plugin runs | |||
// across the plugin chain. Initially, it starts out as empty. | |||
Universe map[string]string `json:"universe"` | |||
|
|||
// Config stores the project configuration file. | |||
Config string `json:"config"` |
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'm curious, why a string type? Do we have any other types we can use here to make it more explicit what the allowed content is?
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.
@camilamacedo86 Fix me if I'm missing something or understanding wrong:
-
I'm wondering if a literal string of the config content can help make it more general when parsing the data structure from different programs.
-
I'm also wondering how we'd like to define a data structure for config?
Shall we directly import the definition from v3/config?
One question here is what exactly content/message a general external plugin will use from the config?
How much do we allow the external plugin to modify the config?
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 biggest concern I have with a string literal of JSON is how do we perform validation on it? How do we ensure that the plugin isn't attempting to use configuration fields that don't exist or they have typos?
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'm wondering if we can have a number of clear criteria to help move on? More specifically, I'm curious if we can answer the following questions before implementation:
- What exactly data structure do we want to transfer for config? (Does it have to be a go struct? If yes, then what is the relationship between such with private
cfg
in config v2/v3?) - Is it necessary to define new methods for
Config
interface so as to help generate the data that might be transferred with the ep? - How does it affect PluginRequest and PluginResponse?
- What are the boundaries for an ep to touch with config? (Is the config read-only? OR what exactly fields an ep can and cannot touch with?)
- Is it necessary to ALWAYS pass the config to an EP? (Do we need to introduce a mechanism to make it optional?)
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.
Here, I think, should be config.Config
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.
Suggestion: can we hold the implementation until we come up with clear definitions / criteria.
e9fb09f
to
b8edf55
Compare
9c2f795
to
924daa7
Compare
@Eileen-Yu: The specified target(s) for
Use In response to this:
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. |
/test pull-kubebuilder-e2e-k8s-1-26-6 |
/test pull-kubebuilder-e2e-k8s-1-28-0 |
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 one I think is very close in this one
It seems for me that we here :
a) Change:
// Config stores the project configuration file.
Config string `json:"config"`
To use config.Config instead of string.
b) Ideally add a test.go for /pkg/plugin/external/types.go . See the other unit tests as example: https://github.com/kubernetes-sigs/kubebuilder/blob/924daa742ac59c9728572396658aaae3199b770f/pkg/config/store/errors_test.go
c) Here instead of re-create the implementation: https://github.com/kubernetes-sigs/kubebuilder/pull/3526/files#diff-e6ed63afd007e4f9eacc0376b867bef072ed4b39eb92cf3e9d683f6d87ffabcf we would use the struct that we have already so that we do not need to keep both places maintained. We can create the interface using the current struct
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: Eileen-Yu, Kavinjsir 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 |
924daa7
to
9ef48b9
Compare
pkg/plugins/external/init.go
Outdated
@@ -40,16 +43,28 @@ func (p *initSubcommand) BindFlags(fs *pflag.FlagSet) { | |||
} | |||
|
|||
func (p *initSubcommand) Scaffold(fs machinery.Filesystem) error { | |||
cfg := p.config.(*v3cfg.Cfg) |
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.
@Eileen-Yu should you not get the Config from the Project file here?
It will want the config empty when we want the config that exists already, right?
I am betting that is the reason you see config 0 instead of the data populated.
We need to do something like:
if err := config.LoadFrom(fmt.Sprintf("%s/%s", opts.InputDir, yaml.DefaultPath)); err != nil {
log.Fatalf("Failed to load PROJECT file %v", err)
As we do to re-scaffold:
kubebuilder/pkg/rescaffold/migrate.go
Lines 45 to 46 in 66c3572
if err := config.LoadFrom(fmt.Sprintf("%s/%s", opts.InputDir, yaml.DefaultPath)); err != nil { | |
log.Fatalf("Failed to load PROJECT file %v", err) |
OR something like we do here:
Lines 206 to 215 in 66c3572
// getInfoFromConfigFile obtains the project version and plugin keys from the project config file. | |
func (c *CLI) getInfoFromConfigFile() error { | |
// Read the project configuration file | |
cfg := yamlstore.New(c.fs) | |
if err := cfg.Load(); err != nil { | |
return err | |
} | |
return c.getInfoFromConfig(cfg.Config()) | |
} |
Hi @Eileen-Yu Thank you for coming back on this one. it would be very nice if we could achieve it. Regards: #3526 (comment) When you try to run the commands from the external plugin, you create the Config struct instead of loading it from the Project file. More info: #3526 (comment) |
pkg/plugins/external/init.go
Outdated
if err != nil { | ||
return err | ||
} | ||
defer file.Close() |
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.
@Eileen-Yu here we need to sort out the lint issue
We need to check the error
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.
Can you please:
a) squash the commits for we have just 1 here
b) fix the lint issue
c) rebase with master and push so that we can check it with the final state
Please, let us know if you are facing any issue that you need help with
a0ba688
to
65ae4a3
Compare
Hi @camilamacedo86 , thx for the help!
I did all of the above lists. And yes, I did see the unit tests still failed because of this version error:
I tried to fix this with this line: https://github.com/kubernetes-sigs/kubebuilder/pull/3526/files#diff-992e7a26b8776b12932c030601857ed56f364b1ecd7dc0fac9dcfd8c0cb903c6R66 but didn't get the luck 😔 |
@@ -40,16 +46,51 @@ func (p *initSubcommand) BindFlags(fs *pflag.FlagSet) { | |||
} | |||
|
|||
func (p *initSubcommand) Scaffold(fs machinery.Filesystem) error { | |||
fileName := "PROJECT" | |||
|
|||
if _, err := os.Stat(fileName); os.IsNotExist(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.
We should not create the file
We should fail in this case.
The CLI is who has the responsibility to create it.
the external plugin just read and update.
Hi @Eileen-Yu Regards: #3526 (comment) |
PR needs rebase. 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. |
@Eileen-Yu: The following tests failed, say
Full PR test history. Your PR dashboard. Please help us cut down on flakes by linking to an open issue when you hit one in your PR. 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-sigs/prow repository. I understand the commands that are listed here. |
Description:
Todo:
Config
in both thePluginRequest
andPluginResponse
PluginRequest
and pass it to the external pluginPluginResponse
replace
once the PR gets merged (next PR)Sample PROJECT updated by go sample external plugin:
Motivation:
Aims to fix the issue #3396