@@ -20,7 +20,6 @@ import (
20
20
"context"
21
21
"fmt"
22
22
"math/rand"
23
- "net/http/httptest"
24
23
"os"
25
24
"strconv"
26
25
"testing"
@@ -36,13 +35,13 @@ import (
36
35
restclient "k8s.io/client-go/rest"
37
36
ref "k8s.io/client-go/tools/reference"
38
37
fakecloud "k8s.io/cloud-provider/fake"
38
+ kubeapiservertesting "k8s.io/kubernetes/cmd/kube-apiserver/app/testing"
39
39
"k8s.io/kubernetes/pkg/api/legacyscheme"
40
40
persistentvolumecontroller "k8s.io/kubernetes/pkg/controller/volume/persistentvolume"
41
41
"k8s.io/kubernetes/pkg/volume"
42
42
volumetest "k8s.io/kubernetes/pkg/volume/testing"
43
43
"k8s.io/kubernetes/test/integration/framework"
44
44
45
- "k8s.io/apimachinery/pkg/runtime/schema"
46
45
"k8s.io/klog/v2"
47
46
)
48
47
@@ -105,16 +104,17 @@ func testSleep() {
105
104
106
105
func TestPersistentVolumeRecycler (t * testing.T ) {
107
106
klog .V (2 ).Infof ("TestPersistentVolumeRecycler started" )
108
- _ , s , closeFn := framework .RunAnAPIServer (nil )
109
- defer closeFn ()
107
+ s := kubeapiservertesting .StartTestServerOrDie (t , nil , []string {"--disable-admission-plugins=ServiceAccount,StorageObjectInUseProtection" }, framework .SharedEtcd ())
108
+ defer s .TearDownFn ()
109
+ namespaceName := "pv-recycler"
110
110
111
- ns := framework .CreateTestingNamespace ("pv-recycler" , t )
112
- defer framework .DeleteTestingNamespace (ns , t )
113
-
114
- testClient , ctrl , informers , watchPV , watchPVC := createClients (ns , t , s , defaultSyncPeriod )
111
+ testClient , ctrl , informers , watchPV , watchPVC := createClients (namespaceName , t , s , defaultSyncPeriod )
115
112
defer watchPV .Stop ()
116
113
defer watchPVC .Stop ()
117
114
115
+ ns := framework .CreateNamespaceOrDie (testClient , namespaceName , t )
116
+ defer framework .DeleteNamespaceOrDie (testClient , ns , t )
117
+
118
118
// NOTE: This test cannot run in parallel, because it is creating and deleting
119
119
// non-namespaced objects (PersistenceVolumes).
120
120
defer testClient .CoreV1 ().PersistentVolumes ().DeleteCollection (context .TODO (), metav1.DeleteOptions {}, metav1.ListOptions {})
@@ -160,16 +160,17 @@ func TestPersistentVolumeRecycler(t *testing.T) {
160
160
161
161
func TestPersistentVolumeDeleter (t * testing.T ) {
162
162
klog .V (2 ).Infof ("TestPersistentVolumeDeleter started" )
163
- _ , s , closeFn := framework .RunAnAPIServer (nil )
164
- defer closeFn ()
165
-
166
- ns := framework .CreateTestingNamespace ("pv-deleter" , t )
167
- defer framework .DeleteTestingNamespace (ns , t )
163
+ s := kubeapiservertesting .StartTestServerOrDie (t , nil , []string {"--disable-admission-plugins=ServiceAccount,StorageObjectInUseProtection" }, framework .SharedEtcd ())
164
+ defer s .TearDownFn ()
165
+ namespaceName := "pv-deleter"
168
166
169
- testClient , ctrl , informers , watchPV , watchPVC := createClients (ns , t , s , defaultSyncPeriod )
167
+ testClient , ctrl , informers , watchPV , watchPVC := createClients (namespaceName , t , s , defaultSyncPeriod )
170
168
defer watchPV .Stop ()
171
169
defer watchPVC .Stop ()
172
170
171
+ ns := framework .CreateNamespaceOrDie (testClient , namespaceName , t )
172
+ defer framework .DeleteNamespaceOrDie (testClient , ns , t )
173
+
173
174
// NOTE: This test cannot run in parallel, because it is creating and deleting
174
175
// non-namespaced objects (PersistenceVolumes).
175
176
defer testClient .CoreV1 ().PersistentVolumes ().DeleteCollection (context .TODO (), metav1.DeleteOptions {}, metav1.ListOptions {})
@@ -220,16 +221,17 @@ func TestPersistentVolumeBindRace(t *testing.T) {
220
221
// Test a race binding many claims to a PV that is pre-bound to a specific
221
222
// PVC. Only this specific PVC should get bound.
222
223
klog .V (2 ).Infof ("TestPersistentVolumeBindRace started" )
223
- _ , s , closeFn := framework .RunAnAPIServer (nil )
224
- defer closeFn ()
225
-
226
- ns := framework .CreateTestingNamespace ("pv-bind-race" , t )
227
- defer framework .DeleteTestingNamespace (ns , t )
224
+ s := kubeapiservertesting .StartTestServerOrDie (t , nil , []string {"--disable-admission-plugins=ServiceAccount,StorageObjectInUseProtection" }, framework .SharedEtcd ())
225
+ defer s .TearDownFn ()
226
+ namespaceName := "pv-bind-race"
228
227
229
- testClient , ctrl , informers , watchPV , watchPVC := createClients (ns , t , s , defaultSyncPeriod )
228
+ testClient , ctrl , informers , watchPV , watchPVC := createClients (namespaceName , t , s , defaultSyncPeriod )
230
229
defer watchPV .Stop ()
231
230
defer watchPVC .Stop ()
232
231
232
+ ns := framework .CreateNamespaceOrDie (testClient , namespaceName , t )
233
+ defer framework .DeleteNamespaceOrDie (testClient , ns , t )
234
+
233
235
// NOTE: This test cannot run in parallel, because it is creating and deleting
234
236
// non-namespaced objects (PersistenceVolumes).
235
237
defer testClient .CoreV1 ().PersistentVolumes ().DeleteCollection (context .TODO (), metav1.DeleteOptions {}, metav1.ListOptions {})
@@ -290,16 +292,17 @@ func TestPersistentVolumeBindRace(t *testing.T) {
290
292
291
293
// TestPersistentVolumeClaimLabelSelector test binding using label selectors
292
294
func TestPersistentVolumeClaimLabelSelector (t * testing.T ) {
293
- _ , s , closeFn := framework .RunAnAPIServer (nil )
294
- defer closeFn ()
295
-
296
- ns := framework .CreateTestingNamespace ("pvc-label-selector" , t )
297
- defer framework .DeleteTestingNamespace (ns , t )
295
+ s := kubeapiservertesting .StartTestServerOrDie (t , nil , []string {"--disable-admission-plugins=ServiceAccount,StorageObjectInUseProtection" }, framework .SharedEtcd ())
296
+ defer s .TearDownFn ()
297
+ namespaceName := "pvc-label-selector"
298
298
299
- testClient , controller , informers , watchPV , watchPVC := createClients (ns , t , s , defaultSyncPeriod )
299
+ testClient , controller , informers , watchPV , watchPVC := createClients (namespaceName , t , s , defaultSyncPeriod )
300
300
defer watchPV .Stop ()
301
301
defer watchPVC .Stop ()
302
302
303
+ ns := framework .CreateNamespaceOrDie (testClient , namespaceName , t )
304
+ defer framework .DeleteNamespaceOrDie (testClient , ns , t )
305
+
303
306
// NOTE: This test cannot run in parallel, because it is creating and deleting
304
307
// non-namespaced objects (PersistenceVolumes).
305
308
defer testClient .CoreV1 ().PersistentVolumes ().DeleteCollection (context .TODO (), metav1.DeleteOptions {}, metav1.ListOptions {})
@@ -371,16 +374,17 @@ func TestPersistentVolumeClaimLabelSelector(t *testing.T) {
371
374
// TestPersistentVolumeClaimLabelSelectorMatchExpressions test binding using
372
375
// MatchExpressions label selectors
373
376
func TestPersistentVolumeClaimLabelSelectorMatchExpressions (t * testing.T ) {
374
- _ , s , closeFn := framework .RunAnAPIServer (nil )
375
- defer closeFn ()
377
+ s := kubeapiservertesting .StartTestServerOrDie (t , nil , []string {"--disable-admission-plugins=ServiceAccount,StorageObjectInUseProtection" }, framework .SharedEtcd ())
378
+ defer s .TearDownFn ()
379
+ namespaceName := "pvc-match-expressions"
376
380
377
- ns := framework .CreateTestingNamespace ("pvc-match-expressions" , t )
378
- defer framework .DeleteTestingNamespace (ns , t )
379
-
380
- testClient , controller , informers , watchPV , watchPVC := createClients (ns , t , s , defaultSyncPeriod )
381
+ testClient , controller , informers , watchPV , watchPVC := createClients (namespaceName , t , s , defaultSyncPeriod )
381
382
defer watchPV .Stop ()
382
383
defer watchPVC .Stop ()
383
384
385
+ ns := framework .CreateNamespaceOrDie (testClient , namespaceName , t )
386
+ defer framework .DeleteNamespaceOrDie (testClient , ns , t )
387
+
384
388
// NOTE: This test cannot run in parallel, because it is creating and deleting
385
389
// non-namespaced objects (PersistenceVolumes).
386
390
defer testClient .CoreV1 ().PersistentVolumes ().DeleteCollection (context .TODO (), metav1.DeleteOptions {}, metav1.ListOptions {})
@@ -471,16 +475,17 @@ func TestPersistentVolumeClaimLabelSelectorMatchExpressions(t *testing.T) {
471
475
// TestPersistentVolumeMultiPVs tests binding of one PVC to 100 PVs with
472
476
// different size.
473
477
func TestPersistentVolumeMultiPVs (t * testing.T ) {
474
- _ , s , closeFn := framework .RunAnAPIServer (nil )
475
- defer closeFn ()
478
+ s := kubeapiservertesting .StartTestServerOrDie (t , nil , []string {"--disable-admission-plugins=ServiceAccount,StorageObjectInUseProtection" }, framework .SharedEtcd ())
479
+ defer s .TearDownFn ()
480
+ namespaceName := "multi-pvs"
476
481
477
- ns := framework .CreateTestingNamespace ("multi-pvs" , t )
478
- defer framework .DeleteTestingNamespace (ns , t )
479
-
480
- testClient , controller , informers , watchPV , watchPVC := createClients (ns , t , s , defaultSyncPeriod )
482
+ testClient , controller , informers , watchPV , watchPVC := createClients (namespaceName , t , s , defaultSyncPeriod )
481
483
defer watchPV .Stop ()
482
484
defer watchPVC .Stop ()
483
485
486
+ ns := framework .CreateNamespaceOrDie (testClient , namespaceName , t )
487
+ defer framework .DeleteNamespaceOrDie (testClient , ns , t )
488
+
484
489
// NOTE: This test cannot run in parallel, because it is creating and deleting
485
490
// non-namespaced objects (PersistenceVolumes).
486
491
defer testClient .CoreV1 ().PersistentVolumes ().DeleteCollection (context .TODO (), metav1.DeleteOptions {}, metav1.ListOptions {})
@@ -561,16 +566,17 @@ func TestPersistentVolumeMultiPVs(t *testing.T) {
561
566
// TestPersistentVolumeMultiPVsPVCs tests binding of 100 PVC to 100 PVs.
562
567
// This test is configurable by KUBE_INTEGRATION_PV_* variables.
563
568
func TestPersistentVolumeMultiPVsPVCs (t * testing.T ) {
564
- _ , s , closeFn := framework .RunAnAPIServer (nil )
565
- defer closeFn ()
566
-
567
- ns := framework .CreateTestingNamespace ("multi-pvs-pvcs" , t )
568
- defer framework .DeleteTestingNamespace (ns , t )
569
+ s := kubeapiservertesting .StartTestServerOrDie (t , nil , []string {"--disable-admission-plugins=ServiceAccount,StorageObjectInUseProtection" }, framework .SharedEtcd ())
570
+ defer s .TearDownFn ()
571
+ namespaceName := "multi-pvs-pvcs"
569
572
570
- testClient , binder , informers , watchPV , watchPVC := createClients (ns , t , s , defaultSyncPeriod )
573
+ testClient , binder , informers , watchPV , watchPVC := createClients (namespaceName , t , s , defaultSyncPeriod )
571
574
defer watchPV .Stop ()
572
575
defer watchPVC .Stop ()
573
576
577
+ ns := framework .CreateNamespaceOrDie (testClient , namespaceName , t )
578
+ defer framework .DeleteNamespaceOrDie (testClient , ns , t )
579
+
574
580
// NOTE: This test cannot run in parallel, because it is creating and deleting
575
581
// non-namespaced objects (PersistenceVolumes).
576
582
defer testClient .CoreV1 ().PersistentVolumes ().DeleteCollection (context .TODO (), metav1.DeleteOptions {}, metav1.ListOptions {})
@@ -721,21 +727,22 @@ func TestPersistentVolumeMultiPVsPVCs(t *testing.T) {
721
727
// TestPersistentVolumeControllerStartup tests startup of the controller.
722
728
// The controller should not unbind any volumes when it starts.
723
729
func TestPersistentVolumeControllerStartup (t * testing.T ) {
724
- _ , s , closeFn := framework .RunAnAPIServer (nil )
725
- defer closeFn ()
726
-
727
- ns := framework .CreateTestingNamespace ("controller-startup" , t )
728
- defer framework .DeleteTestingNamespace (ns , t )
730
+ s := kubeapiservertesting .StartTestServerOrDie (t , nil , []string {"--disable-admission-plugins=ServiceAccount,StorageObjectInUseProtection" }, framework .SharedEtcd ())
731
+ defer s .TearDownFn ()
732
+ namespaceName := "controller-startup"
729
733
730
734
objCount := getObjectCount ()
731
735
732
736
const shortSyncPeriod = 2 * time .Second
733
737
syncPeriod := getSyncPeriod (shortSyncPeriod )
734
738
735
- testClient , binder , informers , watchPV , watchPVC := createClients (ns , t , s , shortSyncPeriod )
739
+ testClient , binder , informers , watchPV , watchPVC := createClients (namespaceName , t , s , shortSyncPeriod )
736
740
defer watchPV .Stop ()
737
741
defer watchPVC .Stop ()
738
742
743
+ ns := framework .CreateNamespaceOrDie (testClient , namespaceName , t )
744
+ defer framework .DeleteNamespaceOrDie (testClient , ns , t )
745
+
739
746
// Create *bound* volumes and PVCs
740
747
pvs := make ([]* v1.PersistentVolume , objCount )
741
748
pvcs := make ([]* v1.PersistentVolumeClaim , objCount )
@@ -850,16 +857,17 @@ func TestPersistentVolumeControllerStartup(t *testing.T) {
850
857
// TestPersistentVolumeProvisionMultiPVCs tests provisioning of many PVCs.
851
858
// This test is configurable by KUBE_INTEGRATION_PV_* variables.
852
859
func TestPersistentVolumeProvisionMultiPVCs (t * testing.T ) {
853
- _ , s , closeFn := framework .RunAnAPIServer (nil )
854
- defer closeFn ()
855
-
856
- ns := framework .CreateTestingNamespace ("provision-multi-pvs" , t )
857
- defer framework .DeleteTestingNamespace (ns , t )
860
+ s := kubeapiservertesting .StartTestServerOrDie (t , nil , []string {"--disable-admission-plugins=ServiceAccount,StorageObjectInUseProtection" }, framework .SharedEtcd ())
861
+ defer s .TearDownFn ()
862
+ namespaceName := "provision-multi-pvs"
858
863
859
- testClient , binder , informers , watchPV , watchPVC := createClients (ns , t , s , defaultSyncPeriod )
864
+ testClient , binder , informers , watchPV , watchPVC := createClients (namespaceName , t , s , defaultSyncPeriod )
860
865
defer watchPV .Stop ()
861
866
defer watchPVC .Stop ()
862
867
868
+ ns := framework .CreateNamespaceOrDie (testClient , namespaceName , t )
869
+ defer framework .DeleteNamespaceOrDie (testClient , ns , t )
870
+
863
871
// NOTE: This test cannot run in parallel, because it is creating and deleting
864
872
// non-namespaced objects (PersistenceVolumes and StorageClasses).
865
873
defer testClient .CoreV1 ().PersistentVolumes ().DeleteCollection (context .TODO (), metav1.DeleteOptions {}, metav1.ListOptions {})
@@ -945,16 +953,17 @@ func TestPersistentVolumeProvisionMultiPVCs(t *testing.T) {
945
953
// TestPersistentVolumeMultiPVsDiffAccessModes tests binding of one PVC to two
946
954
// PVs with different access modes.
947
955
func TestPersistentVolumeMultiPVsDiffAccessModes (t * testing.T ) {
948
- _ , s , closeFn := framework .RunAnAPIServer (nil )
949
- defer closeFn ()
956
+ s := kubeapiservertesting .StartTestServerOrDie (t , nil , []string {"--disable-admission-plugins=ServiceAccount,StorageObjectInUseProtection" }, framework .SharedEtcd ())
957
+ defer s .TearDownFn ()
958
+ namespaceName := "multi-pvs-diff-access"
950
959
951
- ns := framework .CreateTestingNamespace ("multi-pvs-diff-access" , t )
952
- defer framework .DeleteTestingNamespace (ns , t )
953
-
954
- testClient , controller , informers , watchPV , watchPVC := createClients (ns , t , s , defaultSyncPeriod )
960
+ testClient , controller , informers , watchPV , watchPVC := createClients (namespaceName , t , s , defaultSyncPeriod )
955
961
defer watchPV .Stop ()
956
962
defer watchPVC .Stop ()
957
963
964
+ ns := framework .CreateNamespaceOrDie (testClient , namespaceName , t )
965
+ defer framework .DeleteNamespaceOrDie (testClient , ns , t )
966
+
958
967
// NOTE: This test cannot run in parallel, because it is creating and deleting
959
968
// non-namespaced objects (PersistenceVolumes).
960
969
defer testClient .CoreV1 ().PersistentVolumes ().DeleteCollection (context .TODO (), metav1.DeleteOptions {}, metav1.ListOptions {})
@@ -1093,21 +1102,17 @@ func waitForAnyPersistentVolumeClaimPhase(w watch.Interface, phase v1.Persistent
1093
1102
}
1094
1103
}
1095
1104
1096
- func createClients (ns * v1. Namespace , t * testing.T , s * httptest. Server , syncPeriod time.Duration ) (* clientset.Clientset , * persistentvolumecontroller.PersistentVolumeController , informers.SharedInformerFactory , watch.Interface , watch.Interface ) {
1105
+ func createClients (namespaceName string , t * testing.T , s * kubeapiservertesting. TestServer , syncPeriod time.Duration ) (* clientset.Clientset , * persistentvolumecontroller.PersistentVolumeController , informers.SharedInformerFactory , watch.Interface , watch.Interface ) {
1097
1106
// Use higher QPS and Burst, there is a test for race conditions which
1098
1107
// creates many objects and default values were too low.
1099
- binderClient := clientset .NewForConfigOrDie (& restclient.Config {
1100
- Host : s .URL ,
1101
- ContentConfig : restclient.ContentConfig {GroupVersion : & schema.GroupVersion {Group : "" , Version : "v1" }},
1102
- QPS : 1000000 ,
1103
- Burst : 1000000 ,
1104
- })
1105
- testClient := clientset .NewForConfigOrDie (& restclient.Config {
1106
- Host : s .URL ,
1107
- ContentConfig : restclient.ContentConfig {GroupVersion : & schema.GroupVersion {Group : "" , Version : "v1" }},
1108
- QPS : 1000000 ,
1109
- Burst : 1000000 ,
1110
- })
1108
+ binderConfig := restclient .CopyConfig (s .ClientConfig )
1109
+ binderConfig .QPS = 1000000
1110
+ binderConfig .Burst = 1000000
1111
+ binderClient := clientset .NewForConfigOrDie (binderConfig )
1112
+ testConfig := restclient .CopyConfig (s .ClientConfig )
1113
+ testConfig .QPS = 1000000
1114
+ testConfig .Burst = 1000000
1115
+ testClient := clientset .NewForConfigOrDie (testConfig )
1111
1116
1112
1117
host := volumetest .NewFakeVolumeHost (t , "/tmp/fake" , nil , nil )
1113
1118
plugin := & volumetest.FakeVolumePlugin {
@@ -1146,7 +1151,7 @@ func createClients(ns *v1.Namespace, t *testing.T, s *httptest.Server, syncPerio
1146
1151
if err != nil {
1147
1152
t .Fatalf ("Failed to watch PersistentVolumes: %v" , err )
1148
1153
}
1149
- watchPVC , err := testClient .CoreV1 ().PersistentVolumeClaims (ns . Name ).Watch (context .TODO (), metav1.ListOptions {})
1154
+ watchPVC , err := testClient .CoreV1 ().PersistentVolumeClaims (namespaceName ).Watch (context .TODO (), metav1.ListOptions {})
1150
1155
if err != nil {
1151
1156
t .Fatalf ("Failed to watch PersistentVolumeClaims: %v" , err )
1152
1157
}
0 commit comments