@@ -20,7 +20,6 @@ import (
20
20
"context"
21
21
"fmt"
22
22
"io"
23
- "net/http/httptest"
24
23
"strings"
25
24
"sync"
26
25
"testing"
@@ -31,14 +30,13 @@ import (
31
30
32
31
flowcontrol "k8s.io/api/flowcontrol/v1beta2"
33
32
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
34
- "k8s.io/apimachinery/pkg/runtime/schema"
35
33
"k8s.io/apimachinery/pkg/util/wait"
36
34
genericfeatures "k8s.io/apiserver/pkg/features"
37
35
utilfeature "k8s.io/apiserver/pkg/util/feature"
38
36
clientset "k8s.io/client-go/kubernetes"
39
37
"k8s.io/client-go/rest"
40
38
featuregatetesting "k8s.io/component-base/featuregate/testing"
41
- "k8s.io/kubernetes/pkg/controlplane "
39
+ "k8s.io/kubernetes/cmd/kube-apiserver/app/options "
42
40
"k8s.io/kubernetes/test/integration/framework"
43
41
)
44
42
@@ -50,33 +48,27 @@ const (
50
48
timeout = time .Second * 10
51
49
)
52
50
53
- func setup (t testing.TB , maxReadonlyRequestsInFlight , MaxMutatingRequestsInFlight int ) (* httptest. Server , * rest.Config , framework.CloseFunc ) {
54
- opts := framework.ControlPlaneConfigOptions { EtcdOptions : framework .DefaultEtcdOptions ()}
55
- opts . EtcdOptions . DefaultStorageMediaType = "application/vnd.kubernetes.protobuf"
56
- controlPlaneConfig := framework . NewIntegrationTestControlPlaneConfigWithOptions ( & opts )
57
- resourceConfig := controlplane . DefaultAPIResourceConfigSource ()
58
- resourceConfig . EnableVersions (schema. GroupVersion {
59
- Group : "flowcontrol.apiserver.k8s.io" ,
60
- Version : "v1alpha1" ,
51
+ func setup (t testing.TB , maxReadonlyRequestsInFlight , MaxMutatingRequestsInFlight int ) (* rest.Config , framework.TearDownFunc ) {
52
+ _ , kubeConfig , tearDownFn := framework .StartTestServer ( t , framework.TestServerSetup {
53
+ ModifyServerRunOptions : func ( opts * options. ServerRunOptions ) {
54
+ // Ensure all clients are allowed to send requests.
55
+ opts . Authorization . Modes = [] string { "AlwaysAllow" }
56
+ opts . GenericServerRunOptions . MaxRequestsInFlight = maxReadonlyRequestsInFlight
57
+ opts . GenericServerRunOptions . MaxMutatingRequestsInFlight = MaxMutatingRequestsInFlight
58
+ } ,
61
59
})
62
- controlPlaneConfig .GenericConfig .MaxRequestsInFlight = maxReadonlyRequestsInFlight
63
- controlPlaneConfig .GenericConfig .MaxMutatingRequestsInFlight = MaxMutatingRequestsInFlight
64
- controlPlaneConfig .GenericConfig .OpenAPIConfig = framework .DefaultOpenAPIConfig ()
65
- controlPlaneConfig .ExtraConfig .APIResourceConfigSource = resourceConfig
66
- _ , s , closeFn := framework .RunAnAPIServer (controlPlaneConfig )
67
-
68
- return s , controlPlaneConfig .GenericConfig .LoopbackClientConfig , closeFn
60
+ return kubeConfig , tearDownFn
69
61
}
70
62
71
63
func TestPriorityLevelIsolation (t * testing.T ) {
72
64
defer featuregatetesting .SetFeatureGateDuringTest (t , utilfeature .DefaultFeatureGate , genericfeatures .APIPriorityAndFairness , true )()
73
65
// NOTE: disabling the feature should fail the test
74
- _ , loopbackConfig , closeFn := setup (t , 1 , 1 )
66
+ kubeConfig , closeFn := setup (t , 1 , 1 )
75
67
defer closeFn ()
76
68
77
- loopbackClient := clientset .NewForConfigOrDie (loopbackConfig )
78
- noxu1Client := getClientFor (loopbackConfig , "noxu1" )
79
- noxu2Client := getClientFor (loopbackConfig , "noxu2" )
69
+ loopbackClient := clientset .NewForConfigOrDie (kubeConfig )
70
+ noxu1Client := getClientFor (kubeConfig , "noxu1" )
71
+ noxu2Client := getClientFor (kubeConfig , "noxu2" )
80
72
81
73
queueLength := 50
82
74
concurrencyShares := 1
@@ -153,13 +145,9 @@ func TestPriorityLevelIsolation(t *testing.T) {
153
145
}
154
146
155
147
func getClientFor (loopbackConfig * rest.Config , username string ) clientset.Interface {
156
- config := & rest.Config {
157
- Host : loopbackConfig .Host ,
158
- QPS : - 1 ,
159
- BearerToken : loopbackConfig .BearerToken ,
160
- Impersonate : rest.ImpersonationConfig {
161
- UserName : username ,
162
- },
148
+ config := rest .CopyConfig (loopbackConfig )
149
+ config .Impersonate = rest.ImpersonationConfig {
150
+ UserName : username ,
163
151
}
164
152
return clientset .NewForConfigOrDie (config )
165
153
}
0 commit comments