Skip to content

Commit

Permalink
remove delete uncreated pipelineruns (#99)
Browse files Browse the repository at this point in the history
Co-authored-by: Richard Hagen <[email protected]>
  • Loading branch information
Richard87 and Richard87 authored Nov 28, 2023
1 parent e6f6e67 commit 48bde69
Showing 1 changed file with 2 additions and 22 deletions.
24 changes: 2 additions & 22 deletions pkg/pipeline/run_pipelines.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,7 @@ func (ctx *pipelineContext) RunPipelinesJob() error {
pipelineRunMap, err := ctx.runPipelines(pipelineList.Items, namespace)

if err != nil {
err = fmt.Errorf("failed to run pipelines: %w", err)
deleteErrors := ctx.deletePipelineRuns(pipelineRunMap, namespace)
if len(deleteErrors) > 0 {
deleteErrors = append(deleteErrors, err)
return commonErrors.Concat(deleteErrors)
}
return err
return fmt.Errorf("failed to run pipelines: %w", err)
}

err = ctx.WaitForCompletionOf(pipelineRunMap)
Expand All @@ -92,20 +86,6 @@ func (ctx *pipelineContext) getTargetEnvsAsString() string {
return strings.Join(envs, ", ")
}

func (ctx *pipelineContext) deletePipelineRuns(pipelineRunMap map[string]*pipelinev1.PipelineRun, namespace string) []error {
var deleteErrors []error
for _, pipelineRun := range pipelineRunMap {
log.Debugf("delete the pipeline-run %s", pipelineRun.Name)
deleteErr := ctx.tektonClient.TektonV1().PipelineRuns(namespace).
Delete(context.Background(), pipelineRun.GetName(), metav1.DeleteOptions{})
if deleteErr != nil {
log.Debugf("failed to delete the pipeline-run %s", pipelineRun.Name)
deleteErrors = append(deleteErrors, deleteErr)
}
}
return deleteErrors
}

func (ctx *pipelineContext) runPipelines(pipelines []pipelinev1.Pipeline, namespace string) (map[string]*pipelinev1.PipelineRun, error) {
timestamp := time.Now().Format("20060102150405")
pipelineRunMap := make(map[string]*pipelinev1.PipelineRun)
Expand Down Expand Up @@ -233,7 +213,7 @@ func (ctx *pipelineContext) WaitForCompletionOf(pipelineRuns map[string]*pipelin
return err
}
informer := genericInformer.Informer()
informer.AddEventHandler(cache.ResourceEventHandlerFuncs{
_, _ = informer.AddEventHandler(cache.ResourceEventHandlerFuncs{
UpdateFunc: func(old, cur interface{}) {
run, success := cur.(*pipelinev1.PipelineRun)
if !success {
Expand Down

0 comments on commit 48bde69

Please sign in to comment.