@@ -54,47 +54,73 @@ var (
54
54
func (r * Reconciler ) ReconcileKind (ctx context.Context , pr * tektonv1.PipelineRun ) pkgreconciler.Event {
55
55
ctx = info .StoreNS (ctx , system .Namespace ())
56
56
logger := logging .FromContext (ctx ).With ("namespace" , pr .GetNamespace ())
57
+
58
+ logger .Infof ("=== RECONCILE START: PipelineRun %s/%s (resourceVersion: %s) ===" , pr .GetNamespace (), pr .GetName (), pr .GetResourceVersion ())
59
+
57
60
// if pipelineRun is in completed or failed state then return
58
61
state , exist := pr .GetAnnotations ()[keys .State ]
62
+ logger .Infof ("RECONCILE: PipelineRun %s/%s - state='%s' (exists: %v), spec.status='%s'" , pr .GetNamespace (), pr .GetName (), state , exist , pr .Spec .Status )
63
+
59
64
if exist && (state == kubeinteraction .StateCompleted || state == kubeinteraction .StateFailed ) {
65
+ logger .Infof ("=== RECONCILE END: PipelineRun %s/%s - PATH: EARLY EXIT (final state) ===" , pr .GetNamespace (), pr .GetName ())
60
66
return nil
61
67
}
62
68
63
69
reason := ""
64
70
if len (pr .Status .GetConditions ()) > 0 {
65
71
reason = pr .Status .GetConditions ()[0 ].GetReason ()
72
+ logger .Infof ("RECONCILE: PipelineRun %s/%s current reason: '%s'" , pr .GetNamespace (), pr .GetName (), reason )
73
+ } else {
74
+ logger .Infof ("RECONCILE: PipelineRun %s/%s has no status conditions yet" , pr .GetNamespace (), pr .GetName ())
66
75
}
76
+
67
77
// This condition handles cases where the PipelineRun has entered a "Running" state,
68
78
// but its status in the Git provider remains "queued" (e.g., due to updates made by
69
79
// another controller outside PaC). To maintain consistency between the PipelineRun
70
80
// status and the Git provider status, we update both the PipelineRun resource and
71
81
// the corresponding status on the Git provider here.
82
+ logger .Infof ("RECONCILE: Checking condition - reason='%s' (is Running: %v), state='%s' (is queued: %v)" ,
83
+ reason , reason == string (tektonv1 .PipelineRunReasonRunning ), state , state == kubeinteraction .StateQueued )
84
+
72
85
if reason == string (tektonv1 .PipelineRunReasonRunning ) && state == kubeinteraction .StateQueued {
86
+ logger .Infof ("RECONCILE: PATH 1 - PipelineRun %s/%s condition met (reason=Running, state=queued), calling updatePipelineRunToInProgress" , pr .GetNamespace (), pr .GetName ())
73
87
repoName := pr .GetAnnotations ()[keys .Repository ]
74
88
repo , err := r .repoLister .Repositories (pr .Namespace ).Get (repoName )
75
89
if err != nil {
76
90
return fmt .Errorf ("failed to get repository CR: %w" , err )
77
91
}
92
+ logger .Infof ("=== RECONCILE END: PipelineRun %s/%s - PATH: DIRECT CONDITION ===" , pr .GetNamespace (), pr .GetName ())
78
93
return r .updatePipelineRunToInProgress (ctx , logger , repo , pr )
94
+ } else {
95
+ logger .Infof ("RECONCILE: Condition NOT met for %s/%s - reason='%s', state='%s'" , pr .GetNamespace (), pr .GetName (), reason , state )
79
96
}
80
97
81
98
// if its a GitHub App pipelineRun PR then process only if check run id is added otherwise wait
82
99
if _ , ok := pr .Annotations [keys .InstallationID ]; ok {
100
+ logger .Infof ("RECONCILE: PipelineRun %s/%s is a GitHub App PipelineRun, checking for CheckRunID" , pr .GetNamespace (), pr .GetName ())
83
101
if _ , ok := pr .Annotations [keys .CheckRunID ]; ! ok {
102
+ logger .Infof ("=== RECONCILE END: PipelineRun %s/%s - PATH: EARLY EXIT (waiting for CheckRunID) ===" , pr .GetNamespace (), pr .GetName ())
84
103
return nil
85
104
}
105
+ logger .Infof ("RECONCILE: PipelineRun %s/%s has CheckRunID, proceeding" , pr .GetNamespace (), pr .GetName ())
86
106
}
87
107
88
108
// queue pipelines which are in queued state and pending status
89
109
// if status is not pending, it could be canceled so let it be reported, even if state is queued
90
110
if state == kubeinteraction .StateQueued && pr .Spec .Status == tektonv1 .PipelineRunSpecStatusPending {
111
+ logger .Infof ("RECONCILE: PATH 2 - PipelineRun %s/%s is queued with pending status, calling queuePipelineRun" , pr .GetNamespace (), pr .GetName ())
112
+ logger .Infof ("=== RECONCILE END: PipelineRun %s/%s - PATH: QUEUE PROCESSING ===" , pr .GetNamespace (), pr .GetName ())
91
113
return r .queuePipelineRun (ctx , logger , pr )
92
114
}
93
115
94
116
if ! pr .IsDone () && ! pr .IsCancelled () {
117
+ logger .Infof ("RECONCILE: PipelineRun %s/%s is not done and not cancelled, skipping final status" , pr .GetNamespace (), pr .GetName ())
118
+ logger .Infof ("=== RECONCILE END: PipelineRun %s/%s - PATH: EARLY EXIT (not done) ===" , pr .GetNamespace (), pr .GetName ())
95
119
return nil
96
120
}
97
121
122
+ logger .Infof ("RECONCILE: PATH 3 - PipelineRun %s/%s is done, processing final status" , pr .GetNamespace (), pr .GetName ())
123
+
98
124
// make sure we have the latest pipelinerun to reconcile, since there is something updating at the same time
99
125
lpr , err := r .run .Clients .Tekton .TektonV1 ().PipelineRuns (pr .GetNamespace ()).Get (ctx , pr .GetName (), metav1.GetOptions {})
100
126
if err != nil {
@@ -267,10 +293,26 @@ func (r *Reconciler) reportFinalStatus(ctx context.Context, logger *zap.SugaredL
267
293
}
268
294
269
295
func (r * Reconciler ) updatePipelineRunToInProgress (ctx context.Context , logger * zap.SugaredLogger , repo * v1alpha1.Repository , pr * tektonv1.PipelineRun ) error {
296
+ logger .Infof ("*** updatePipelineRunToInProgress CALLED for PipelineRun %s/%s (resourceVersion: %s) ***" , pr .GetNamespace (), pr .GetName (), pr .GetResourceVersion ())
297
+
298
+ // Guard: Check if already in "started" state to prevent duplicate processing
299
+ currentState := pr .GetAnnotations ()[keys .State ]
300
+ logger .Infof ("*** Current state before update: %s ***" , currentState )
301
+
302
+ if currentState == kubeinteraction .StateStarted {
303
+ logger .Infof ("*** PipelineRun %s/%s already in 'started' state, skipping duplicate SCM reporting ***" , pr .GetNamespace (), pr .GetName ())
304
+ return nil
305
+ }
306
+
307
+ logger .Infof ("updating pipelineRun %v/%v state to %v and reporting status to provider" , pr .GetNamespace (), pr .GetName (), kubeinteraction .StateStarted )
308
+
270
309
pr , err := r .updatePipelineRunState (ctx , logger , pr , kubeinteraction .StateStarted )
271
310
if err != nil {
311
+ logger .Errorf ("Failed to update PipelineRun %s/%s state to %s: %v" , pr .GetNamespace (), pr .GetName (), kubeinteraction .StateStarted , err )
272
312
return fmt .Errorf ("cannot update state: %w" , err )
273
313
}
314
+ logger .Infof ("*** Successfully updated PipelineRun %s/%s state to %s (new resourceVersion: %s) ***" , pr .GetNamespace (), pr .GetName (), kubeinteraction .StateStarted , pr .GetResourceVersion ())
315
+
274
316
pacInfo := r .run .Info .GetPacOpts ()
275
317
detectedProvider , event , err := r .detectProvider (ctx , logger , pr )
276
318
if err != nil {
@@ -334,15 +376,23 @@ func (r *Reconciler) updatePipelineRunToInProgress(ctx context.Context, logger *
334
376
if err := createStatusWithRetry (ctx , logger , detectedProvider , event , status ); err != nil {
335
377
// if failed to report status for running state, let the pipelineRun continue,
336
378
// pipelineRun is already started so we will try again once it completes
337
- logger .Errorf ("failed to report status to running on provider continuing! error : %v" , err )
379
+ logger .Errorf ("*** FAILED to report status to SCM for PipelineRun %s/%s : %v ***" , pr . GetNamespace (), pr . GetName () , err )
338
380
return nil
339
381
}
340
382
341
- logger .Info ( "updated in_progress status on provider platform for pipelineRun " , pr .GetName ())
383
+ logger .Infof ( "*** SUCCESS: Reported ' in_progress' status to SCM for PipelineRun %s/%s ***" , pr . GetNamespace () , pr .GetName ())
342
384
return nil
343
385
}
344
386
345
387
func (r * Reconciler ) updatePipelineRunState (ctx context.Context , logger * zap.SugaredLogger , pr * tektonv1.PipelineRun , state string ) (* tektonv1.PipelineRun , error ) {
388
+ // Guard against unnecessary state transitions
389
+ currentState := pr .GetAnnotations ()[keys .State ]
390
+ if currentState == state {
391
+ logger .Infof ("PipelineRun %s/%s already in state %s, skipping update" , pr .GetNamespace (), pr .GetName (), state )
392
+ return pr , nil
393
+ }
394
+
395
+ logger .Infof ("updating pipelineRun %v/%v state from %s to %s" , pr .GetNamespace (), pr .GetName (), currentState , state )
346
396
mergePatch := map [string ]any {
347
397
"metadata" : map [string ]any {
348
398
"labels" : map [string ]string {
0 commit comments