mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-01 15:58:37 +00:00
Clean shutdown of flowcontrol integration tests
This commit is contained in:
parent
57242e3cbb
commit
6b59525746
@ -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)
|
||||
}
|
||||
|
@ -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)
|
||||
|
@ -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)
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user