Skip to content

Commit 67f9bf4

Browse files
authored
Merge pull request #1 from gbenhaim/gben-debug
Gben debug
2 parents 4ae3540 + e0f14bf commit 67f9bf4

File tree

2 files changed

+56
-6
lines changed

2 files changed

+56
-6
lines changed

.github/workflows/container.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ on:
66
- "**.go"
77
- "**.yaml"
88
# For testing when pushing to the main repo directly on pr
9-
# pull_request:
10-
# paths:
11-
# - "**.go"
12-
# - "**.yaml"
9+
pull_request:
10+
paths:
11+
- "**.go"
12+
- "**.yaml"
1313
env:
1414
PLATFORMS: linux/amd64,linux/arm64,linux/ppc64le
1515

pkg/reconciler/reconciler.go

Lines changed: 52 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,47 +54,73 @@ var (
5454
func (r *Reconciler) ReconcileKind(ctx context.Context, pr *tektonv1.PipelineRun) pkgreconciler.Event {
5555
ctx = info.StoreNS(ctx, system.Namespace())
5656
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+
5760
// if pipelineRun is in completed or failed state then return
5861
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+
5964
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())
6066
return nil
6167
}
6268

6369
reason := ""
6470
if len(pr.Status.GetConditions()) > 0 {
6571
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())
6675
}
76+
6777
// This condition handles cases where the PipelineRun has entered a "Running" state,
6878
// but its status in the Git provider remains "queued" (e.g., due to updates made by
6979
// another controller outside PaC). To maintain consistency between the PipelineRun
7080
// status and the Git provider status, we update both the PipelineRun resource and
7181
// 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+
7285
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())
7387
repoName := pr.GetAnnotations()[keys.Repository]
7488
repo, err := r.repoLister.Repositories(pr.Namespace).Get(repoName)
7589
if err != nil {
7690
return fmt.Errorf("failed to get repository CR: %w", err)
7791
}
92+
logger.Infof("=== RECONCILE END: PipelineRun %s/%s - PATH: DIRECT CONDITION ===", pr.GetNamespace(), pr.GetName())
7893
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)
7996
}
8097

8198
// if its a GitHub App pipelineRun PR then process only if check run id is added otherwise wait
8299
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())
83101
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())
84103
return nil
85104
}
105+
logger.Infof("RECONCILE: PipelineRun %s/%s has CheckRunID, proceeding", pr.GetNamespace(), pr.GetName())
86106
}
87107

88108
// queue pipelines which are in queued state and pending status
89109
// if status is not pending, it could be canceled so let it be reported, even if state is queued
90110
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())
91113
return r.queuePipelineRun(ctx, logger, pr)
92114
}
93115

94116
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())
95119
return nil
96120
}
97121

122+
logger.Infof("RECONCILE: PATH 3 - PipelineRun %s/%s is done, processing final status", pr.GetNamespace(), pr.GetName())
123+
98124
// make sure we have the latest pipelinerun to reconcile, since there is something updating at the same time
99125
lpr, err := r.run.Clients.Tekton.TektonV1().PipelineRuns(pr.GetNamespace()).Get(ctx, pr.GetName(), metav1.GetOptions{})
100126
if err != nil {
@@ -267,10 +293,26 @@ func (r *Reconciler) reportFinalStatus(ctx context.Context, logger *zap.SugaredL
267293
}
268294

269295
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+
270309
pr, err := r.updatePipelineRunState(ctx, logger, pr, kubeinteraction.StateStarted)
271310
if err != nil {
311+
logger.Errorf("Failed to update PipelineRun %s/%s state to %s: %v", pr.GetNamespace(), pr.GetName(), kubeinteraction.StateStarted, err)
272312
return fmt.Errorf("cannot update state: %w", err)
273313
}
314+
logger.Infof("*** Successfully updated PipelineRun %s/%s state to %s (new resourceVersion: %s) ***", pr.GetNamespace(), pr.GetName(), kubeinteraction.StateStarted, pr.GetResourceVersion())
315+
274316
pacInfo := r.run.Info.GetPacOpts()
275317
detectedProvider, event, err := r.detectProvider(ctx, logger, pr)
276318
if err != nil {
@@ -334,15 +376,23 @@ func (r *Reconciler) updatePipelineRunToInProgress(ctx context.Context, logger *
334376
if err := createStatusWithRetry(ctx, logger, detectedProvider, event, status); err != nil {
335377
// if failed to report status for running state, let the pipelineRun continue,
336378
// 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)
338380
return nil
339381
}
340382

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())
342384
return nil
343385
}
344386

345387
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)
346396
mergePatch := map[string]any{
347397
"metadata": map[string]any{
348398
"labels": map[string]string{

0 commit comments

Comments
 (0)