Skip to content

Commit

Permalink
Prevent runner controller from recreating runner pod when pod was ter…
Browse files Browse the repository at this point in the history
…minated externally (#1851)
  • Loading branch information
mumoshu committed Oct 13, 2022
1 parent 4335527 commit 710e2fb
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions controllers/runner_pod_controller.go
Expand Up @@ -27,10 +27,13 @@ import (

kerrors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/types"
"k8s.io/client-go/tools/record"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"

arcv1alpha1 "github.com/actions-runner-controller/actions-runner-controller/api/v1alpha1"

corev1 "k8s.io/api/core/v1"
)

Expand Down Expand Up @@ -124,6 +127,21 @@ func (r *RunnerPodReconciler) Reconcile(ctx context.Context, req ctrl.Request) (
} else {
log.V(2).Info("Seen deletion-timestamp is already set")

// Mark the parent Runner resource for deletion before deleting this runner pod from the cluster.
// Otherwise the runner controller can recreate the runner pod thinking it has not created any runner pod yet.
var (
key = types.NamespacedName{Namespace: runnerPod.Namespace, Name: runnerPod.Name}
runner arcv1alpha1.Runner
)
if err := r.Get(ctx, key, &runner); err == nil {
if runner.Name != "" && runner.DeletionTimestamp == nil {
log.Info("This runner pod seems to have been deleted directly, bypassing the parent Runner resource. Marking the runner for deletion to not let it recreate this pod.")
if err := r.Delete(ctx, &runner); err != nil {
return ctrl.Result{}, err
}
}
}

if finalizers, removed := removeFinalizer(runnerPod.ObjectMeta.Finalizers, runnerLinkedResourcesFinalizerName); removed {
if err := r.cleanupRunnerLinkedPods(ctx, &runnerPod, log); err != nil {
log.Info("Runner-linked pods clean up that has failed due to an error. If this persists, please manually remove the runner-linked pods to unblock ARC", "err", err.Error())
Expand Down

0 comments on commit 710e2fb

Please sign in to comment.