Skip to content

Commit 3b5693e

Browse files
authored
Remove check if runner exists after exit code 0 (#4142)
1 parent e6e621a commit 3b5693e

File tree

2 files changed

+4
-98
lines changed

2 files changed

+4
-98
lines changed

controllers/actions.github.com/ephemeralrunner_controller.go

Lines changed: 4 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -293,28 +293,10 @@ func (r *EphemeralRunnerReconciler) Reconcile(ctx context.Context, req ctrl.Requ
293293
}
294294
return ctrl.Result{}, nil
295295

296-
default:
297-
// pod succeeded. We double-check with the service if the runner exists.
298-
// The reason is that image can potentially finish with status 0, but not pick up the job.
299-
existsInService, err := r.runnerRegisteredWithService(ctx, ephemeralRunner.DeepCopy(), log)
300-
if err != nil {
301-
log.Error(err, "Failed to check if runner is registered with the service")
302-
return ctrl.Result{}, err
303-
}
304-
if !existsInService {
305-
// the runner does not exist in the service, so it must be done
306-
log.Info("Ephemeral runner has finished since it does not exist in the service anymore")
307-
if err := r.markAsFinished(ctx, ephemeralRunner, log); err != nil {
308-
log.Error(err, "Failed to mark ephemeral runner as finished")
309-
return ctrl.Result{}, err
310-
}
311-
return ctrl.Result{}, nil
312-
}
313-
314-
// The runner still exists. This can happen if the pod exited with 0 but fails to start
315-
log.Info("Ephemeral runner pod has finished, but the runner still exists in the service. Deleting the pod to restart it.")
316-
if err := r.deletePodAsFailed(ctx, ephemeralRunner, pod, log); err != nil {
317-
log.Error(err, "failed to delete a pod that still exists in the service")
296+
default: // succeeded
297+
log.Info("Ephemeral runner has finished successfully")
298+
if err := r.markAsFinished(ctx, ephemeralRunner, log); err != nil {
299+
log.Error(err, "Failed to mark ephemeral runner as finished")
318300
return ctrl.Result{}, err
319301
}
320302
return ctrl.Result{}, nil
@@ -752,35 +734,6 @@ func (r *EphemeralRunnerReconciler) updateRunStatusFromPod(ctx context.Context,
752734
return nil
753735
}
754736

755-
// runnerRegisteredWithService checks if the runner is still registered with the service
756-
// Returns found=false and err=nil if ephemeral runner does not exist in GitHub service and should be deleted
757-
func (r EphemeralRunnerReconciler) runnerRegisteredWithService(ctx context.Context, runner *v1alpha1.EphemeralRunner, log logr.Logger) (found bool, err error) {
758-
actionsClient, err := r.GetActionsService(ctx, runner)
759-
if err != nil {
760-
return false, fmt.Errorf("failed to get Actions client for ScaleSet: %w", err)
761-
}
762-
763-
log.Info("Checking if runner exists in GitHub service", "runnerId", runner.Status.RunnerId)
764-
_, err = actionsClient.GetRunner(ctx, int64(runner.Status.RunnerId))
765-
if err != nil {
766-
actionsError := &actions.ActionsError{}
767-
if !errors.As(err, &actionsError) {
768-
return false, err
769-
}
770-
771-
if actionsError.StatusCode != http.StatusNotFound ||
772-
!actionsError.IsException("AgentNotFoundException") {
773-
return false, fmt.Errorf("failed to check if runner exists in GitHub service: %w", err)
774-
}
775-
776-
log.Info("Runner does not exist in GitHub service", "runnerId", runner.Status.RunnerId)
777-
return false, nil
778-
}
779-
780-
log.Info("Runner exists in GitHub service", "runnerId", runner.Status.RunnerId)
781-
return true, nil
782-
}
783-
784737
func (r *EphemeralRunnerReconciler) deleteRunnerFromService(ctx context.Context, ephemeralRunner *v1alpha1.EphemeralRunner, log logr.Logger) error {
785738
client, err := r.GetActionsService(ctx, ephemeralRunner)
786739
if err != nil {

controllers/actions.github.com/ephemeralrunner_controller_test.go

Lines changed: 0 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -675,53 +675,6 @@ var _ = Describe("EphemeralRunner", func() {
675675
).Should(BeEquivalentTo(true))
676676
})
677677

678-
It("It should re-create pod on exit status 0, but runner exists within the service", func() {
679-
pod := new(corev1.Pod)
680-
Eventually(
681-
func() (bool, error) {
682-
if err := k8sClient.Get(ctx, client.ObjectKey{Name: ephemeralRunner.Name, Namespace: ephemeralRunner.Namespace}, pod); err != nil {
683-
return false, err
684-
}
685-
return true, nil
686-
},
687-
ephemeralRunnerTimeout,
688-
ephemeralRunnerInterval,
689-
).Should(BeEquivalentTo(true))
690-
691-
pod.Status.ContainerStatuses = append(pod.Status.ContainerStatuses, corev1.ContainerStatus{
692-
Name: v1alpha1.EphemeralRunnerContainerName,
693-
State: corev1.ContainerState{
694-
Terminated: &corev1.ContainerStateTerminated{
695-
ExitCode: 0,
696-
},
697-
},
698-
})
699-
err := k8sClient.Status().Update(ctx, pod)
700-
Expect(err).To(BeNil(), "failed to update pod status")
701-
702-
updated := new(v1alpha1.EphemeralRunner)
703-
Eventually(func() (bool, error) {
704-
err := k8sClient.Get(ctx, client.ObjectKey{Name: ephemeralRunner.Name, Namespace: ephemeralRunner.Namespace}, updated)
705-
if err != nil {
706-
return false, err
707-
}
708-
return len(updated.Status.Failures) == 1, nil
709-
}, ephemeralRunnerTimeout, ephemeralRunnerInterval).Should(BeEquivalentTo(true))
710-
711-
// should re-create after failure
712-
Eventually(
713-
func() (bool, error) {
714-
pod := new(corev1.Pod)
715-
if err := k8sClient.Get(ctx, client.ObjectKey{Name: ephemeralRunner.Name, Namespace: ephemeralRunner.Namespace}, pod); err != nil {
716-
return false, err
717-
}
718-
return true, nil
719-
},
720-
ephemeralRunnerTimeout,
721-
ephemeralRunnerInterval,
722-
).Should(BeEquivalentTo(true))
723-
})
724-
725678
It("It should not set the phase to succeeded without pod termination status", func() {
726679
pod := new(corev1.Pod)
727680
Eventually(

0 commit comments

Comments
 (0)