mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-21 10:51:29 +00:00
Unify apiserver startup in integration tests
This commit is contained in:
parent
e8ac6d8a8e
commit
d1c9042f57
@ -20,7 +20,6 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
|
||||||
"net/http/httptest"
|
"net/http/httptest"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
@ -68,18 +67,11 @@ type ShutdownFunc func()
|
|||||||
|
|
||||||
// StartApiserver starts a local API server for testing and returns the handle to the URL and the shutdown function to stop it.
|
// StartApiserver starts a local API server for testing and returns the handle to the URL and the shutdown function to stop it.
|
||||||
func StartApiserver() (string, ShutdownFunc) {
|
func StartApiserver() (string, ShutdownFunc) {
|
||||||
h := &framework.APIServerHolder{Initialized: make(chan struct{})}
|
_, s, closeFn := framework.RunAnAPIServer(framework.NewIntegrationTestControlPlaneConfig())
|
||||||
s := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
|
|
||||||
<-h.Initialized
|
|
||||||
h.M.GenericAPIServer.Handler.ServeHTTP(w, req)
|
|
||||||
}))
|
|
||||||
|
|
||||||
_, _, closeFn := framework.RunAnAPIServerUsingServer(framework.NewIntegrationTestControlPlaneConfig(), s, h)
|
|
||||||
|
|
||||||
shutdownFunc := func() {
|
shutdownFunc := func() {
|
||||||
klog.Infof("destroying API server")
|
klog.Infof("destroying API server")
|
||||||
closeFn()
|
closeFn()
|
||||||
s.Close()
|
|
||||||
klog.Infof("destroyed API server")
|
klog.Infof("destroyed API server")
|
||||||
}
|
}
|
||||||
return s.URL, shutdownFunc
|
return s.URL, shutdownFunc
|
||||||
|
@ -18,7 +18,6 @@ package volumescheduling
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"net/http"
|
|
||||||
"net/http/httptest"
|
"net/http/httptest"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
@ -63,12 +62,6 @@ func initTestAPIServer(t *testing.T, nsPrefix string, admission admission.Interf
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 1. Create API server
|
// 1. Create API server
|
||||||
h := &framework.APIServerHolder{Initialized: make(chan struct{})}
|
|
||||||
s := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
|
|
||||||
<-h.Initialized
|
|
||||||
h.M.GenericAPIServer.Handler.ServeHTTP(w, req)
|
|
||||||
}))
|
|
||||||
|
|
||||||
controlPlaneConfig := framework.NewIntegrationTestControlPlaneConfig()
|
controlPlaneConfig := framework.NewIntegrationTestControlPlaneConfig()
|
||||||
resourceConfig := controlplane.DefaultAPIResourceConfigSource()
|
resourceConfig := controlplane.DefaultAPIResourceConfigSource()
|
||||||
controlPlaneConfig.ExtraConfig.APIResourceConfigSource = resourceConfig
|
controlPlaneConfig.ExtraConfig.APIResourceConfigSource = resourceConfig
|
||||||
@ -77,7 +70,8 @@ func initTestAPIServer(t *testing.T, nsPrefix string, admission admission.Interf
|
|||||||
controlPlaneConfig.GenericConfig.AdmissionControl = admission
|
controlPlaneConfig.GenericConfig.AdmissionControl = admission
|
||||||
}
|
}
|
||||||
|
|
||||||
_, testCtx.httpServer, testCtx.closeFn = framework.RunAnAPIServerUsingServer(controlPlaneConfig, s, h)
|
_, testCtx.httpServer, testCtx.closeFn = framework.RunAnAPIServer(controlPlaneConfig)
|
||||||
|
s := testCtx.httpServer
|
||||||
|
|
||||||
if nsPrefix != "default" {
|
if nsPrefix != "default" {
|
||||||
testCtx.ns = framework.CreateTestingNamespace(nsPrefix+string(uuid.NewUUID()), s, t)
|
testCtx.ns = framework.CreateTestingNamespace(nsPrefix+string(uuid.NewUUID()), s, t)
|
||||||
|
Loading…
Reference in New Issue
Block a user