Skip to content

Commit

Permalink
Fix selecting non completed pipelineRun on cleanup
Browse files Browse the repository at this point in the history
We were selecting the pipelineRun that did not have the StateCompleted
label and this would seriously bug the concurrency manager.

This fixes it.
  • Loading branch information
chmouel committed Mar 21, 2024
1 parent 744fa89 commit f9139fa
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 2 deletions.
6 changes: 4 additions & 2 deletions pkg/kubeinteraction/cleanups.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions pkg/kubeinteraction/cleanups_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions pkg/reconciler/cleanup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down

0 comments on commit f9139fa

Please sign in to comment.