Log and wait if the creation event is not yet sourced

This commit is contained in:
Nikola Jokic 2025-08-08 12:40:14 +02:00
parent ad2dd7d787
commit 84a2f0d68e
No known key found for this signature in database
GPG Key ID: E4104494F9B8DDF6
1 changed files with 8 additions and 2 deletions

View File

@ -193,6 +193,10 @@ func (r *EphemeralRunnerReconciler) Reconcile(ctx context.Context, req ctrl.Requ
// create secret if not created
log.Info("Creating new ephemeral runner secret for jitconfig.")
if err := r.createSecret(ctx, ephemeralRunner, jitConfig, log); err != nil {
if kerrors.IsAlreadyExists(err) {
log.Info("Secret already exists. Requeing after 1 second to wait for the event")
return ctrl.Result{Requeue: true, RequeueAfter: 1 * time.Second}, nil
}
return ctrl.Result{}, fmt.Errorf("failed to create secret: %w", err)
}
log.Info("Created new ephemeral runner secret for jitconfig.")
@ -268,13 +272,15 @@ func (r *EphemeralRunnerReconciler) Reconcile(ctx context.Context, req ctrl.Requ
log.Error(err, "Failed to fetch the pod")
return ctrl.Result{}, err
}
log.Info("Ephemeral runner pod does not exist. Creating new ephemeral runner")
// Pod was not found. Create if the pod has never been created
log.Info("Creating new EphemeralRunner pod.")
result, err := r.createPod(ctx, ephemeralRunner, secret, log)
switch {
case err == nil:
return result, nil
case kerrors.IsAlreadyExists(err):
log.Info("Runner pod already exists. Waiting for the pod event to be received")
return ctrl.Result{}, nil
case kerrors.IsInvalid(err) || kerrors.IsForbidden(err):
log.Error(err, "Failed to create a pod due to unrecoverable failure")
errMessage := fmt.Sprintf("Failed to create the pod: %v", err)