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

Add support of excluded_repos for plugins #20707

Merged
merged 1 commit into from
Feb 23, 2021

Conversation

matthyx
Copy link
Contributor

@matthyx matthyx commented Feb 2, 2021

Fixes #20631
/cc @chaodaiG

@k8s-ci-robot k8s-ci-robot added do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. area/prow Issues or PRs related to prow area/prow/plugins Issues or PRs related to prow's plugins for the hook component sig/testing Categorizes an issue or PR as relevant to SIG Testing. labels Feb 2, 2021
@matthyx
Copy link
Contributor Author

matthyx commented Feb 2, 2021

I need to add test cases for the new format, and fix some CI checks, but could you check already if that would do it?

@matthyx
Copy link
Contributor Author

matthyx commented Feb 2, 2021

This is the first PR where I need to support both old and new config styles... after some time we can simplify it by ditching the old format.

@chaodaiG
Copy link
Contributor

chaodaiG commented Feb 2, 2021

Would worth mentioning in https://github.com/kubernetes/test-infra/blob/master/prow/ANNOUNCEMENTS.md as well I think

@matthyx matthyx force-pushed the 20631 branch 2 times, most recently from 1d4f82d to 053c16c Compare February 4, 2021 10:57
@k8s-ci-robot k8s-ci-robot added 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. labels Feb 4, 2021
@chaodaiG
Copy link
Contributor

chaodaiG commented Feb 4, 2021

I need to add test cases for the new format, and fix some CI checks, but could you check already if that would do it?

Sorry overlooked this comment last time. This looks exactly like what's in my mind!

@k8s-ci-robot k8s-ci-robot added area/prow/deck Issues or PRs related to prow's deck component area/prow/hook Issues or PRs related to prow's hook component labels Feb 5, 2021
@@ -817,9 +853,15 @@ func (c *Configuration) EnabledReposForPlugin(plugin string) (orgs, repos []stri
repos = append(repos, repo)
} else {
orgs = append(orgs, repo)
orgExceptions[repo] = sets.NewString(plugins.ExcludedRepos...)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I am not sure orgExceptions is the right way to go... do you have an idea @alvaroaleman ?

Copy link
Contributor

Choose a reason for hiding this comment

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

My feeling is that this is very explicit, like orgA/repoB, so a slice of repos should do?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I am just trying to integrate with the existing mechanisms

@matthyx matthyx changed the title WIP - Add support of excluded_repos for plugins Add support of excluded_repos for plugins Feb 17, 2021
@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 Feb 17, 2021
@matthyx
Copy link
Contributor Author

matthyx commented Feb 17, 2021

@chaodaiG PTAL

}
testCases := []struct {
name string
orgs []string
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: rename the wanted output to make tests better readable, such as:

name string
wantOrgs []string
wantRepos []string
wantExcludedRepos map[string]sets.String

return newPlugins
}

func ToRawMessage(plugins interface{}) json.RawMessage {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this used?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes in all tests, as during the migration time we need to use a json.RawMessage to allow deserialization with our own code until we completely switch to the new form

if err := yaml.Unmarshal(c.PluginsRaw, &oldPlugins); err != nil {
var newPlugins map[string]OrgPlugins
if err := yaml.Unmarshal(c.PluginsRaw, &newPlugins); err != nil {
logrus.WithError(err).Error("error unmarshalling Plugins config to oldPlugins and newPlugins formats")
Copy link
Contributor

@chaodaiG chaodaiG Feb 17, 2021

Choose a reason for hiding this comment

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

I feel that we might want to return an error here, if we can't unmarshal plugins config then hook is almost not functioning.

Also a nit, you can return earlier to avoid nested if else loop. for example:

if err := yaml.Unmarshal(c.PluginsRaw, &oldPlugins); err == nil {
  logrus.Warn("plugins declaration uses a deprecated config style, please migrate it")
  return oldToNewPlugins(oldPlugins), nil
}
var newPlugins map[string]OrgPlugins
err := yaml.Unmarshal(c.PluginsRaw, &newPlugins)
return newPlugins, err

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I see, but then what do I do with this error in the caller side?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think checkconfig need to catch this error and not letting the change go through. And for hook I would prefer to let it crash, with an error message asking for running checkconfig

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This custom unmarshaling is just for the transition period, to let people migrate from old to new format... otherwise such error is thrown when the yaml file is parsed, so maybe I should validate at that very beginning and not every time I need to access plugins?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, I will do like ConfigUpdater and redefine my own unmarshall method...

}
}
}
// if org/repo has explicitly plugin enabled, remove its exception
Copy link
Contributor

Choose a reason for hiding this comment

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

This is slightly confusing, I guess you meant:

- orgA
  plugins:
  - common
  excluded:
  - repoB
- orgA/repoB
  plugins:
  - common

We might need more comments here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes that's what I meant, alright will rephrase

@@ -817,9 +853,15 @@ func (c *Configuration) EnabledReposForPlugin(plugin string) (orgs, repos []stri
repos = append(repos, repo)
} else {
orgs = append(orgs, repo)
orgExceptions[repo] = sets.NewString(plugins.ExcludedRepos...)
Copy link
Contributor

Choose a reason for hiding this comment

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

My feeling is that this is very explicit, like orgA/repoB, so a slice of repos should do?

plugins = append(plugins, pa.configuration.Plugins[owner]...)
plugins = append(plugins, pa.configuration.Plugins[fullName]...)
plugins = append(plugins, pa.configuration.Plugins()[owner].Plugins...)
plugins = append(plugins, pa.configuration.Plugins()[fullName].Plugins...)
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't we process excluded repos here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes

@chaodaiG
Copy link
Contributor

/cc @alvaroaleman

Copy link
Contributor

@chaodaiG chaodaiG 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 awesome to me. Left one last nit

/hold
In case you want to address

pa := ConfigAgent{configuration: &Configuration{Plugins: OldToNewPlugins(tc.pluginMap)}}

plugins := pa.getPlugins(tc.owner, tc.repo)
if len(plugins) != len(tc.expectedPlugins) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it possible to use cmp.Diff instead? Same below

@k8s-ci-robot k8s-ci-robot added do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. lgtm "Looks good to me", indicates that a PR is ready to be merged. approved Indicates a PR has been approved by an approver from all required OWNERS files. labels Feb 19, 2021
@k8s-ci-robot k8s-ci-robot removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Feb 19, 2021
@matthyx
Copy link
Contributor Author

matthyx commented Feb 19, 2021

In case you want to address

Squashed commits as well. Thanks for your help!

Copy link
Contributor

@chaodaiG chaodaiG left a comment

Choose a reason for hiding this comment

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

Looks awesome! Thank you for the contribution!

@michelle192837 and @alvaroaleman for awareness

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Feb 19, 2021
Copy link
Contributor

@chaodaiG chaodaiG left a comment

Choose a reason for hiding this comment

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

Just noticed that there is still a hold on the PR, left a comment. No big deal, so please feel free address it in current PR or in future PR

- pluginOnlyForRepoB
`)
var p Plugins
err := yaml.Unmarshal(badPluginsYaml, &p)
Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry I must haven't got enough coffee for the morning, didn't notice this test didn't use UnmarshalJSON method. Please modify the test to use it

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry, fixed!

@k8s-ci-robot k8s-ci-robot removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Feb 22, 2021
Copy link
Contributor

@chaodaiG chaodaiG left a comment

Choose a reason for hiding this comment

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

Thank you!

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Feb 22, 2021
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: chaodaiG, matthyx

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

@chaodaiG
Copy link
Contributor

/unhold

@k8s-ci-robot k8s-ci-robot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Feb 23, 2021
@k8s-ci-robot k8s-ci-robot merged commit ad856c1 into kubernetes:master Feb 23, 2021
@k8s-ci-robot k8s-ci-robot added this to the v1.21 milestone Feb 23, 2021
@cjwagner
Copy link
Member

This is handy, thanks Matthias!

@matthyx
Copy link
Contributor Author

matthyx commented Feb 26, 2021

This is handy, thanks Matthias!

Now I will rework my never ending contribution for config trees... I'm almost sure by the time I get it merged go will support generics 😂

@fejta
Copy link
Contributor

fejta commented Feb 26, 2021

What documentation am I supposed to follow to do this migration?

@fejta
Copy link
Contributor

fejta commented Feb 26, 2021

This is somewhat unhelpful:

msg: "plugins declaration uses a deprecated config style, please migrate it"
file: "prow/plugins/config.go:843"

@fejta
Copy link
Contributor

fejta commented Feb 26, 2021

Also can you please update this logging to only say this once per process and/or once per hour? Right now this is the only thing visible in our logs.

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. area/prow/deck Issues or PRs related to prow's deck component area/prow/hook Issues or PRs related to prow's hook component area/prow/plugins Issues or PRs related to prow's plugins for the hook component area/prow Issues or PRs related to prow cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. sig/testing Categorizes an issue or PR as relevant to SIG Testing. 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.

Consider supporting ExcludedRepos for plugins
5 participants