Skip to content

Commit f9139fa

Browse files
committed
Fix selecting non completed pipelineRun on cleanup
We were selecting the pipelineRun that did not have the StateCompleted label and this would seriously bug the concurrency manager. This fixes it.
1 parent 744fa89 commit f9139fa

File tree

3 files changed

+6
-2
lines changed

3 files changed

+6
-2
lines changed

pkg/kubeinteraction/cleanups.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,10 @@ func (k Interaction) CleanupPipelines(ctx context.Context, logger *zap.SugaredLo
2020
}
2121

2222
// Select PR by repository and by its true pipelineRun name (not auto generated one)
23-
labelSelector := fmt.Sprintf("%s=%s,%s=%s",
24-
keys.Repository, formatting.CleanValueKubernetes(repo.GetName()), keys.OriginalPRName, formatting.CleanValueKubernetes(pr.GetLabels()[keys.OriginalPRName]))
23+
labelSelector := fmt.Sprintf("%s=%s,%s=%s,%s=%s",
24+
keys.Repository, formatting.CleanValueKubernetes(repo.GetName()), keys.OriginalPRName,
25+
formatting.CleanValueKubernetes(pr.GetLabels()[keys.OriginalPRName]),
26+
keys.State, StateCompleted)
2527
logger.Infof("selecting pipelineruns by labels \"%s\" for deletion", labelSelector)
2628

2729
pruns, err := k.Run.Clients.Tekton.TektonV1().PipelineRuns(repo.GetNamespace()).List(ctx,

pkg/kubeinteraction/cleanups_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ func TestCleanupPipelines(t *testing.T) {
2727
cleanupLabels := map[string]string{
2828
keys.OriginalPRName: cleanupPRName,
2929
keys.Repository: cleanupRepoName,
30+
keys.State: StateCompleted,
3031
}
3132
// copy of cleanupLabels to be used in annotations
3233
cleanupAnnotations := maps.Clone(cleanupLabels)

pkg/reconciler/cleanup_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ func TestCleanupPipelineRuns(t *testing.T) {
3030
cleanupLabels := map[string]string{
3131
keys.OriginalPRName: cleanupPRName,
3232
keys.Repository: cleanupRepoName,
33+
keys.State: kubeinteraction.StateCompleted,
3334
}
3435

3536
cleanupAnnotation := map[string]string{

0 commit comments

Comments
 (0)