mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-22 03:11:40 +00:00
Merge pull request #102270 from mengjiao-liu/update-term-control-plane
Part1: master to controlplane in test/integration(1.22)
This commit is contained in:
commit
9d6e5049bb
@ -87,19 +87,19 @@ func alwaysEmpty(req *http.Request) (*authauthenticator.Response, bool, error) {
|
||||
}, true, nil
|
||||
}
|
||||
|
||||
// MasterReceiver can be used to provide the master to a custom incoming server function
|
||||
type MasterReceiver interface {
|
||||
// APIServerReceiver can be used to provide the API server to a custom incoming server function
|
||||
type APIServerReceiver interface {
|
||||
SetMaster(m *controlplane.Instance)
|
||||
}
|
||||
|
||||
// MasterHolder implements
|
||||
type MasterHolder struct {
|
||||
// APIServerHolder implements
|
||||
type APIServerHolder struct {
|
||||
Initialized chan struct{}
|
||||
M *controlplane.Instance
|
||||
}
|
||||
|
||||
// SetMaster assigns the current master.
|
||||
func (h *MasterHolder) SetMaster(m *controlplane.Instance) {
|
||||
func (h *APIServerHolder) SetMaster(m *controlplane.Instance) {
|
||||
h.M = m
|
||||
close(h.Initialized)
|
||||
}
|
||||
@ -124,7 +124,7 @@ func DefaultOpenAPIConfig() *openapicommon.Config {
|
||||
}
|
||||
|
||||
// startApiserverOrDie starts a kubernetes master and an httpserver to handle api requests
|
||||
func startApiserverOrDie(controlPlaneConfig *controlplane.Config, incomingServer *httptest.Server, masterReceiver MasterReceiver) (*controlplane.Instance, *httptest.Server, CloseFunc) {
|
||||
func startApiserverOrDie(controlPlaneConfig *controlplane.Config, incomingServer *httptest.Server, apiServerReceiver APIServerReceiver) (*controlplane.Instance, *httptest.Server, CloseFunc) {
|
||||
var m *controlplane.Instance
|
||||
var s *httptest.Server
|
||||
|
||||
@ -214,8 +214,8 @@ func startApiserverOrDie(controlPlaneConfig *controlplane.Config, incomingServer
|
||||
closeFn()
|
||||
klog.Fatalf("error in bringing up the master: %v", err)
|
||||
}
|
||||
if masterReceiver != nil {
|
||||
masterReceiver.SetMaster(m)
|
||||
if apiServerReceiver != nil {
|
||||
apiServerReceiver.SetMaster(m)
|
||||
}
|
||||
|
||||
// TODO have this start method actually use the normal start sequence for the API server
|
||||
@ -351,8 +351,8 @@ func RunAnAPIServer(masterConfig *controlplane.Config) (*controlplane.Instance,
|
||||
}
|
||||
|
||||
// RunAnAPIServerUsingServer starts up an instance using the provided config on the specified server.
|
||||
func RunAnAPIServerUsingServer(controlPlaneConfig *controlplane.Config, s *httptest.Server, masterReceiver MasterReceiver) (*controlplane.Instance, *httptest.Server, CloseFunc) {
|
||||
return startApiserverOrDie(controlPlaneConfig, s, masterReceiver)
|
||||
func RunAnAPIServerUsingServer(controlPlaneConfig *controlplane.Config, s *httptest.Server, apiServerReceiver APIServerReceiver) (*controlplane.Instance, *httptest.Server, CloseFunc) {
|
||||
return startApiserverOrDie(controlPlaneConfig, s, apiServerReceiver)
|
||||
}
|
||||
|
||||
// SharedEtcd creates a storage config for a shared etcd instance, with a unique prefix.
|
||||
|
@ -608,7 +608,7 @@ func createJobWithDefaults(ctx context.Context, clientSet clientset.Interface, n
|
||||
|
||||
func setup(t *testing.T, nsBaseName string) (framework.CloseFunc, *restclient.Config, clientset.Interface, *v1.Namespace) {
|
||||
masterConfig := framework.NewIntegrationTestControlPlaneConfig()
|
||||
_, server, masterCloseFn := framework.RunAnAPIServer(masterConfig)
|
||||
_, server, apiServerCloseFn := framework.RunAnAPIServer(masterConfig)
|
||||
|
||||
config := restclient.Config{Host: server.URL}
|
||||
clientSet, err := clientset.NewForConfig(&config)
|
||||
@ -618,7 +618,7 @@ func setup(t *testing.T, nsBaseName string) (framework.CloseFunc, *restclient.Co
|
||||
ns := framework.CreateTestingNamespace(nsBaseName, server, t)
|
||||
closeFn := func() {
|
||||
framework.DeleteTestingNamespace(ns, server, t)
|
||||
masterCloseFn()
|
||||
apiServerCloseFn()
|
||||
}
|
||||
return closeFn, &config, clientSet, ns
|
||||
}
|
||||
|
@ -434,9 +434,9 @@ func verifyEndpointsWithIPs(servers []*kubeapiservertesting.TestServer, ips []st
|
||||
return reflect.DeepEqual(listenAddresses, ips)
|
||||
}
|
||||
|
||||
func testReconcilersMasterLease(t *testing.T, leaseCount int, masterCount int) {
|
||||
func testReconcilersMasterLease(t *testing.T, leaseCount int, apiServerCount int) {
|
||||
var leaseServers = make([]*kubeapiservertesting.TestServer, leaseCount)
|
||||
var masterCountServers = make([]*kubeapiservertesting.TestServer, masterCount)
|
||||
var apiServerCountServers = make([]*kubeapiservertesting.TestServer, apiServerCount)
|
||||
etcd := framework.SharedEtcd()
|
||||
|
||||
instanceOptions := &kubeapiservertesting.TestServerInstanceOptions{
|
||||
@ -447,25 +447,25 @@ func testReconcilersMasterLease(t *testing.T, leaseCount int, masterCount int) {
|
||||
defer registry.CleanupStorage()
|
||||
|
||||
wg := sync.WaitGroup{}
|
||||
// 1. start masterCount api servers
|
||||
for i := 0; i < masterCount; i++ {
|
||||
// start master count api server
|
||||
// 1. start apiServerCount api servers
|
||||
for i := 0; i < apiServerCount; i++ {
|
||||
// start count api server
|
||||
wg.Add(1)
|
||||
go func(i int) {
|
||||
defer wg.Done()
|
||||
server := kubeapiservertesting.StartTestServerOrDie(t, instanceOptions, []string{
|
||||
"--endpoint-reconciler-type", "master-count",
|
||||
"--advertise-address", fmt.Sprintf("10.0.1.%v", i+1),
|
||||
"--apiserver-count", fmt.Sprintf("%v", masterCount),
|
||||
"--apiserver-count", fmt.Sprintf("%v", apiServerCount),
|
||||
}, etcd)
|
||||
masterCountServers[i] = server
|
||||
apiServerCountServers[i] = server
|
||||
}(i)
|
||||
}
|
||||
wg.Wait()
|
||||
|
||||
// 2. verify master count servers have registered
|
||||
if err := wait.PollImmediate(3*time.Second, 2*time.Minute, func() (bool, error) {
|
||||
client, err := kubernetes.NewForConfig(masterCountServers[0].ClientConfig)
|
||||
client, err := kubernetes.NewForConfig(apiServerCountServers[0].ClientConfig)
|
||||
if err != nil {
|
||||
t.Logf("error creating client: %v", err)
|
||||
return false, nil
|
||||
@ -475,7 +475,7 @@ func testReconcilersMasterLease(t *testing.T, leaseCount int, masterCount int) {
|
||||
t.Logf("error fetching endpoints: %v", err)
|
||||
return false, nil
|
||||
}
|
||||
return verifyEndpointsWithIPs(masterCountServers, getEndpointIPs(endpoints)), nil
|
||||
return verifyEndpointsWithIPs(apiServerCountServers, getEndpointIPs(endpoints)), nil
|
||||
}); err != nil {
|
||||
t.Fatalf("master count endpoints failed to register: %v", err)
|
||||
}
|
||||
@ -502,8 +502,8 @@ func testReconcilersMasterLease(t *testing.T, leaseCount int, masterCount int) {
|
||||
|
||||
time.Sleep(3 * time.Second)
|
||||
|
||||
// 4. Shutdown the masterCount server
|
||||
for _, server := range masterCountServers {
|
||||
// 4. Shutdown the apiServerCount server
|
||||
for _, server := range apiServerCountServers {
|
||||
server.TearDownFn()
|
||||
}
|
||||
|
||||
|
@ -54,8 +54,8 @@ import (
|
||||
// quota_test.go:100: Took 4.196205966s to scale up without quota
|
||||
// quota_test.go:115: Took 12.021640372s to scale up with quota
|
||||
func TestQuota(t *testing.T) {
|
||||
// Set up a master
|
||||
h := &framework.MasterHolder{Initialized: make(chan struct{})}
|
||||
// Set up a 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)
|
||||
@ -245,8 +245,8 @@ func scale(t *testing.T, namespace string, clientset *clientset.Clientset) {
|
||||
}
|
||||
|
||||
func TestQuotaLimitedResourceDenial(t *testing.T) {
|
||||
// Set up a master
|
||||
h := &framework.MasterHolder{Initialized: make(chan struct{})}
|
||||
// Set up an 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)
|
||||
|
@ -322,7 +322,7 @@ func TestServiceAccountTokenAuthentication(t *testing.T) {
|
||||
// It is the responsibility of the caller to ensure the returned stopFunc is called
|
||||
func startServiceAccountTestServer(t *testing.T) (*clientset.Clientset, restclient.Config, func(), error) {
|
||||
// Listener
|
||||
h := &framework.MasterHolder{Initialized: make(chan struct{})}
|
||||
h := &framework.APIServerHolder{Initialized: make(chan struct{})}
|
||||
apiServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
|
||||
<-h.Initialized
|
||||
h.M.GenericAPIServer.Handler.ServeHTTP(w, req)
|
||||
|
@ -56,7 +56,7 @@ 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.
|
||||
func StartApiserver() (string, ShutdownFunc) {
|
||||
h := &framework.MasterHolder{Initialized: make(chan struct{})}
|
||||
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)
|
||||
@ -329,8 +329,8 @@ func InitTestMaster(t *testing.T, nsPrefix string, admission admission.Interface
|
||||
CancelFn: cancelFunc,
|
||||
}
|
||||
|
||||
// 1. Create master
|
||||
h := &framework.MasterHolder{Initialized: make(chan struct{})}
|
||||
// 1. Create control plane
|
||||
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)
|
||||
|
@ -64,8 +64,8 @@ func initTestMaster(t *testing.T, nsPrefix string, admission admission.Interface
|
||||
cancelFn: cancelFunc,
|
||||
}
|
||||
|
||||
// 1. Create master
|
||||
h := &framework.MasterHolder{Initialized: make(chan struct{})}
|
||||
// 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)
|
||||
|
Loading…
Reference in New Issue
Block a user