Skip to content

Commit 744fa89

Browse files
committed
Only cleanups PRs after reconciliation
I experienced some issues where the watcher was getting stuck when there is a race between the deletion of the PR and the reconciliation. The high load would make it slow to know which PR to get deleted, and the reconciliation would be stuck trying to reconcile on a deleted PR. Stress tested this over 150 concurrent PR of 3 PipelineRuns with a concurrency of 1 and a max-keep-runs of 1 for each pipelinerun and the Q processed properly until the end all PipelineRuns without getting stuck (like it was before the change).
1 parent f08a73c commit 744fa89

File tree

2 files changed

+7
-8
lines changed

2 files changed

+7
-8
lines changed

pkg/kubeinteraction/cleanups.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ func (k Interaction) CleanupPipelines(ctx context.Context, logger *zap.SugaredLo
3333
for c, prun := range psort.PipelineRunSortByCompletionTime(pruns.Items) {
3434
prReason := prun.GetStatusCondition().GetCondition(apis.ConditionSucceeded).GetReason()
3535
if prReason == tektonv1.PipelineRunReasonRunning.String() || prReason == tektonv1.PipelineRunReasonPending.String() {
36-
logger.Infof("skipping cleaning PipelineRun %s since the conditions.reason is %s", prReason, prun.GetName())
36+
logger.Infof("skipping cleaning PipelineRun %s since the conditions.reason is %s", prun.GetName(), prReason)
3737
continue
3838
}
3939

pkg/reconciler/reconciler.go

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -156,10 +156,6 @@ func (r *Reconciler) reportFinalStatus(ctx context.Context, logger *zap.SugaredL
156156
return repo, fmt.Errorf("cannot set client: %w", err)
157157
}
158158

159-
if err := r.cleanupPipelineRuns(ctx, logger, repo, pr); err != nil {
160-
return repo, fmt.Errorf("cannot clean prs: %w", err)
161-
}
162-
163159
finalState := kubeinteraction.StateCompleted
164160
newPr, err := r.postFinalStatus(ctx, logger, provider, event, pr)
165161
if err != nil {
@@ -185,13 +181,16 @@ func (r *Reconciler) reportFinalStatus(ctx context.Context, logger *zap.SugaredL
185181
key := strings.Split(next, "/")
186182
pr, err := r.run.Clients.Tekton.TektonV1().PipelineRuns(key[0]).Get(ctx, key[1], metav1.GetOptions{})
187183
if err != nil {
188-
return repo, fmt.Errorf("cannot get pipeline: %w", err)
184+
return repo, fmt.Errorf("cannot get pipeline for next in queue: %w", err)
189185
}
190186

191187
if err := r.updatePipelineRunToInProgress(ctx, logger, repo, pr); err != nil {
192188
return repo, fmt.Errorf("failed to update status: %w", err)
193189
}
194-
return repo, nil
190+
}
191+
192+
if err := r.cleanupPipelineRuns(ctx, logger, repo, pr); err != nil {
193+
return repo, fmt.Errorf("error cleaning pipelineruns: %w", err)
195194
}
196195

197196
return repo, nil
@@ -276,7 +275,7 @@ func (r *Reconciler) updatePipelineRunState(ctx context.Context, logger *zap.Sug
276275
actionLog := state + " state"
277276
patchedPR, err := action.PatchPipelineRun(ctx, logger, actionLog, r.run.Clients.Tekton, pr, mergePatch)
278277
if err != nil {
279-
return pr, err
278+
return pr, fmt.Errorf("error patching the pipelinerun: %w", err)
280279
}
281280
return patchedPR, nil
282281
}

0 commit comments

Comments
 (0)