diff --git a/test/integration/apiserver/flowcontrol/concurrency_test.go b/test/integration/apiserver/flowcontrol/concurrency_test.go index d5f314af22b..c8121de45bc 100644 --- a/test/integration/apiserver/flowcontrol/concurrency_test.go +++ b/test/integration/apiserver/flowcontrol/concurrency_test.go @@ -20,7 +20,6 @@ import ( "context" "fmt" "io" - "net/http/httptest" "strings" "sync" "testing" @@ -31,14 +30,13 @@ import ( flowcontrol "k8s.io/api/flowcontrol/v1beta2" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/runtime/schema" "k8s.io/apimachinery/pkg/util/wait" genericfeatures "k8s.io/apiserver/pkg/features" utilfeature "k8s.io/apiserver/pkg/util/feature" clientset "k8s.io/client-go/kubernetes" "k8s.io/client-go/rest" featuregatetesting "k8s.io/component-base/featuregate/testing" - "k8s.io/kubernetes/pkg/controlplane" + "k8s.io/kubernetes/cmd/kube-apiserver/app/options" "k8s.io/kubernetes/test/integration/framework" ) @@ -50,33 +48,27 @@ const ( timeout = time.Second * 10 ) -func setup(t testing.TB, maxReadonlyRequestsInFlight, MaxMutatingRequestsInFlight int) (*httptest.Server, *rest.Config, framework.CloseFunc) { - opts := framework.ControlPlaneConfigOptions{EtcdOptions: framework.DefaultEtcdOptions()} - opts.EtcdOptions.DefaultStorageMediaType = "application/vnd.kubernetes.protobuf" - controlPlaneConfig := framework.NewIntegrationTestControlPlaneConfigWithOptions(&opts) - resourceConfig := controlplane.DefaultAPIResourceConfigSource() - resourceConfig.EnableVersions(schema.GroupVersion{ - Group: "flowcontrol.apiserver.k8s.io", - Version: "v1alpha1", +func setup(t testing.TB, maxReadonlyRequestsInFlight, MaxMutatingRequestsInFlight int) (*rest.Config, framework.TearDownFunc) { + _, kubeConfig, tearDownFn := framework.StartTestServer(t, framework.TestServerSetup{ + ModifyServerRunOptions: func(opts *options.ServerRunOptions) { + // Ensure all clients are allowed to send requests. + opts.Authorization.Modes = []string{"AlwaysAllow"} + opts.GenericServerRunOptions.MaxRequestsInFlight = maxReadonlyRequestsInFlight + opts.GenericServerRunOptions.MaxMutatingRequestsInFlight = MaxMutatingRequestsInFlight + }, }) - controlPlaneConfig.GenericConfig.MaxRequestsInFlight = maxReadonlyRequestsInFlight - controlPlaneConfig.GenericConfig.MaxMutatingRequestsInFlight = MaxMutatingRequestsInFlight - controlPlaneConfig.GenericConfig.OpenAPIConfig = framework.DefaultOpenAPIConfig() - controlPlaneConfig.ExtraConfig.APIResourceConfigSource = resourceConfig - _, s, closeFn := framework.RunAnAPIServer(controlPlaneConfig) - - return s, controlPlaneConfig.GenericConfig.LoopbackClientConfig, closeFn + return kubeConfig, tearDownFn } func TestPriorityLevelIsolation(t *testing.T) { defer featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, genericfeatures.APIPriorityAndFairness, true)() // NOTE: disabling the feature should fail the test - _, loopbackConfig, closeFn := setup(t, 1, 1) + kubeConfig, closeFn := setup(t, 1, 1) defer closeFn() - loopbackClient := clientset.NewForConfigOrDie(loopbackConfig) - noxu1Client := getClientFor(loopbackConfig, "noxu1") - noxu2Client := getClientFor(loopbackConfig, "noxu2") + loopbackClient := clientset.NewForConfigOrDie(kubeConfig) + noxu1Client := getClientFor(kubeConfig, "noxu1") + noxu2Client := getClientFor(kubeConfig, "noxu2") queueLength := 50 concurrencyShares := 1 @@ -153,13 +145,9 @@ func TestPriorityLevelIsolation(t *testing.T) { } func getClientFor(loopbackConfig *rest.Config, username string) clientset.Interface { - config := &rest.Config{ - Host: loopbackConfig.Host, - QPS: -1, - BearerToken: loopbackConfig.BearerToken, - Impersonate: rest.ImpersonationConfig{ - UserName: username, - }, + config := rest.CopyConfig(loopbackConfig) + config.Impersonate = rest.ImpersonationConfig{ + UserName: username, } return clientset.NewForConfigOrDie(config) } diff --git a/test/integration/apiserver/flowcontrol/fight_test.go b/test/integration/apiserver/flowcontrol/fight_test.go index 9f034521aef..84c0ad71ad4 100644 --- a/test/integration/apiserver/flowcontrol/fight_test.go +++ b/test/integration/apiserver/flowcontrol/fight_test.go @@ -170,10 +170,10 @@ func (ft *fightTest) evaluate(tBeforeCreate, tAfterCreate time.Time) { } func TestConfigConsumerFight(t *testing.T) { defer featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, genericfeatures.APIPriorityAndFairness, true)() - _, loopbackConfig, closeFn := setup(t, 100, 100) + kubeConfig, closeFn := setup(t, 100, 100) defer closeFn() const teamSize = 3 - ft := newFightTest(t, loopbackConfig, teamSize) + ft := newFightTest(t, kubeConfig, teamSize) tBeforeCreate := time.Now() ft.createMainInformer() ft.foreach(ft.createController) diff --git a/test/integration/apiserver/flowcontrol/fs_condition_test.go b/test/integration/apiserver/flowcontrol/fs_condition_test.go index 2ecc6db7858..f47ce82f3ce 100644 --- a/test/integration/apiserver/flowcontrol/fs_condition_test.go +++ b/test/integration/apiserver/flowcontrol/fs_condition_test.go @@ -38,10 +38,10 @@ import ( func TestConditionIsolation(t *testing.T) { defer featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, genericfeatures.APIPriorityAndFairness, true)() // NOTE: disabling the feature should fail the test - _, loopbackConfig, closeFn := setup(t, 10, 10) + kubeConfig, closeFn := setup(t, 10, 10) defer closeFn() - loopbackClient := clientset.NewForConfigOrDie(loopbackConfig) + loopbackClient := clientset.NewForConfigOrDie(kubeConfig) stopCh := make(chan struct{}) defer close(stopCh) diff --git a/test/integration/framework/test_server.go b/test/integration/framework/test_server.go index 558b527db3a..405ffb9e0a9 100644 --- a/test/integration/framework/test_server.go +++ b/test/integration/framework/test_server.go @@ -59,7 +59,7 @@ type TestServerSetup struct { type TearDownFunc func() // StartTestServer runs a kube-apiserver, optionally calling out to the setup.ModifyServerRunOptions and setup.ModifyServerConfig functions -func StartTestServer(t *testing.T, setup TestServerSetup) (client.Interface, *rest.Config, TearDownFunc) { +func StartTestServer(t testing.TB, setup TestServerSetup) (client.Interface, *rest.Config, TearDownFunc) { certDir, err := os.MkdirTemp("", "test-integration-"+strings.ReplaceAll(t.Name(), "/", "_")) if err != nil { t.Fatalf("Couldn't create temp dir: %v", err)