From 6a6742c90eec494aa96b2df0b27cd58dc51edb33 Mon Sep 17 00:00:00 2001 From: chaosinthecrd Date: Wed, 29 Jul 2026 13:56:46 +0000 Subject: [PATCH] cmd/k8s-operator: attach egress readiness gate to ProxyGroup Pods The egressPodsReconciler (added in #14792) only sets the tailscale.com/egress-services readiness condition on egress ProxyGroup replica Pods that declare the corresponding readiness gate. However, the gate was never actually added to the egress Pod template, so the reconciler always hit its early-return and the readiness condition was never set. This commit adds said readiness gate to the egress Pod template. Updates #14326 Signed-off-by: chaosinthecrd --- cmd/k8s-operator/proxygroup_specs.go | 12 ++++++++++++ cmd/k8s-operator/proxygroup_test.go | 10 ++++++++++ 2 files changed, 22 insertions(+) diff --git a/cmd/k8s-operator/proxygroup_specs.go b/cmd/k8s-operator/proxygroup_specs.go index fc9b532b5..6337fec55 100644 --- a/cmd/k8s-operator/proxygroup_specs.go +++ b/cmd/k8s-operator/proxygroup_specs.go @@ -303,6 +303,18 @@ func pgStatefulSet(pg *tsapi.ProxyGroup, namespace, image, tsFirewallMode string // Set the deletion grace period to 6 minutes to ensure that the pre-stop hook has enough time to terminate // gracefully. ss.Spec.Template.DeletionGracePeriodSeconds = new(deletionGracePeriodSeconds) + + // Add a readiness gate so that kubelet does not mark a replica Pod as + // ready before egressPodsReconciler has confirmed that cluster traffic + // for all egress services is being routed to it. Because StatefulSet + // rolling updates only restart the next replica once the previous one + // is ready, this prevents a window during updates where every replica + // has been recreated but none is yet serving traffic, which would drop + // cluster egress traffic. The reconciler sets the corresponding + // condition; see egress-pod-readiness.go. + tmpl.Spec.ReadinessGates = append(tmpl.Spec.ReadinessGates, corev1.PodReadinessGate{ + ConditionType: tsEgressReadinessGate, + }) } return ss, nil diff --git a/cmd/k8s-operator/proxygroup_test.go b/cmd/k8s-operator/proxygroup_test.go index 4c9cd3714..ce2e72c80 100644 --- a/cmd/k8s-operator/proxygroup_test.go +++ b/cmd/k8s-operator/proxygroup_test.go @@ -1216,6 +1216,11 @@ func TestProxyGroupTypes(t *testing.T) { if *sts.Spec.Template.DeletionGracePeriodSeconds != deletionGracePeriodSeconds { t.Errorf("unexpected deletion grace period seconds %d, want %d", *sts.Spec.Template.DeletionGracePeriodSeconds, deletionGracePeriodSeconds) } + if !slices.ContainsFunc(sts.Spec.Template.Spec.ReadinessGates, func(r corev1.PodReadinessGate) bool { + return r.ConditionType == tsEgressReadinessGate + }) { + t.Errorf("expected egress readiness gate %q to be set, got %v", tsEgressReadinessGate, sts.Spec.Template.Spec.ReadinessGates) + } }) t.Run("egress_type_no_lifecycle_hook_when_local_addr_port_set", func(t *testing.T) { pg := &tsapi.ProxyGroup{ @@ -1252,6 +1257,11 @@ func TestProxyGroupTypes(t *testing.T) { if sts.Spec.Template.Spec.Containers[0].Lifecycle != nil { t.Error("lifecycle hook was set when TS_LOCAL_ADDR_PORT was configured via ProxyClass") } + if slices.ContainsFunc(sts.Spec.Template.Spec.ReadinessGates, func(r corev1.PodReadinessGate) bool { + return r.ConditionType == tsEgressReadinessGate + }) { + t.Error("egress readiness gate was set when TS_LOCAL_ADDR_PORT was configured via ProxyClass") + } }) t.Run("ingress_type", func(t *testing.T) {