Documentation
¶
Index ¶
- Variables
- func Command(executableName, identity string) []string
- func GetFreePort(t TestingT) (string, error)
- func LoadKubeConfig(kubeconfigPath, contextName string) (clientcmd.ClientConfig, error)
- func MonitorEndpoints(t TestingT, client *rest.Config, endpoints ...string)
- func ScrapeMetrics(ctx context.Context, cfg *rest.Config, ...) error
- func ScratchDirs(t TestingT) (string, string, error)
- func StartKcpCommand(identity string) []string
- func WaitForReady(ctx context.Context, cfg *rest.Config) error
- func WaitLoadKubeConfig(ctx context.Context, kubeconfigPath, contextName string) (clientcmd.ClientConfig, error)
- type Config
- type Fixture
- type KcpRunner
- type Option
- func WithBindAddress(addr string) Option
- func WithClientCA(clientCADir string) Option
- func WithCustomArguments(args ...string) Option
- func WithDefaultsFrom(t TestingT) Option
- func WithLogToConsole() Option
- func WithRunInProcess() Option
- func WithScratchDirectories(artifactDir, dataDir string) Option
- type RunningServer
- type TestingT
Constants ¶
This section is empty.
Variables ¶
var ErrEmptyKubeConfig = fmt.Errorf("kubeconfig is empty")
var RunInProcessFunc func(t TestingT, dataDir string, args []string) (<-chan struct{}, error)
RunInProcessFunc instantiates the kcp server in process for easier debugging. It is here to decouple the rest of the code from kcp core dependencies. Deprecated: Use ContextRunInProcessFunc instead.
Functions ¶
func Command ¶
Command returns the string tokens required to start the given executable in the currently configured mode (direct or via `go run`).
func GetFreePort ¶
GetFreePort asks the kernel for a free open port that is ready to use.
func LoadKubeConfig ¶ added in v0.28.0
func LoadKubeConfig(kubeconfigPath, contextName string) (clientcmd.ClientConfig, error)
LoadKubeConfig loads a kubeconfig from disk. This method is intended to be common between fixture for servers whose lifecycle is test-managed and fixture for servers whose lifecycle is managed separately from a test run.
func MonitorEndpoints ¶
MonitorEndpoints keeps watching the given endpoints and fails t on error.
func ScrapeMetrics ¶
func ScratchDirs ¶
ScratchDirs determines where artifacts and data should live for a test server. The passed subDir is appended to the artifact directory and should be unique to the test.
func StartKcpCommand ¶
StartKcpCommand returns the string tokens required to start kcp in the currently configured mode (direct or via `go run`).
func WaitForReady ¶
WaitForReady waits for /livez and then /readyz to return success.
func WaitLoadKubeConfig ¶ added in v0.28.0
func WaitLoadKubeConfig(ctx context.Context, kubeconfigPath, contextName string) (clientcmd.ClientConfig, error)
WaitLoadKubeConfig wraps LoadKubeConfig and waits until the context is cancelled, two minutes have passed, or the kubeconfig file is loaded without error.
Types ¶
type Config ¶
type Config struct { Name string Args []string ArtifactDir string DataDir string ClientCADir string BindAddress string LogToConsole bool RunInProcess bool }
Config qualify a kcp server to start
Deprecated for use outside this package. Prefer PrivateKcpServer().
func (Config) KubeconfigPath ¶ added in v0.28.0
type Fixture ¶
type Fixture = map[string]RunningServer
Fixture manages the lifecycle of a set of kcp servers.
Deprecated for use outside this package. Prefer PrivateKcpServer().
func NewFixture ¶
NewFixture returns a new kcp server fixture.
type KcpRunner ¶ added in v0.28.0
var ContextRunInProcessFunc KcpRunner = func(ctx context.Context, t TestingT, cfg Config) (<-chan struct{}, error) { return nil, fmt.Errorf("not implemented") }
ContextRunInProcessFunc instantiates the kcp server in process for easier debugging. It is here to decouple the rest of the code from kcp core dependencies.
type Option ¶
type Option func(*Config)
Option a function that wish to modify a given kcp configuration.
func WithBindAddress ¶ added in v0.28.0
WithBindAddress sets the kcp server to log to console.
func WithClientCA ¶
WithClientCA sets the client CA directory for a given kcp configuration. A client CA will automatically created and the --client-ca configured.
func WithCustomArguments ¶
WithCustomArguments applies provided arguments to a given kcp configuration.
func WithDefaultsFrom ¶ added in v0.28.0
WithDefaultsFrom sets defaults on Config based off of the passed TestingT.
func WithLogToConsole ¶
func WithLogToConsole() Option
WithLogToConsole sets the kcp server to log to console.
func WithRunInProcess ¶
func WithRunInProcess() Option
WithRunInProcess sets the kcp server to run in process. This requires extra setup of the RunInProcessFunc variable and will only work inside of the kcp repository.
func WithScratchDirectories ¶
WithScratchDirectories adds custom scratch directories to a kcp configuration.
type RunningServer ¶
type RunningServer interface { Name() string KubeconfigPath() string RawConfig() (clientcmdapi.Config, error) BaseConfig(t TestingT) *rest.Config RootShardSystemMasterBaseConfig(t TestingT) *rest.Config ShardSystemMasterBaseConfig(t TestingT, shard string) *rest.Config ShardNames() []string Artifact(t TestingT, producer func() (runtime.Object, error)) ClientCAUserConfig(t TestingT, config *rest.Config, name string, groups ...string) *rest.Config CADirectory() string // Stop signals the server to shutdown and waits until it finishes. // Stop is a noop for external servers. Stop() // Stopped returns true if the server has ran and stopped. // Stopped is a noop for external servers. Stopped() bool }
func NewExternalKCPServer ¶
func NewExternalKCPServer(name, kubeconfigPath string, shardKubeconfigPaths map[string]string, clientCADir string) (RunningServer, error)
NewExternalKCPServer returns a RunningServer for a kubeconfig pointing to a kcp instance not managed by the test run. Since the kubeconfig is expected to exist prior to running tests against it, the configuration can be loaded synchronously and no locking is required to subsequently access it.
type TestingT ¶
type TestingT interface { Cleanup(func()) Error(args ...any) Errorf(format string, args ...any) FailNow() Failed() bool Fatal(args ...any) Fatalf(format string, args ...any) Helper() Log(args ...any) Logf(format string, args ...any) Name() string TempDir() string }
TestingT is implemented by *testing.T and potentially other test frameworks.