mirror of
https://github.com/tailscale/tailscale.git
synced 2026-11-21 20:22:41 +09:00
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 <tom@tmlabs.co.uk>
This commit is contained in:
1 parent
1af2fa9eeb
commit
93ba239f2c
1 file changed
+61
@@ -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).
|
||||
|
||||
Reference in new issue
Block a user