kubernetesk8s.io/kubernetes/cmd/kube-apiserver/app/testing Index | Files

package testing

import "k8s.io/kubernetes/cmd/kube-apiserver/app/testing"

Index

Types

type Logger

type Logger interface {
	Helper()
	Errorf(format string, args ...interface{})
	Fatalf(format string, args ...interface{})
	Logf(format string, args ...interface{})
	Cleanup(func())
}

Logger allows t.Testing and b.Testing to be passed to StartTestServer and StartTestServerOrDie

type ProxyCA

type ProxyCA struct {
	ProxySigningCert *x509.Certificate
	ProxySigningKey  *rsa.PrivateKey
}

ProxyCA contains the certificate authority certificate and key which is used to verify client connections to kube-apiservers. The clients can be : 1. aggregated apiservers 2. peer kube-apiservers

type TearDownFunc

type TearDownFunc func()

TearDownFunc is to be called to tear down a test server.

type TestServer

type TestServer struct {
	ClientConfig      *restclient.Config        // Rest client config
	ServerOpts        *options.ServerRunOptions // ServerOpts
	TearDownFn        TearDownFunc              // TearDown function
	TmpDir            string                    // Temp Dir used, by the apiserver
	EtcdClient        *clientv3.Client          // used by tests that need to check data migrated from APIs that are no longer served
	EtcdStoragePrefix string                    // storage prefix in etcd
}

TestServer return values supplied by kube-test-ApiServer

func StartTestServer

func StartTestServer(t ktesting.TB, instanceOptions *TestServerInstanceOptions, customFlags []string, storageConfig *storagebackend.Config) (result TestServer, err error)

StartTestServer starts a etcd server and kube-apiserver. A rest client config and a tear-down func, and location of the tmpdir are returned.

Note: we return a tear-down func instead of a stop channel because the later will leak temporary files that because Golang testing's call to os.Exit will not give a stop channel go routine enough time to remove temporary files.

func StartTestServerOrDie

func StartTestServerOrDie(t testing.TB, instanceOptions *TestServerInstanceOptions, flags []string, storageConfig *storagebackend.Config) *TestServer

StartTestServerOrDie calls StartTestServer t.Fatal if it does not succeed.

type TestServerInstanceOptions

type TestServerInstanceOptions struct {
	// SkipHealthzCheck returns without waiting for the server to become healthy.
	// Useful for testing server configurations expected to prevent /healthz from completing.
	SkipHealthzCheck bool
	// Enable cert-auth for the kube-apiserver
	EnableCertAuth bool
	// Wrap the storage version interface of the created server's generic server.
	StorageVersionWrapFunc func(storageversion.Manager) storageversion.Manager

	// We specify this as on option to pass a common proxyCA to multiple apiservers to simulate
	// an apiserver version skew scenario where all apiservers use the same proxyCA to verify client connections.
	ProxyCA *ProxyCA
	// Set the BinaryVersion of server effective version.
	// If empty, effective version will default to DefaultKubeEffectiveVersion.
	BinaryVersion string
	// Set non-default request timeout in the server.
	RequestTimeout time.Duration
}

TestServerInstanceOptions Instance options the TestServer

func NewDefaultTestServerOptions

func NewDefaultTestServerOptions() *TestServerInstanceOptions

NewDefaultTestServerOptions Default options for TestServer instances

Source Files

testserver.go

Version
v1.33.0 (latest)
Published
Apr 23, 2025
Platform
linux/amd64
Imports
47 packages
Last checked
3 hours ago

Tools for package owners.