Documentation
¶
Overview ¶
Package envtest provides a test environment for testing code against a kcp control plane.
Index ¶
- Variables
- func Eventually(t TestingT, condition func() (success bool, reason string), ...)
- func EventuallyCondition(t TestingT, getter func() (conditions.Getter, error), ...)
- func EventuallyReady(t TestingT, getter func() (conditions.Getter, error), ...)
- func NewInitializingWorkspaceFixture(t TestingT, clusterClient kcpclient.ClusterClient, parent logicalcluster.Path, ...) (*tenancyv1alpha1.Workspace, logicalcluster.Path)
- func NewWorkspaceFixture(t TestingT, clusterClient kcpclient.ClusterClient, parent logicalcluster.Path, ...) (*tenancyv1alpha1.Workspace, logicalcluster.Path)
- func WorkspaceShard(ctx context.Context, kcpClient kcpclient.ClusterClient, ...) (*corev1alpha1.Shard, error)
- func WorkspaceShardOrDie(t TestingT, kcpClient kcpclient.ClusterClient, ws *tenancyv1alpha1.Workspace) *corev1alpha1.Shard
- type Arg
- type Arguments
- type AuthenticatedUser
- type Authn
- type ConditionEvaluator
- type Environment
- type Kcp
- type ListenAddr
- type SecureServing
- type Shard
- type TestingT
- type User
- type WorkspaceOption
- func WithLocation(w tenancyv1alpha1.WorkspaceLocation) WorkspaceOption
- func WithName(s string, formatArgs ...interface{}) WorkspaceOption
- func WithNamePrefix(prefix string) WorkspaceOption
- func WithRootShard() WorkspaceOption
- func WithShard(name string) WorkspaceOption
- func WithType(path logicalcluster.Path, name tenancyv1alpha1.WorkspaceTypeName) WorkspaceOption
Constants ¶
This section is empty.
Variables ¶
var ( // EmptyArguments constructs a new set of flags with nothing set. // // This is mostly useful for testing helper methods -- you'll want to call // Configure on the APIServer (or etcd) to configure their arguments. EmptyArguments = process.EmptyArguments )
Functions ¶
func Eventually ¶
func Eventually(t TestingT, condition func() (success bool, reason string), waitFor time.Duration, tick time.Duration, msgAndArgs ...interface{})
Eventually asserts that given condition will be met in waitFor time, periodically checking target function each tick. In addition to require.Eventually, this function t.Logs the reason string value returned by the condition function (eventually after 20% of the wait time) to aid in debugging.
func EventuallyCondition ¶
func EventuallyCondition(t TestingT, getter func() (conditions.Getter, error), evaluator *ConditionEvaluator, msgAndArgs ...interface{})
EventuallyCondition asserts that the object returned by getter() eventually has a condition that matches the evaluator.
func EventuallyReady ¶
func EventuallyReady(t TestingT, getter func() (conditions.Getter, error), msgAndArgs ...interface{})
EventuallyReady asserts that the object returned by getter() eventually has a ready condition.
func NewInitializingWorkspaceFixture ¶ added in v0.2.0
func NewInitializingWorkspaceFixture(t TestingT, clusterClient kcpclient.ClusterClient, parent logicalcluster.Path, options ...WorkspaceOption) (*tenancyv1alpha1.Workspace, logicalcluster.Path)
NewInitializingWorkspaceFixture creates a new workspace under the given parent using the given client, and waits for it to be stuck in the initializing phase.
func NewWorkspaceFixture ¶
func NewWorkspaceFixture(t TestingT, clusterClient kcpclient.ClusterClient, parent logicalcluster.Path, options ...WorkspaceOption) (*tenancyv1alpha1.Workspace, logicalcluster.Path)
NewWorkspaceFixture creates a new workspace under the given parent using the given client.
func WorkspaceShard ¶
func WorkspaceShard(ctx context.Context, kcpClient kcpclient.ClusterClient, ws *tenancyv1alpha1.Workspace) (*corev1alpha1.Shard, error)
WorkspaceShard returns the shard that a workspace is scheduled on.
func WorkspaceShardOrDie ¶
func WorkspaceShardOrDie(t TestingT, kcpClient kcpclient.ClusterClient, ws *tenancyv1alpha1.Workspace) *corev1alpha1.Shard
WorkspaceShardOrDie returns the shard that a workspace is scheduled on, or fails the test on error.
Types ¶
type AuthenticatedUser ¶
type AuthenticatedUser = controlplane.AuthenticatedUser
AuthenticatedUser represets a Kubernetes user that's been provisioned.
type Authn ¶
type Authn = controlplane.Authn
Authn is an authentication method that can be used with the control plane to provision users.
type ConditionEvaluator ¶
type ConditionEvaluator struct {
// contains filtered or unexported fields
}
ConditionEvaluator is a helper for evaluating conditions.
func Is ¶
func Is(conditionType conditionsv1alpha1.ConditionType, s corev1.ConditionStatus) *ConditionEvaluator
Is matches if the given condition type is of the given value.
func IsNot ¶
func IsNot(conditionType conditionsv1alpha1.ConditionType, s corev1.ConditionStatus) *ConditionEvaluator
IsNot matches if the given condition type is not of the given value.
func (*ConditionEvaluator) WithReason ¶
func (c *ConditionEvaluator) WithReason(reason string) *ConditionEvaluator
WithReason matches if the given condition type has the given reason.
type Environment ¶
type Environment struct {
// Kcp is the Kcp instance.
Kcp controlplane.Kcp
// Scheme is used to determine if conversion webhooks should be enabled
// for a particular CRD / object.
//
// Conversion webhooks are going to be enabled if an object in the scheme
// implements Hub and Spoke conversions.
//
// If nil, scheme.Scheme is used.
Scheme *runtime.Scheme
// Config can be used to talk to the apiserver. It's automatically
// populated if not set using the standard controller-runtime config
// loading.
Config *rest.Config
// BinaryAssetsDirectory is the path where the binaries required for the envtest are
// located in the local environment. This field can be overridden by setting TEST_KCP_ASSETS.
BinaryAssetsDirectory string
// UseExistingCluster indicates that this environments should use an
// existing kubeconfig, instead of trying to stand up a new kcp.
// It defaults to the USE_EXISTING_KCP environment variable if unspecified.
UseExistingKcp *bool
// ExistingKcpContext indicates that when UseExistingKcp is set to true,
// a specific context should be loaded from a kubeconfig instead of the
// current one. It defaults to the EXISTING_KCP_CONTEXT environment variable
// if unspecified.
ExistingKcpContext string
// KcpStartTimeout is the maximum duration each kcp component
// may take to start. It defaults to the TEST_KCP_START_TIMEOUT
// environment variable or 20 seconds if unspecified.
KcpStartTimeout time.Duration
// KcpStopTimeout is the maximum duration each kcp component
// may take to stop. It defaults to the TEST_KCP_STOP_TIMEOUT
// environment variable or 20 seconds if unspecified.
KcpStopTimeout time.Duration
// AttachKcpOutput indicates if kcp output will be attached to os.Stdout and os.Stderr.
// Enable this to get more visibility of the testing kcp.
// It respects the the TEST_ATTACH_KCP_OUTPUT environment variable.
AttachKcpOutput bool
}
Environment creates a Kubernetes test environment that will start / stop the Kubernetes control plane and install extension APIs.
func (*Environment) AddUser ¶
func (te *Environment) AddUser(user User, baseConfig *rest.Config) (*AuthenticatedUser, error)
AddUser provisions a new user for connecting to this Environment. The user will have the specified name & belong to the specified groups.
If you specify a "base" config, the returned REST Config will contain those settings as well as any required by the authentication method. You can use this to easily specify options like QPS.
This is effectively a convinience alias for Kcp.AddUser -- see that for more low-level details.
func (*Environment) Start ¶
func (te *Environment) Start() (*rest.Config, error)
Start starts a local Kubernetes server and updates te.ApiserverPort with the port it is listening on.
func (*Environment) Stop ¶
func (te *Environment) Stop() error
Stop stops a running server. Previously installed CRDs, as listed in CRDInstallOptions.CRDs, will be uninstalled if CRDInstallOptions.CleanUpAfterUse are set to true.
type Kcp ¶
type Kcp = controlplane.Kcp
Kcp is the re-exported Kcp type from the internal testing package.
type ListenAddr ¶
type ListenAddr = process.ListenAddr
ListenAddr indicates the address and port that the API server should listen on.
type SecureServing ¶
type SecureServing = controlplane.SecureServing
SecureServing contains details describing how the API server should serve its secure endpoint.
type Shard ¶
type Shard = controlplane.Shard
Shard is the re-exported Shard from the internal testing package.
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.
type User ¶
type User = controlplane.User
User represents a Kubernetes user to provision for auth purposes.
type WorkspaceOption ¶
type WorkspaceOption func(ws *tenancyv1alpha1.Workspace)
WorkspaceOption is an option for creating a workspace.
func WithLocation ¶
func WithLocation(w tenancyv1alpha1.WorkspaceLocation) WorkspaceOption
WithLocation sets the location of the workspace.
func WithName ¶
func WithName(s string, formatArgs ...interface{}) WorkspaceOption
WithName sets the name of the workspace.
func WithNamePrefix ¶
func WithNamePrefix(prefix string) WorkspaceOption
WithNamePrefix make the workspace be named with the given prefix plus "-".
func WithRootShard ¶
func WithRootShard() WorkspaceOption
WithRootShard schedules the workspace on the root shard.
func WithShard ¶
func WithShard(name string) WorkspaceOption
WithShard schedules the workspace on the given shard.
func WithType ¶
func WithType(path logicalcluster.Path, name tenancyv1alpha1.WorkspaceTypeName) WorkspaceOption
WithType sets the type of the workspace.