-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Conversation
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? |
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. |
Would worth mentioning in https://github.com/kubernetes/test-infra/blob/master/prow/ANNOUNCEMENTS.md as well I think |
1d4f82d
to
053c16c
Compare
Sorry overlooked this comment last time. This looks exactly like what's in my mind! |
62c1c75
to
263dae3
Compare
prow/plugins/config.go
Outdated
@@ -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...) |
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 am not sure orgExceptions
is the right way to go... do you have an idea @alvaroaleman ?
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.
My feeling is that this is very explicit, like orgA/repoB
, so a slice of repos should do?
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 am just trying to integrate with the existing mechanisms
@chaodaiG PTAL |
prow/plugins/config_test.go
Outdated
} | ||
testCases := []struct { | ||
name string | ||
orgs []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.
nit: rename the wanted output to make tests better readable, such as:
name string
wantOrgs []string
wantRepos []string
wantExcludedRepos map[string]sets.String
prow/plugins/config.go
Outdated
return newPlugins | ||
} | ||
|
||
func ToRawMessage(plugins interface{}) json.RawMessage { |
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.
Is this used?
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.
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
prow/plugins/config.go
Outdated
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") |
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 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
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 see, but then what do I do with this error in the caller side?
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 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
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 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?
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.
Ok, I will do like ConfigUpdater
and redefine my own unmarshall method...
prow/plugins/config.go
Outdated
} | ||
} | ||
} | ||
// if org/repo has explicitly plugin enabled, remove its exception |
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 is slightly confusing, I guess you meant:
- orgA
plugins:
- common
excluded:
- repoB
- orgA/repoB
plugins:
- common
We might need more comments 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.
yes that's what I meant, alright will rephrase
prow/plugins/config.go
Outdated
@@ -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...) |
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.
My feeling is that this is very explicit, like orgA/repoB
, so a slice of repos should do?
prow/plugins/plugins.go
Outdated
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...) |
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.
Shouldn't we process excluded repos 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.
yes
/cc @alvaroaleman |
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.
Overall looks awesome to me. Left one last nit
/hold
In case you want to address
prow/plugins/plugins_test.go
Outdated
pa := ConfigAgent{configuration: &Configuration{Plugins: OldToNewPlugins(tc.pluginMap)}} | ||
|
||
plugins := pa.getPlugins(tc.owner, tc.repo) | ||
if len(plugins) != len(tc.expectedPlugins) { |
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.
Is it possible to use cmp.Diff instead? Same below
Squashed commits as well. Thanks for your help! |
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.
Looks awesome! Thank you for the contribution!
@michelle192837 and @alvaroaleman for awareness
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.
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
prow/plugins/config_test.go
Outdated
- pluginOnlyForRepoB | ||
`) | ||
var p Plugins | ||
err := yaml.Unmarshal(badPluginsYaml, &p) |
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.
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
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.
Sorry, fixed!
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.
Thank you!
[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 |
/unhold |
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 😂 |
What documentation am I supposed to follow to do this migration? |
This is somewhat unhelpful:
|
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. |
Fixes #20631
/cc @chaodaiG