make client authentication optional for test kube-apiserver

This commit is contained in:
David Eads 2019-11-13 10:25:28 -05:00
parent 3aede35b3b
commit 3fbfe60ed2
2 changed files with 34 additions and 27 deletions

View File

@ -47,6 +47,9 @@ type TearDownFunc func()
type TestServerInstanceOptions struct { type TestServerInstanceOptions struct {
// DisableStorageCleanup Disable the automatic storage cleanup // DisableStorageCleanup Disable the automatic storage cleanup
DisableStorageCleanup bool DisableStorageCleanup bool
// Enable cert-auth for the kube-apiserver
EnableCertAuth bool
} }
// TestServer return values supplied by kube-test-ApiServer // TestServer return values supplied by kube-test-ApiServer
@ -68,6 +71,7 @@ type Logger interface {
func NewDefaultTestServerOptions() *TestServerInstanceOptions { func NewDefaultTestServerOptions() *TestServerInstanceOptions {
return &TestServerInstanceOptions{ return &TestServerInstanceOptions{
DisableStorageCleanup: false, DisableStorageCleanup: false,
EnableCertAuth: true,
} }
} }
@ -124,7 +128,8 @@ func StartTestServer(t Logger, instanceOptions *TestServerInstanceOptions, custo
} }
s.SecureServing.ServerCert.CertDirectory = result.TmpDir s.SecureServing.ServerCert.CertDirectory = result.TmpDir
// create optional certificates for aggregation and client-cert auth if instanceOptions.EnableCertAuth {
// create certificates for aggregation and client-cert auth
proxySigningKey, err := testutil.NewPrivateKey() proxySigningKey, err := testutil.NewPrivateKey()
if err != nil { if err != nil {
return result, err return result, err
@ -151,6 +156,8 @@ func StartTestServer(t Logger, instanceOptions *TestServerInstanceOptions, custo
return result, err return result, err
} }
s.Authentication.ClientCert.ClientCA = clientCACertFile s.Authentication.ClientCert.ClientCA = clientCACertFile
}
s.SecureServing.ExternalAddress = s.SecureServing.Listener.Addr().(*net.TCPAddr).IP // use listener addr although it is a loopback device s.SecureServing.ExternalAddress = s.SecureServing.Listener.Addr().(*net.TCPAddr).IP // use listener addr although it is a loopback device
_, thisFile, _, ok := runtime.Caller(0) _, thisFile, _, ok := runtime.Caller(0)

View File

@ -58,7 +58,7 @@ func TestAggregatedAPIServer(t *testing.T) {
stopCh := make(chan struct{}) stopCh := make(chan struct{})
defer close(stopCh) defer close(stopCh)
testServer := kastesting.StartTestServerOrDie(t, nil, nil, framework.SharedEtcd()) testServer := kastesting.StartTestServerOrDie(t, &kastesting.TestServerInstanceOptions{EnableCertAuth: true}, nil, framework.SharedEtcd())
defer testServer.TearDownFn() defer testServer.TearDownFn()
kubeClientConfig := rest.CopyConfig(testServer.ClientConfig) kubeClientConfig := rest.CopyConfig(testServer.ClientConfig)
// force json because everything speaks it // force json because everything speaks it