From 93ba239f2c8a1216e5e0a920953ce0481b11c691 Mon Sep 17 00:00:00 2001 From: chaosinthecrd Date: Tue, 17 Nov 2026 19:06:45 +0000 Subject: [PATCH] cmd/k8s-operator: test ProxyGroup StatefulSet Pod management policy Covers a new ProxyGroup getting a Parallel StatefulSet, and an existing OrderedReady one being deleted and then recreated as Parallel. Updates tailscale/corp#38175 Signed-off-by: chaosinthecrd --- cmd/k8s-operator/proxygroup_test.go | 61 +++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) diff --git a/cmd/k8s-operator/proxygroup_test.go b/cmd/k8s-operator/proxygroup_test.go index 9b9164f59..9bd8871e3 100644 --- a/cmd/k8s-operator/proxygroup_test.go +++ b/cmd/k8s-operator/proxygroup_test.go @@ -1586,6 +1586,9 @@ func TestProxyGroupTypes(t *testing.T) { if sts.Spec.Template.Spec.Containers[0].Ports[0].Name != "k8s-proxy" { t.Errorf("unexpected port name %s, want k8s-proxy", sts.Spec.Template.Spec.Containers[0].Ports[0].Name) } + if sts.Spec.PodManagementPolicy != appsv1.ParallelPodManagement { + t.Errorf("unexpected PodManagementPolicy %q, want %q", sts.Spec.PodManagementPolicy, appsv1.ParallelPodManagement) + } }) } @@ -1663,6 +1666,64 @@ func TestKubeAPIServerStatusConditionFlow(t *testing.T) { expectEqual(t, fc, pg, omitPGStatusConditionMessages) } +func TestProxyGroupReplacesStatefulSetForPodManagementPolicy(t *testing.T) { + pg := &tsapi.ProxyGroup{ + ObjectMeta: metav1.ObjectMeta{ + Name: "test", + Finalizers: []string{FinalizerName}, + Generation: 1, + }, + Spec: tsapi.ProxyGroupSpec{ + Type: tsapi.ProxyGroupTypeEgress, + Replicas: new(int32(1)), + }, + } + fc := fake.NewClientBuilder(). + WithScheme(tsapi.GlobalScheme). + WithObjects(pg). + WithStatusSubresource(pg). + Build() + r := &ProxyGroupReconciler{ + tsNamespace: tsNamespace, + tsProxyImage: testProxyImage, + Client: fc, + log: zap.Must(zap.NewDevelopment()).Sugar(), + clients: tsclient.NewProvider(&fakeTSClient{}), + clock: tstest.NewClock(tstest.ClockOpts{}), + reissuer: tailscaled.NewReissuer(), + } + key := client.ObjectKey{Namespace: tsNamespace, Name: pg.Name} + getPolicy := func() (appsv1.PodManagementPolicyType, bool) { + t.Helper() + ss := new(appsv1.StatefulSet) + if err := fc.Get(t.Context(), key, ss); apierrors.IsNotFound(err) { + return "", false + } else if err != nil { + t.Fatalf("getting StatefulSet: %v", err) + } + return ss.Spec.PodManagementPolicy, true + } + + expectReconciled(t, r, "", pg.Name) + if got, _ := getPolicy(); got != appsv1.ParallelPodManagement { + t.Fatalf("PodManagementPolicy = %q, want %q", got, appsv1.ParallelPodManagement) + } + + // Simulate a StatefulSet created by an older operator version. + mustUpdate(t, fc, tsNamespace, pg.Name, func(ss *appsv1.StatefulSet) { + ss.Spec.PodManagementPolicy = appsv1.OrderedReadyPodManagement + }) + expectReconciled(t, r, "", pg.Name) + if _, ok := getPolicy(); ok { + t.Fatal("StatefulSet with OrderedReady policy not deleted") + } + + expectReconciled(t, r, "", pg.Name) + if got, _ := getPolicy(); got != appsv1.ParallelPodManagement { + t.Fatalf("PodManagementPolicy after replacement = %q, want %q", got, appsv1.ParallelPodManagement) + } +} + func TestKubeAPIServerType_DoesNotOverwriteServicesConfig(t *testing.T) { fc := fake.NewClientBuilder(). WithScheme(tsapi.GlobalScheme).