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

✨ pass config between KB and external plugin #3526

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Eileen-Yu
Copy link
Member

@Eileen-Yu Eileen-Yu commented Aug 7, 2023

Description:

Todo:

  • Add new specs Config in both the PluginRequest and PluginResponse
  • Create a local type definition in the sampleexternalplugin path for easier testing
  • Inject the config in PluginRequest and pass it to the external plugin
  • Update the config on the sample external plugin side, send the updated config back via response
  • Enable KB to update the config based on the modified the config passed back from PluginResponse
  • Add e2e tests
  • Remove the replace once the PR gets merged (next PR)

Sample PROJECT updated by go sample external plugin:

Motivation:

Aims to fix the issue #3396

@k8s-ci-robot
Copy link
Contributor

Skipping CI for Draft Pull Request.
If you want CI signal for your change, please convert it to an actual PR.
You can still manually trigger a test run with /test all

@k8s-ci-robot k8s-ci-robot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Aug 7, 2023
@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Aug 7, 2023
func (p *initSubcommand) InjectConfig(c config.Config) error {
p.config = c
return nil
}
Copy link
Member

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

@k8s-ci-robot k8s-ci-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Aug 10, 2023
@k8s-ci-robot k8s-ci-robot added size/S Denotes a PR that changes 10-29 lines, ignoring generated files. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Aug 10, 2023
@Eileen-Yu Eileen-Yu changed the title ✨ pass config between KB and external plugin ✨ [WIP] pass config between KB and external plugin Aug 11, 2023
@Eileen-Yu Eileen-Yu force-pushed the feat/ep-with-PROJECT branch 2 times, most recently from 8fac0bf to b5a1d16 Compare August 15, 2023 03:32
@Eileen-Yu Eileen-Yu marked this pull request as ready for review August 15, 2023 03:35
@k8s-ci-robot k8s-ci-robot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Aug 15, 2023
@Eileen-Yu Eileen-Yu changed the title ✨ [WIP] pass config between KB and external plugin ✨ pass config between KB and external plugin Aug 15, 2023
@@ -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"`
Copy link
Contributor

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?

Copy link
Member Author

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:

  1. 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.

  2. 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?

Copy link
Contributor

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?

Copy link
Contributor

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?)

Copy link
Member

Choose a reason for hiding this comment

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

@Eileen-Yu

Here, I think, should be config.Config

Copy link
Contributor

@Kavinjsir Kavinjsir left a 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.

@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Sep 13, 2023
@k8s-ci-robot k8s-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Nov 15, 2023
@k8s-ci-robot
Copy link
Contributor

@Eileen-Yu: The specified target(s) for /test were not found.
The following commands are available to trigger required jobs:

  • /test pull-kubebuilder-e2e-k8s-1-26-6
  • /test pull-kubebuilder-e2e-k8s-1-27-3
  • /test pull-kubebuilder-e2e-k8s-1-28-0
  • /test pull-kubebuilder-test

Use /test all to run all jobs.

In response to this:

/test pull-kubebuilder-e2e-k8s-1-26-1

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
Copy link
Member Author

/test pull-kubebuilder-e2e-k8s-1-26-6

@Eileen-Yu
Copy link
Member Author

/test pull-kubebuilder-e2e-k8s-1-28-0

Copy link
Member

@camilamacedo86 camilamacedo86 left a comment

Choose a reason for hiding this comment

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

@Eileen-Yu

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

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: Eileen-Yu, Kavinjsir
Once this PR has been reviewed and has the lgtm label, please assign varshaprasad96 for approval. For more information see the Kubernetes Code Review Process.

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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. and removed approved Indicates a PR has been approved by an approver from all required OWNERS files. labels Feb 6, 2024
@k8s-ci-robot k8s-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Feb 13, 2024
@Eileen-Yu
Copy link
Member Author

Eileen-Yu commented Feb 13, 2024

Tried to update it with the suggestions.. Is this what we're looking for?

Guess I meet with the similar blocker when I did this last time: the project version would somehow be 0 (but by default it should be 3, and it did show as 3 in the scaffolded PROJECT, but if print it in the middle it's actually 0... not quite sure what caused this), and PROECT content failed to update with new fields... but these issues wouldn't happen when req/res.Config is set to string.

Screenshot 2024-02-13 at 12 25 35 AM

Not sure if there's any unexpected issues in between 🤔

@@ -40,16 +43,28 @@ func (p *initSubcommand) BindFlags(fs *pflag.FlagSet) {
}

func (p *initSubcommand) Scaffold(fs machinery.Filesystem) error {
cfg := p.config.(*v3cfg.Cfg)
Copy link
Member

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:

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:

kubebuilder/pkg/cli/cli.go

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())
}

@camilamacedo86
Copy link
Member

camilamacedo86 commented Feb 13, 2024

Hi @Eileen-Yu

Thank you for coming back on this one. it would be very nice if we could achieve it.
Your help here is very appreciated.

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)

if err != nil {
return err
}
defer file.Close()
Copy link
Member

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

Copy link
Member

@camilamacedo86 camilamacedo86 left a comment

Choose a reason for hiding this comment

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

@Eileen-Yu

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

@Eileen-Yu
Copy link
Member Author

Hi @camilamacedo86 , thx for the help!

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

I did all of the above lists.

And yes, I did see the unit tests still failed because of this version error:

 msg: "unable to create config for version \"0\": version 0 is not supported",
              err: <config.UnsupportedVersionError>{
                  Version: {Number: 0, Stage: 0},

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) {
Copy link
Member

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.

@camilamacedo86
Copy link
Member

camilamacedo86 commented Feb 15, 2024

Hi @Eileen-Yu

Regards: #3526 (comment)
thank you a lot
I do not have this weekend to check it out.
But up the following one, I will run it locally and see if I can fix the nit

@camilamacedo86 camilamacedo86 self-assigned this Feb 15, 2024
@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Apr 3, 2024
@k8s-ci-robot
Copy link
Contributor

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.

@k8s-ci-robot
Copy link
Contributor

@Eileen-Yu: The following tests failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
pull-kubebuilder-e2e-k8s-1-28-6 924daa7 link true /test pull-kubebuilder-e2e-k8s-1-28-6
pull-kubebuilder-e2e-k8s-1-27-10 924daa7 link true /test pull-kubebuilder-e2e-k8s-1-27-10
pull-kubebuilder-e2e-k8s-1-29-0 924daa7 link true /test pull-kubebuilder-e2e-k8s-1-29-0
pull-kubebuilder-test 65ae4a3 link true /test pull-kubebuilder-test
pull-kubebuilder-e2e-k8s-1-27-3 65ae4a3 link true /test pull-kubebuilder-e2e-k8s-1-27-3
pull-kubebuilder-e2e-k8s-1-26-6 65ae4a3 link true /test pull-kubebuilder-e2e-k8s-1-26-6
pull-kubebuilder-e2e-k8s-1-28-0 65ae4a3 link true /test pull-kubebuilder-e2e-k8s-1-28-0
pull-kubebuilder-e2e-k8s-1-29-2 65ae4a3 link true /test pull-kubebuilder-e2e-k8s-1-29-2
pull-kubebuilder-e2e-k8s-1-27-11 65ae4a3 link true /test pull-kubebuilder-e2e-k8s-1-27-11
pull-kubebuilder-e2e-k8s-1-28-7 65ae4a3 link true /test pull-kubebuilder-e2e-k8s-1-28-7
pull-kubebuilder-e2e-k8s-1-30-0 65ae4a3 link true /test pull-kubebuilder-e2e-k8s-1-30-0

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.

@camilamacedo86 camilamacedo86 added the help wanted Denotes an issue that needs help from a contributor. Must meet "help wanted" guidelines. label May 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. help wanted Denotes an issue that needs help from a contributor. Must meet "help wanted" guidelines. needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. 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.

None yet

5 participants