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:
Kubernetes Prow Robot 2021-06-03 08:19:38 -07:00 committed by GitHub
commit 9d6e5049bb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 33 additions and 33 deletions

View File

@ -87,19 +87,19 @@ func alwaysEmpty(req *http.Request) (*authauthenticator.Response, bool, error) {
}, true, nil }, true, nil
} }
// MasterReceiver can be used to provide the master to a custom incoming server function // APIServerReceiver can be used to provide the API server to a custom incoming server function
type MasterReceiver interface { type APIServerReceiver interface {
SetMaster(m *controlplane.Instance) SetMaster(m *controlplane.Instance)
} }
// MasterHolder implements // APIServerHolder implements
type MasterHolder struct { type APIServerHolder struct {
Initialized chan struct{} Initialized chan struct{}
M *controlplane.Instance M *controlplane.Instance
} }
// SetMaster assigns the current master. // SetMaster assigns the current master.
func (h *MasterHolder) SetMaster(m *controlplane.Instance) { func (h *APIServerHolder) SetMaster(m *controlplane.Instance) {
h.M = m h.M = m
close(h.Initialized) close(h.Initialized)
} }
@ -124,7 +124,7 @@ func DefaultOpenAPIConfig() *openapicommon.Config {
} }
// startApiserverOrDie starts a kubernetes master and an httpserver to handle api requests // 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 m *controlplane.Instance
var s *httptest.Server var s *httptest.Server
@ -214,8 +214,8 @@ func startApiserverOrDie(controlPlaneConfig *controlplane.Config, incomingServer
closeFn() closeFn()
klog.Fatalf("error in bringing up the master: %v", err) klog.Fatalf("error in bringing up the master: %v", err)
} }
if masterReceiver != nil { if apiServerReceiver != nil {
masterReceiver.SetMaster(m) apiServerReceiver.SetMaster(m)
} }
// TODO have this start method actually use the normal start sequence for the API server // 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. // 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) { func RunAnAPIServerUsingServer(controlPlaneConfig *controlplane.Config, s *httptest.Server, apiServerReceiver APIServerReceiver) (*controlplane.Instance, *httptest.Server, CloseFunc) {
return startApiserverOrDie(controlPlaneConfig, s, masterReceiver) return startApiserverOrDie(controlPlaneConfig, s, apiServerReceiver)
} }
// SharedEtcd creates a storage config for a shared etcd instance, with a unique prefix. // SharedEtcd creates a storage config for a shared etcd instance, with a unique prefix.

View File

@ -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) { func setup(t *testing.T, nsBaseName string) (framework.CloseFunc, *restclient.Config, clientset.Interface, *v1.Namespace) {
masterConfig := framework.NewIntegrationTestControlPlaneConfig() masterConfig := framework.NewIntegrationTestControlPlaneConfig()
_, server, masterCloseFn := framework.RunAnAPIServer(masterConfig) _, server, apiServerCloseFn := framework.RunAnAPIServer(masterConfig)
config := restclient.Config{Host: server.URL} config := restclient.Config{Host: server.URL}
clientSet, err := clientset.NewForConfig(&config) 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) ns := framework.CreateTestingNamespace(nsBaseName, server, t)
closeFn := func() { closeFn := func() {
framework.DeleteTestingNamespace(ns, server, t) framework.DeleteTestingNamespace(ns, server, t)
masterCloseFn() apiServerCloseFn()
} }
return closeFn, &config, clientSet, ns return closeFn, &config, clientSet, ns
} }

View File

@ -434,9 +434,9 @@ func verifyEndpointsWithIPs(servers []*kubeapiservertesting.TestServer, ips []st
return reflect.DeepEqual(listenAddresses, ips) 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 leaseServers = make([]*kubeapiservertesting.TestServer, leaseCount)
var masterCountServers = make([]*kubeapiservertesting.TestServer, masterCount) var apiServerCountServers = make([]*kubeapiservertesting.TestServer, apiServerCount)
etcd := framework.SharedEtcd() etcd := framework.SharedEtcd()
instanceOptions := &kubeapiservertesting.TestServerInstanceOptions{ instanceOptions := &kubeapiservertesting.TestServerInstanceOptions{
@ -447,25 +447,25 @@ func testReconcilersMasterLease(t *testing.T, leaseCount int, masterCount int) {
defer registry.CleanupStorage() defer registry.CleanupStorage()
wg := sync.WaitGroup{} wg := sync.WaitGroup{}
// 1. start masterCount api servers // 1. start apiServerCount api servers
for i := 0; i < masterCount; i++ { for i := 0; i < apiServerCount; i++ {
// start master count api server // start count api server
wg.Add(1) wg.Add(1)
go func(i int) { go func(i int) {
defer wg.Done() defer wg.Done()
server := kubeapiservertesting.StartTestServerOrDie(t, instanceOptions, []string{ server := kubeapiservertesting.StartTestServerOrDie(t, instanceOptions, []string{
"--endpoint-reconciler-type", "master-count", "--endpoint-reconciler-type", "master-count",
"--advertise-address", fmt.Sprintf("10.0.1.%v", i+1), "--advertise-address", fmt.Sprintf("10.0.1.%v", i+1),
"--apiserver-count", fmt.Sprintf("%v", masterCount), "--apiserver-count", fmt.Sprintf("%v", apiServerCount),
}, etcd) }, etcd)
masterCountServers[i] = server apiServerCountServers[i] = server
}(i) }(i)
} }
wg.Wait() wg.Wait()
// 2. verify master count servers have registered // 2. verify master count servers have registered
if err := wait.PollImmediate(3*time.Second, 2*time.Minute, func() (bool, error) { 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 { if err != nil {
t.Logf("error creating client: %v", err) t.Logf("error creating client: %v", err)
return false, nil return false, nil
@ -475,7 +475,7 @@ func testReconcilersMasterLease(t *testing.T, leaseCount int, masterCount int) {
t.Logf("error fetching endpoints: %v", err) t.Logf("error fetching endpoints: %v", err)
return false, nil return false, nil
} }
return verifyEndpointsWithIPs(masterCountServers, getEndpointIPs(endpoints)), nil return verifyEndpointsWithIPs(apiServerCountServers, getEndpointIPs(endpoints)), nil
}); err != nil { }); err != nil {
t.Fatalf("master count endpoints failed to register: %v", err) 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) time.Sleep(3 * time.Second)
// 4. Shutdown the masterCount server // 4. Shutdown the apiServerCount server
for _, server := range masterCountServers { for _, server := range apiServerCountServers {
server.TearDownFn() server.TearDownFn()
} }

View File

@ -54,8 +54,8 @@ import (
// quota_test.go:100: Took 4.196205966s to scale up without quota // quota_test.go:100: Took 4.196205966s to scale up without quota
// quota_test.go:115: Took 12.021640372s to scale up with quota // quota_test.go:115: Took 12.021640372s to scale up with quota
func TestQuota(t *testing.T) { func TestQuota(t *testing.T) {
// Set up a master // Set up a API server
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) { s := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
<-h.Initialized <-h.Initialized
h.M.GenericAPIServer.Handler.ServeHTTP(w, req) 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) { func TestQuotaLimitedResourceDenial(t *testing.T) {
// Set up a master // Set up an API server
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) { s := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
<-h.Initialized <-h.Initialized
h.M.GenericAPIServer.Handler.ServeHTTP(w, req) h.M.GenericAPIServer.Handler.ServeHTTP(w, req)

View File

@ -322,7 +322,7 @@ func TestServiceAccountTokenAuthentication(t *testing.T) {
// It is the responsibility of the caller to ensure the returned stopFunc is called // 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) { func startServiceAccountTestServer(t *testing.T) (*clientset.Clientset, restclient.Config, func(), error) {
// Listener // 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) { apiServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
<-h.Initialized <-h.Initialized
h.M.GenericAPIServer.Handler.ServeHTTP(w, req) h.M.GenericAPIServer.Handler.ServeHTTP(w, req)

View File

@ -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. // 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.MasterHolder{Initialized: make(chan struct{})} h := &framework.APIServerHolder{Initialized: make(chan struct{})}
s := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) { s := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
<-h.Initialized <-h.Initialized
h.M.GenericAPIServer.Handler.ServeHTTP(w, req) h.M.GenericAPIServer.Handler.ServeHTTP(w, req)
@ -329,8 +329,8 @@ func InitTestMaster(t *testing.T, nsPrefix string, admission admission.Interface
CancelFn: cancelFunc, CancelFn: cancelFunc,
} }
// 1. Create master // 1. Create control plane
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) { s := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
<-h.Initialized <-h.Initialized
h.M.GenericAPIServer.Handler.ServeHTTP(w, req) h.M.GenericAPIServer.Handler.ServeHTTP(w, req)

View File

@ -64,8 +64,8 @@ func initTestMaster(t *testing.T, nsPrefix string, admission admission.Interface
cancelFn: cancelFunc, cancelFn: cancelFunc,
} }
// 1. Create master // 1. Create API server
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) { s := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
<-h.Initialized <-h.Initialized
h.M.GenericAPIServer.Handler.ServeHTTP(w, req) h.M.GenericAPIServer.Handler.ServeHTTP(w, req)