Skip to content

Commit 8428fcd

Browse files
badstreffAdam Furbee
authored andcommitted
update ephemeral runner controller to retry even if the pod doesn't get created
1 parent a0c30df commit 8428fcd

File tree

2 files changed

+22
-13
lines changed

2 files changed

+22
-13
lines changed

controllers/actions.github.com/ephemeralrunner_controller.go

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ func (r *EphemeralRunnerReconciler) Reconcile(ctx context.Context, req ctrl.Requ
139139
return ctrl.Result{}, nil
140140
}
141141

142-
if ephemeralRunner.IsDone() {
142+
if ephemeralRunner.IsDone() && ephemeralRunner.Status.Phase != corev1.PodFailed {
143143
log.Info("Cleaning up resources after after ephemeral runner termination", "phase", ephemeralRunner.Status.Phase)
144144
err := r.cleanupResources(ctx, ephemeralRunner, log)
145145
if err != nil {
@@ -517,16 +517,14 @@ func (r *EphemeralRunnerReconciler) markAsFailed(ctx context.Context, ephemeralR
517517
obj.Status.Phase = corev1.PodFailed
518518
obj.Status.Reason = reason
519519
obj.Status.Message = errMessage
520+
if obj.Status.Failures == nil {
521+
obj.Status.Failures = make(map[string]metav1.Time)
522+
}
523+
obj.Status.Failures[metav1.Now().GoString()] = metav1.Now()
520524
}); err != nil {
521525
return fmt.Errorf("failed to update ephemeral runner status Phase/Message: %w", err)
522526
}
523-
524-
log.Info("Removing the runner from the service")
525-
if err := r.deleteRunnerFromService(ctx, ephemeralRunner, log); err != nil {
526-
return fmt.Errorf("failed to remove the runner from service: %w", err)
527-
}
528-
529-
log.Info("EphemeralRunner is marked as Failed and deleted from the service")
527+
log.Info("EphemeralRunner is marked as Failed")
530528
return nil
531529
}
532530

controllers/actions.github.com/ephemeralrunner_controller_test.go

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -261,19 +261,20 @@ var _ = Describe("EphemeralRunner", func() {
261261
).Should(BeTrue(), "Ephemeral runner should eventually be deleted")
262262
})
263263

264-
It("It should failed if a pod template is invalid", func() {
265-
invalideEphemeralRunner := newExampleRunner("invalid-ephemeral-runner", autoscalingNS.Name, configSecret.Name)
266-
invalideEphemeralRunner.Spec.Spec.PriorityClassName = "notexist"
264+
It("It should failed and eventually retry if a pod template is invalid", func() {
267265

268-
err := k8sClient.Create(ctx, invalideEphemeralRunner)
266+
invalidEphemeralRunner := newExampleRunner("invalid-ephemeral-runner", autoscalingNS.Name, configSecret.Name)
267+
invalidEphemeralRunner.Spec.Spec.PriorityClassName = "notexist"
268+
269+
err := k8sClient.Create(ctx, invalidEphemeralRunner)
269270
Expect(err).To(BeNil())
270271

271272
updated := new(v1alpha1.EphemeralRunner)
272273
Eventually(
273274
func() (corev1.PodPhase, error) {
274275
err := k8sClient.Get(
275276
ctx,
276-
client.ObjectKey{Name: invalideEphemeralRunner.Name, Namespace: invalideEphemeralRunner.Namespace},
277+
client.ObjectKey{Name: invalidEphemeralRunner.Name, Namespace: invalidEphemeralRunner.Namespace},
277278
updated,
278279
)
279280
if err != nil {
@@ -287,6 +288,16 @@ var _ = Describe("EphemeralRunner", func() {
287288

288289
Expect(updated.Status.Reason).Should(Equal("InvalidPod"))
289290
Expect(updated.Status.Message).Should(Equal("Failed to create the pod: pods \"invalid-ephemeral-runner\" is forbidden: no PriorityClass with name notexist was found"))
291+
292+
er := new(v1alpha1.EphemeralRunner)
293+
Eventually(
294+
func() bool {
295+
err := k8sClient.Get(ctx, client.ObjectKey{Name: invalidEphemeralRunner.Name, Namespace: invalidEphemeralRunner.Namespace}, er)
296+
return kerrors.IsNotFound(err)
297+
},
298+
ephemeralRunnerTimeout,
299+
ephemeralRunnerInterval,
300+
).Should(BeTrue(), "Ephemeral runner should eventually be deleted")
290301
})
291302

292303
It("It should clean up resources when deleted", func() {

0 commit comments

Comments
 (0)