diff --git a/controllers/actions.github.com/autoscalinglistener_controller.go b/controllers/actions.github.com/autoscalinglistener_controller.go index cecfdfbf..1b16eadf 100644 --- a/controllers/actions.github.com/autoscalinglistener_controller.go +++ b/controllers/actions.github.com/autoscalinglistener_controller.go @@ -260,6 +260,19 @@ func (r *AutoscalingListenerReconciler) Reconcile(ctx context.Context, req ctrl. log.Error(err, "Unable to delete the listener pod", "namespace", listenerPod.Namespace, "name", listenerPod.Name) return ctrl.Result{}, err } + + // delete the listener config secret as well, so it gets recreated when the listener pod is recreated, with any new data if it exists + var configSecret corev1.Secret + err := r.Get(ctx, types.NamespacedName{Namespace: autoscalingListener.Namespace, Name: scaleSetListenerConfigName(autoscalingListener)}, &configSecret) + switch { + case err == nil && configSecret.DeletionTimestamp.IsZero(): + log.Info("Deleting the listener config secret") + if err := r.Delete(ctx, &configSecret); err != nil { + return ctrl.Result{}, fmt.Errorf("failed to delete listener config secret: %w", err) + } + case !kerrors.IsNotFound(err): + return ctrl.Result{}, fmt.Errorf("failed to get the listener config secret: %w", err) + } } return ctrl.Result{}, nil case cs.State.Running != nil: diff --git a/controllers/actions.github.com/autoscalinglistener_controller_test.go b/controllers/actions.github.com/autoscalinglistener_controller_test.go index 5ce5ee48..b5b957d0 100644 --- a/controllers/actions.github.com/autoscalinglistener_controller_test.go +++ b/controllers/actions.github.com/autoscalinglistener_controller_test.go @@ -339,7 +339,7 @@ var _ = Describe("Test AutoScalingListener controller", func() { autoscalingListenerTestInterval).Should(BeEquivalentTo(rulesForListenerRole([]string{updated.Spec.EphemeralRunnerSetName})), "Role should be updated") }) - It("It should re-create pod whenever listener container is terminated", func() { + It("It should re-create pod and config secret whenever listener container is terminated", func() { // Waiting for the pod is created pod := new(corev1.Pod) Eventually( @@ -355,7 +355,18 @@ var _ = Describe("Test AutoScalingListener controller", func() { autoscalingListenerTestInterval, ).Should(BeEquivalentTo(autoscalingListener.Name), "Pod should be created") + secret := new(corev1.Secret) + Eventually( + func() error { + return k8sClient.Get(ctx, client.ObjectKey{Name: scaleSetListenerConfigName(autoscalingListener), Namespace: autoscalingListener.Namespace}, secret) + }, + autoscalingListenerTestTimeout, + autoscalingListenerTestInterval, + ).Should(Succeed(), "Config secret should be created") + oldPodUID := string(pod.UID) + oldSecretUID := string(secret.UID) + updated := pod.DeepCopy() updated.Status.ContainerStatuses = []corev1.ContainerStatus{ { @@ -384,6 +395,21 @@ var _ = Describe("Test AutoScalingListener controller", func() { autoscalingListenerTestTimeout, autoscalingListenerTestInterval, ).ShouldNot(BeEquivalentTo(oldPodUID), "Pod should be re-created") + + // Check if config secret is re-created + Eventually( + func() (string, error) { + secret := new(corev1.Secret) + err := k8sClient.Get(ctx, client.ObjectKey{Name: scaleSetListenerConfigName(autoscalingListener), Namespace: autoscalingListener.Namespace}, secret) + if err != nil { + return "", err + } + + return string(secret.UID), nil + }, + autoscalingListenerTestTimeout, + autoscalingListenerTestInterval, + ).ShouldNot(BeEquivalentTo(oldSecretUID), "Config secret should be re-created") }) }) })