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

plugins: add sharding support for bugzilla #22427

Merged
merged 3 commits into from
Jun 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 60 additions & 2 deletions prow/plugins/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -1771,7 +1771,7 @@ type Override struct {

func (c *Configuration) mergeFrom(other *Configuration) error {
var errs []error
if diff := cmp.Diff(other, &Configuration{Plugins: other.Plugins}); diff != "" {
if diff := cmp.Diff(other, &Configuration{Plugins: other.Plugins, Bugzilla: other.Bugzilla}); diff != "" {
errs = append(errs, fmt.Errorf("supplemental plugin configuration has config that doesn't support merging: %s", diff))
}

Expand All @@ -1782,6 +1782,10 @@ func (c *Configuration) mergeFrom(other *Configuration) error {
errs = append(errs, fmt.Errorf("failed to merge .plugins from supplemental config: %w", err))
}

if err := c.Bugzilla.mergeFrom(&other.Bugzilla); err != nil {
errs = append(errs, fmt.Errorf("failed to merge .bugzilla from supplemental config: %w", err))
}

return utilerrors.NewAggregate(errs)
}

Expand All @@ -1806,8 +1810,53 @@ func (p *Plugins) mergeFrom(other *Plugins) error {
return utilerrors.NewAggregate(errs)
}

func (p *Bugzilla) mergeFrom(other *Bugzilla) error {
if other == nil {
return nil
}

var errs []error
if other.Default != nil {
if p.Default != nil {
errs = append(errs, errors.New("configuration of global default defined in multiple places"))
} else {
p.Default = other.Default
}
}
if len(other.Orgs) != 0 && p.Orgs == nil {
p.Orgs = make(map[string]BugzillaOrgOptions)
}
for org, orgConfig := range other.Orgs {
if _, ok := p.Orgs[org]; !ok {
p.Orgs[org] = BugzillaOrgOptions{}
}
if orgConfig.Default != nil {
if p.Orgs[org].Default != nil {
errs = append(errs, fmt.Errorf("found duplicate organization config for bugzilla.%s", org))
continue
}
newConfig := p.Orgs[org]
newConfig.Default = orgConfig.Default
p.Orgs[org] = newConfig
}
if len(orgConfig.Repos) != 0 && p.Orgs[org].Repos == nil {
newConfig := p.Orgs[org]
newConfig.Repos = make(map[string]BugzillaRepoOptions)
p.Orgs[org] = newConfig
}
for repo, repoConfig := range orgConfig.Repos {
if _, ok := p.Orgs[org].Repos[repo]; ok {
errs = append(errs, fmt.Errorf("found duplicate repository config for bugzilla.%s/%s", org, repo))
continue
}
p.Orgs[org].Repos[repo] = repoConfig
}
}
return utilerrors.NewAggregate(errs)
}

func (c *Configuration) HasConfigFor() (global bool, orgs sets.String, repos sets.String) {
AlexNPavel marked this conversation as resolved.
Show resolved Hide resolved
if !reflect.DeepEqual(c, &Configuration{Plugins: c.Plugins}) {
if !reflect.DeepEqual(c, &Configuration{Plugins: c.Plugins, Bugzilla: c.Bugzilla}) || c.Bugzilla.Default != nil {
global = true
}
orgs = sets.String{}
Expand All @@ -1820,5 +1869,14 @@ func (c *Configuration) HasConfigFor() (global bool, orgs sets.String, repos set
}
}

for org, orgConfig := range c.Bugzilla.Orgs {
if orgConfig.Default != nil {
orgs.Insert(org)
}
for repo := range orgConfig.Repos {
repos.Insert(org + "/" + repo)
}
}

return global, orgs, repos
}
Loading