Skip to content

Commit ae0ce62

Browse files
author
Lukas Hybner
committed
fix reconcilation when pods was deleted
When pods are deleted then podRunnerPairs should be reloaded, so it's better to requeue reconcilation immediately. When new pods are scale up then it takes some time usually a few seconds to sync between pods and runner API and so there is no need to wait whole period (default 1m) to sync. Signed-off-by: Lukas Hybner <[email protected]>
1 parent 5ba542c commit ae0ce62

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

controllers/githubactionrunner_controller.go

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -116,13 +116,18 @@ func (r *GithubActionRunnerReconciler) handleScaling(ctx context.Context, instan
116116

117117
// safety guard - always look for finalizers in order to unregister runners for pods about to delete
118118
// pods could have been deleted by user directly and not through operator
119-
if err = r.handleFinalization(ctx, instance, podRunnerPairs); err != nil {
119+
// if some pods are deleted then it's better to requeue immediately, because we have to reload podRunnerPairs.
120+
numDeleted, err := r.handleFinalization(ctx, instance, podRunnerPairs)
121+
if err != nil {
120122
return r.manageOutcome(ctx, instance, err)
121123
}
124+
if numDeleted > 0 {
125+
return r.ManageSuccess(ctx, instance)
126+
}
122127

123128
if !podRunnerPairs.inSync() {
124-
logger.Info("Pods and runner API not in sync, returning early")
125-
return r.manageOutcome(ctx, instance, nil)
129+
logger.Info("Pods and runner API not in sync, returning early", "Pods", podRunnerPairs.numPods(), "Runners", podRunnerPairs.numRunners())
130+
return r.ManageSuccessWithRequeue(ctx, instance, 3*time.Second)
126131
}
127132

128133
if shouldScaleUp(podRunnerPairs, instance) {
@@ -362,29 +367,31 @@ func (r *GithubActionRunnerReconciler) unregisterRunner(ctx context.Context, cr
362367
}
363368

364369
// handleFinalization will remove runner from github based on presence of finalizer
365-
func (r *GithubActionRunnerReconciler) handleFinalization(ctx context.Context, cr *garov1alpha1.GithubActionRunner, list podRunnerPairList) error {
370+
func (r *GithubActionRunnerReconciler) handleFinalization(ctx context.Context, cr *garov1alpha1.GithubActionRunner, list podRunnerPairList) (int, error) {
371+
numDeleted := 0
366372
for _, item := range list.getPodsBeingDeletedOrEvictedOrCompleted() {
373+
numDeleted++
367374
// TODO - cause of failure should be checked more closely, if it does not exist we can ignore it. If it is a comms error we should stick around
368375
if err := r.unregisterRunner(ctx, cr, item); err != nil {
369-
return err
376+
return numDeleted, err
370377
}
371378
if isEvicted(&item.pod) && env.GetBoolDefault(deleteEvictedPodsEnvVarName, true) {
372379
logr.FromContextOrDiscard(ctx).Info("Deleting evicted pod", "podname", item.pod.Name)
373380
err := r.DeleteResourceIfExists(ctx, &item.pod)
374381
if err != nil {
375-
return err
382+
return numDeleted, err
376383
}
377384
}
378385
if isCompleted(&item.pod) {
379386
logr.FromContextOrDiscard(ctx).Info("Deleting succeeded pod", "podname", item.pod.Name)
380387
err := r.DeleteResourceIfExists(ctx, &item.pod)
381388
if err != nil {
382-
return err
389+
return numDeleted, err
383390
}
384391
}
385392
}
386393

387-
return nil
394+
return numDeleted, nil
388395
}
389396

390397
// tokenForRef returns the token referenced from the GithubActionRunner Spec.TokenRef

0 commit comments

Comments
 (0)