From a2b1e2d79bf07f79757c6498d5b0df2110f4646d Mon Sep 17 00:00:00 2001 From: Khurram Baig Date: Mon, 21 Oct 2024 16:10:38 +0530 Subject: [PATCH] Storing PipelineRun and TaskRun deletion metadata Earlier, data coming during deletion like timestamp weren't stored. This PR fixes that. --- pkg/watcher/reconciler/pipelinerun/reconciler.go | 5 ++++- pkg/watcher/reconciler/taskrun/reconciler.go | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/pkg/watcher/reconciler/pipelinerun/reconciler.go b/pkg/watcher/reconciler/pipelinerun/reconciler.go index df8271567..0147e74d2 100644 --- a/pkg/watcher/reconciler/pipelinerun/reconciler.go +++ b/pkg/watcher/reconciler/pipelinerun/reconciler.go @@ -130,6 +130,9 @@ func isMarkedAsReadyForDeletion(taskRun *pipelinev1.TaskRun) bool { // that we see flowing through the system. If we don't add a finalizer, it could // get cleaned up before we see the final state and store it. func (r *Reconciler) FinalizeKind(ctx context.Context, pr *pipelinev1.PipelineRun) knativereconciler.Event { + // Reconcile the pipelinerun to ensure that it is stored in the database + rerr := r.ReconcileKind(ctx, pr) + // If logsClient isn't nil, it means we have logging storage enabled // and we can't use finalizers to coordinate deletion. if r.logsClient != nil { @@ -184,7 +187,7 @@ func (r *Reconciler) FinalizeKind(ctx context.Context, pr *pipelinev1.PipelineRu pr.Namespace, pr.Name, now.String(), storeDeadline.String(), requeueAfter.String()) return controller.NewRequeueAfter(requeueAfter) } - if stored != "true" { + if rerr != nil || stored != "true" { logging.FromContext(ctx).Debugf("stored annotation is not true on pipelinerun %s/%s, now: %s, storeDeadline: %s, requeueAfter: %s", pr.Namespace, pr.Name, now.String(), storeDeadline.String(), requeueAfter.String()) return controller.NewRequeueAfter(requeueAfter) diff --git a/pkg/watcher/reconciler/taskrun/reconciler.go b/pkg/watcher/reconciler/taskrun/reconciler.go index 4eea594e0..5cf818506 100644 --- a/pkg/watcher/reconciler/taskrun/reconciler.go +++ b/pkg/watcher/reconciler/taskrun/reconciler.go @@ -64,6 +64,9 @@ func (r *Reconciler) ReconcileKind(ctx context.Context, tr *pipelinev1.TaskRun) // that we see flowing through the system. If we don't add a finalizer, it could // get cleaned up before we see the final state and store it. func (r *Reconciler) FinalizeKind(ctx context.Context, tr *pipelinev1.TaskRun) knativereconciler.Event { + // Reconcile the taskrun to ensure that it is stored in the database + rerr := r.ReconcileKind(ctx, tr) + // If logsClient isn't nil, it means we have logging storage enabled // and we can't use finalizers to coordinate deletion. if r.logsClient != nil { @@ -134,7 +137,7 @@ func (r *Reconciler) FinalizeKind(ctx context.Context, tr *pipelinev1.TaskRun) k tr.Namespace, tr.Name, now.String(), storeDeadline.String(), requeueAfter.String()) return controller.NewRequeueAfter(requeueAfter) } - if stored != "true" { + if rerr != nil || stored != "true" { logging.FromContext(ctx).Debugf("stored annotation is not true on taskrun %s/%s, now: %s, storeDeadline: %s", tr.Namespace, tr.Name, now.String(), storeDeadline.String()) return controller.NewRequeueAfter(requeueAfter)