From f9139fa24b22060b5cc1fa117433028c4a2b2095 Mon Sep 17 00:00:00 2001 From: Chmouel Boudjnah Date: Thu, 21 Mar 2024 13:32:27 +0100 Subject: [PATCH] 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. --- pkg/kubeinteraction/cleanups.go | 6 ++++-- pkg/kubeinteraction/cleanups_test.go | 1 + pkg/reconciler/cleanup_test.go | 1 + 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/pkg/kubeinteraction/cleanups.go b/pkg/kubeinteraction/cleanups.go index 9b757b3f1..8797d485a 100644 --- a/pkg/kubeinteraction/cleanups.go +++ b/pkg/kubeinteraction/cleanups.go @@ -20,8 +20,10 @@ func (k Interaction) CleanupPipelines(ctx context.Context, logger *zap.SugaredLo } // Select PR by repository and by its true pipelineRun name (not auto generated one) - labelSelector := fmt.Sprintf("%s=%s,%s=%s", - keys.Repository, formatting.CleanValueKubernetes(repo.GetName()), keys.OriginalPRName, formatting.CleanValueKubernetes(pr.GetLabels()[keys.OriginalPRName])) + labelSelector := fmt.Sprintf("%s=%s,%s=%s,%s=%s", + keys.Repository, formatting.CleanValueKubernetes(repo.GetName()), keys.OriginalPRName, + formatting.CleanValueKubernetes(pr.GetLabels()[keys.OriginalPRName]), + keys.State, StateCompleted) logger.Infof("selecting pipelineruns by labels \"%s\" for deletion", labelSelector) pruns, err := k.Run.Clients.Tekton.TektonV1().PipelineRuns(repo.GetNamespace()).List(ctx, diff --git a/pkg/kubeinteraction/cleanups_test.go b/pkg/kubeinteraction/cleanups_test.go index 0aa080ea6..04d40779a 100644 --- a/pkg/kubeinteraction/cleanups_test.go +++ b/pkg/kubeinteraction/cleanups_test.go @@ -27,6 +27,7 @@ func TestCleanupPipelines(t *testing.T) { cleanupLabels := map[string]string{ keys.OriginalPRName: cleanupPRName, keys.Repository: cleanupRepoName, + keys.State: StateCompleted, } // copy of cleanupLabels to be used in annotations cleanupAnnotations := maps.Clone(cleanupLabels) diff --git a/pkg/reconciler/cleanup_test.go b/pkg/reconciler/cleanup_test.go index a137ed2b9..340c4d30d 100644 --- a/pkg/reconciler/cleanup_test.go +++ b/pkg/reconciler/cleanup_test.go @@ -30,6 +30,7 @@ func TestCleanupPipelineRuns(t *testing.T) { cleanupLabels := map[string]string{ keys.OriginalPRName: cleanupPRName, keys.Repository: cleanupRepoName, + keys.State: kubeinteraction.StateCompleted, } cleanupAnnotation := map[string]string{