Skip to content

Commit

Permalink
Fix single override creates many ProwJobs in the system
Browse files Browse the repository at this point in the history
This commit addresses the problem described in kubernetes#22690. Override once issued,
can spawn many the almost same prowjobs. The root cause of the problem takes
the origin in the statuses returned by GitHub API. There are multiple statuses
with the same context which reflects the history of the job. One repetition of
context handling for override is enough, rest of the statuses can be ignored.
This commit also adjusts unit tests to the real situation, removing maps as
overlapping statuses are possible.

Signed-off-by: Jakub Guzik <jguzik@redhat.com>
  • Loading branch information
jmguzik committed Nov 23, 2021
1 parent 261259c commit 7a5643d
Show file tree
Hide file tree
Showing 2 changed files with 188 additions and 133 deletions.
6 changes: 4 additions & 2 deletions prow/plugins/override/override.go
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,7 @@ Only the following contexts were expected:
}

done := sets.String{}
contextsWithCreatedJobs := sets.String{}

defer func() {
if len(done) == 0 {
Expand All @@ -405,8 +406,7 @@ Only the following contexts were expected:

for _, status := range statuses {
pre := presubmitForContext(presubmits, status.Context)

if status.State == github.StatusSuccess || !(overrides.Has(status.Context) || pre != nil && overrides.Has(pre.Name)) {
if status.State == github.StatusSuccess || !(overrides.Has(status.Context) || pre != nil && overrides.Has(pre.Name)) || contextsWithCreatedJobs.Has(status.Context) {
continue
}

Expand All @@ -428,12 +428,14 @@ Only the following contexts were expected:
Description: description(user),
URL: e.HTMLURL,
}

log.WithFields(pjutil.ProwJobFields(&pj)).Info("Creating a new prowjob.")
if _, err := oc.Create(context.TODO(), &pj, metav1.CreateOptions{}); err != nil {
resp := fmt.Sprintf("Failed to create override job for %s", status.Context)
log.WithError(err).Warn(resp)
return oc.CreateComment(org, repo, number, plugins.FormatResponseRaw(e.Body, e.HTMLURL, user, resp))
}
contextsWithCreatedJobs.Insert(status.Context)
}
status.State = github.StatusSuccess
status.Description = description(user)
Expand Down
Loading

0 comments on commit 7a5643d

Please sign in to comment.