framework

package
v0.20.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 30, 2023 License: Apache-2.0 Imports: 101 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var TestConfig *testConfig

Functions

func AdmitWorkspaceAccess

func AdmitWorkspaceAccess(ctx context.Context, t *testing.T, kubeClusterClient kcpkubernetesclientset.ClusterInterface, clusterName logicalcluster.Path, users []string, groups []string, admin bool)

AdmitWorkspaceAccess create RBAC rules that allow the given users and/or groups to access the given workspace, optionally as admin.

func ClientCAUserConfig

func ClientCAUserConfig(t *testing.T, cfg *rest.Config, clientCAConfigDirectory, username string, groups ...string) *rest.Config

ClientCAUserConfig returns a config based on a dynamically created client certificate. The returned client CA is signed by "test/e2e/framework/client-ca.crt".

func ConfigWithToken

func ConfigWithToken(token string, cfg *rest.Config) *rest.Config

func CreateClientCA

func CreateClientCA(t *testing.T) (string, string)

func CreateResources

func CreateResources(ctx context.Context, fs embed.FS, upstreamConfig *rest.Config, clusterName logicalcluster.Path, transformers ...helpers.TransformFileFunc) error

CreateResources creates all resources from a filesystem in the given workspace identified by upstreamConfig.

func CreateTempDirForTest

func CreateTempDirForTest(t *testing.T, dirName string) (string, error)

CreateTempDirForTest creates the named directory with a unique base path derived from the name of the current test.

func DirectOrGoRunCommand

func DirectOrGoRunCommand(executableName string) []string

DirectOrGoRunCommand returns the string tokens required to start the given executable in the currently configured mode (direct or via `go run`).

func Eventually

func Eventually(t *testing.T, 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 raason string value returned by the condition function (eventually after 20% of the wait time) to aid in debugging.

func EventuallyCondition

func EventuallyCondition(t *testing.T, 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 *testing.T, getter func() (conditions.Getter, error), msgAndArgs ...interface{})

EventuallyReady asserts that the object returned by getter() eventually has a ready condition.

func ExportVirtualWorkspaceURLs

func ExportVirtualWorkspaceURLs(export *apisv1alpha1.APIExport) []string

func GatherMetrics

func GatherMetrics(ctx context.Context, t *testing.T, server RunningServer, directory string)

func GetFreePort

func GetFreePort(t *testing.T) (string, error)

GetFreePort asks the kernel for a free open port that is ready to use.

func InProcessEnvSet

func InProcessEnvSet() bool

func Kubectl

func Kubectl(t *testing.T, kubeconfigPath string, args ...string) []byte

Kubectl runs kubectl with the given arguments and returns the combined stderr and stdout.

func KubectlApply

func KubectlApply(t *testing.T, kubeconfigPath string, input []byte) []byte

KubectlApply runs kubectl apply -f with the supplied input piped to stdin and returns the combined stderr and stdout output.

func LoadKubeConfig

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 LogToConsoleEnvSet

func LogToConsoleEnvSet() bool

func LogicalClusterRawConfig

func LogicalClusterRawConfig(rawConfig clientcmdapi.Config, logicalClusterName logicalcluster.Path, contextName string) clientcmdapi.Config

LogicalClusterRawConfig returns the raw cluster config of the given config.

func NewBindCompute

func NewBindCompute(t *testing.T, path logicalcluster.Path, server RunningServer, opts ...BindComputeOption) *bindCompute

func NewOrganizationFixture

func NewOrganizationFixture(t *testing.T, server RunningServer, options ...UnprivilegedWorkspaceOption) (logicalcluster.Path, *tenancyv1alpha1.Workspace)

func NewPrivilegedOrganizationFixture

func NewPrivilegedOrganizationFixture[O WorkspaceOption](t *testing.T, server RunningServer, options ...O) (logicalcluster.Path, *tenancyv1alpha1.Workspace)

func NewSyncerFixture

func NewSyncerFixture(t *testing.T, server RunningServer, path logicalcluster.Path, opts ...SyncerOption) *syncerFixture

func NewWorkspaceFixture

func NewWorkspaceFixture(t *testing.T, server RunningServer, parent logicalcluster.Path, options ...UnprivilegedWorkspaceOption) (logicalcluster.Path, *tenancyv1alpha1.Workspace)

func NoGoRunEnvSet

func NoGoRunEnvSet() bool

func RepositoryBinDir

func RepositoryBinDir() string

RepositoryBinDir returns the absolute path of <repo-dir>/bin. That's where `make build` produces our binaries.

func RepositoryDir

func RepositoryDir() string

RepositoryDir returns the absolute path of <repo-dir>.

func RunInProcess

func RunInProcess(o *runOptions)

func RunTMCCliPlugin

func RunTMCCliPlugin(t *testing.T, kubeconfigPath string, subcommand []string) []byte

RunTMCCliPlugin runs the tmc workspace plugin with the provided subcommand and returns the combined stderr and stdout output.

func ScrapeMetrics

func ScrapeMetrics(ctx context.Context, cfg *rest.Config, promUrl, promCfgDir, jobName, caFile string, labels map[string]string) error

func ScrapeMetricsForServer

func ScrapeMetricsForServer(t *testing.T, srv RunningServer)

func ScratchDirs

func ScratchDirs(t *testing.T) (string, string, error)

ScratchDirs determines where artifacts and data should live for a test server.

func StartKcpCommand

func StartKcpCommand() []string

StartKcpCommand returns the string tokens required to start kcp in the currently configured mode (direct or via `go run`).

func StaticTokenUserConfig

func StaticTokenUserConfig(username string, cfg *rest.Config) *rest.Config

StaticTokenUserConfig returns a user config based on static user tokens defined in "test/e2e/framework/auth-tokens.csv". The token being used is "[username]-token".

func Suite

func Suite(t *testing.T, suite string)

Suite should be called at the very beginning of a test case, to ensure that a test is only run when the suite containing it is selected by the user running tests.

func TestServerArgs

func TestServerArgs() []string

TestServerArgs returns the set of kcp args used to start a test server using the token auth file from the working tree.

func TestServerArgsWithTokenAuthFile

func TestServerArgsWithTokenAuthFile(tokenAuthFile string) []string

TestServerArgsWithTokenAuthFile returns the set of kcp args used to start a test server with the given token auth file.

func TestServerWithAuditPolicyFile

func TestServerWithAuditPolicyFile(auditPolicyFile string) []string

TestServerWithAuditPolicyFile returns the set of kcp args used to start a test server with the given audit policy file.

func TestServerWithClientCAFile

func TestServerWithClientCAFile(clientCAFile string) []string

func TmcCliPluginCommand

func TmcCliPluginCommand() []string

TmcCliPluginCommand returns the cli args to run the workspace plugin directly or via go run (depending on whether NO_GORUN is set).

func UniqueGroup

func UniqueGroup(suffix string) string

UniqueGroup returns a unique API group with the given suffix by prefixing some random 8 character base36 string. suffix must start with a dot if the random string should be dot-separated.

func VirtualWorkspaceURL

func VirtualWorkspaceURL(ctx context.Context, kcpClusterClient kcpclientset.ClusterInterface, ws *tenancyv1alpha1.Workspace, urls []string) (string, bool, error)

func VirtualWorkspaceURLOrDie

func VirtualWorkspaceURLOrDie(t *testing.T, kcpClusterClient kcpclientset.ClusterInterface, ws *tenancyv1alpha1.Workspace, urls []string) string

func WaitForReady

func WaitForReady(ctx context.Context, t *testing.T, cfg *rest.Config, keepMonitoring bool) error

func WithLogStreaming

func WithLogStreaming(o *runOptions)

func WriteEmbedFile

func WriteEmbedFile(t *testing.T, source string) string

func WriteLogicalClusterConfig

func WriteLogicalClusterConfig(t *testing.T, rawConfig clientcmdapi.Config, contextName string, clusterName logicalcluster.Path) (clientcmd.ClientConfig, string)

WriteLogicalClusterConfig creates a logical cluster config for the given config and cluster name and writes it to the test's artifact path. Useful for configuring the workspace plugin with --kubeconfig.

func WriteTokenAuthFile

func WriteTokenAuthFile(t *testing.T) string

WriteTokenAuthFile writes the embedded token file to the current test's data dir.

Persistent servers can target the file in the source tree with `--token-auth-file` and test-managed servers can target a file written to a temp path. This avoids requiring a test to know the location of the token file.

TODO(marun) Is there a way to avoid embedding by determining the path to the file during test execution?

Types

type Accessory

type Accessory struct {
	// contains filtered or unexported fields
}

Accessory knows how to run an executable with arguments for the duration of the context.

func NewAccessory

func NewAccessory(t *testing.T, artifactDir string, name string, cmd ...string) *Accessory

NewAccessory creates a new accessory process.

func (*Accessory) Run

func (a *Accessory) Run(t *testing.T, opts ...RunOption) error

type ArtifactFunc

type ArtifactFunc func(*testing.T, func() (runtime.Object, error))

type BindComputeOption

type BindComputeOption func(t *testing.T, w *bindCompute)

func WithAPIExportsWorkloadBindOption

func WithAPIExportsWorkloadBindOption(apiexports ...string) BindComputeOption

func WithLocationSelectorWorkloadBindOption

func WithLocationSelectorWorkloadBindOption(selectors ...metav1.LabelSelector) BindComputeOption

func WithLocationWorkspaceWorkloadBindOption

func WithLocationWorkspaceWorkloadBindOption(clusterName logicalcluster.Path) BindComputeOption

func WithNSSelectorWorkloadBindOption

func WithNSSelectorWorkloadBindOption(selector metav1.LabelSelector) BindComputeOption

func WithPlacementNameBindOption

func WithPlacementNameBindOption(placementName string) BindComputeOption

type ConditionEvaluator

type ConditionEvaluator struct {
	// contains filtered or unexported fields
}

func IsNot

func (*ConditionEvaluator) WithReason

func (c *ConditionEvaluator) WithReason(reason string) *ConditionEvaluator

type Expectation

type Expectation func(ctx context.Context) (done bool, err error)

Expectation closes over a statement of intent, allowing the caller to accumulate errors and determine when the expectation should cease to be evaluated.

type ExpectationController

type ExpectationController struct {
	// contains filtered or unexported fields
}

ExpectationController knows how to register expectations and trigger them.

func NewExpecter

func NewExpecter(informer cache.SharedIndexInformer) *ExpectationController

NewExpecter creates a informer-driven registry of expectations, which will be triggered on every event that the informer ingests.

func (*ExpectationController) ExpectBefore

func (c *ExpectationController) ExpectBefore(ctx context.Context, expectation Expectation, duration time.Duration) error

type Expecter

type Expecter interface {
	// ExpectBefore will result in the Expectation being evaluated whenever
	// state changes, up until the desired timeout is reached.
	ExpectBefore(context.Context, Expectation, time.Duration) error
}

Expecter allows callers to register expectations.

type PrivilegedWorkspaceOption

type PrivilegedWorkspaceOption func(ws *tenancyv1alpha1.Workspace)

func WithRequiredGroups

func WithRequiredGroups(groups ...string) PrivilegedWorkspaceOption

WithRequiredGroups is a privileged action, so we return a privileged option type, and only the helpers that use the system:master config can consume this. However, workspace initialization requires a valid user annotation on the workspace object to impersonate during initialization, and system:master bypasses setting that, so we end up needing to hard-code something conceivable.

type RegisterWorkspaceExpectation

type RegisterWorkspaceExpectation func(seed *tenancyv1alpha1.Workspace, expectation WorkspaceExpectation) error

RegisterWorkspaceExpectation registers an expectation about the future state of the seed.

func ExpectWorkspaces

func ExpectWorkspaces(
	ctx context.Context,
	t *testing.T,
	client kcpclient.Interface,
) (RegisterWorkspaceExpectation, error)

ExpectWorkspaces sets up an Expecter in order to allow registering expectations in tests with minimal setup.

type RegisterWorkspaceShardExpectation

type RegisterWorkspaceShardExpectation func(seed *corev1alpha1.Shard, expectation WorkspaceShardExpectation) error

RegisterWorkspaceShardExpectation registers an expectation about the future state of the seed.

func ExpectWorkspaceShards

func ExpectWorkspaceShards(ctx context.Context, t *testing.T, client kcpclient.Interface) (RegisterWorkspaceShardExpectation, error)

ExpectWorkspaceShards sets up an Expecter in order to allow registering expectations in tests with minimal setup.

type RunOption

type RunOption func(o *runOptions)

type RunningServer

type RunningServer interface {
	Name() string
	KubeconfigPath() string
	RawConfig() (clientcmdapi.Config, error)
	BaseConfig(t *testing.T) *rest.Config
	RootShardSystemMasterBaseConfig(t *testing.T) *rest.Config
	ShardSystemMasterBaseConfig(t *testing.T, shard string) *rest.Config
	ShardNames() []string
	Artifact(t *testing.T, producer func() (runtime.Object, error))
	ClientCAUserConfig(t *testing.T, config *rest.Config, name string, groups ...string) *rest.Config
	CADirectory() string
}

func NewFakeWorkloadServer

func NewFakeWorkloadServer(t *testing.T, server RunningServer, org logicalcluster.Path, syncTargetName string) RunningServer

NewFakeWorkloadServer creates a workspace in the provided server and org and creates a server fixture for the logical cluster that results.

func PrivateKcpServer

func PrivateKcpServer(t *testing.T, options ...TmcConfigOption) RunningServer

PrivateKcpServer returns a new kcp server fixture managing a new server process that is not intended to be shared between tests.

func SharedKcpServer

func SharedKcpServer(t *testing.T) RunningServer

SharedKcpServer returns a kcp server fixture intended to be shared between tests. A persistent server will be configured if `--kcp-kubeconfig` or `--use-default-kcp-server` is supplied to the test runner. Otherwise a test-managed server will be started. Only tests that are known to be hermetic are compatible with shared fixture.

type StartedSyncerFixture

type StartedSyncerFixture struct {
	// contains filtered or unexported fields
}

StartedSyncerFixture contains the configuration used to start a syncer and interact with its downstream cluster.

func (*StartedSyncerFixture) DownstreamNamespaceFor

func (sf *StartedSyncerFixture) DownstreamNamespaceFor(t *testing.T, upstreamWorkspace logicalcluster.Name, upstreamNamespace string) string

func (StartedSyncerFixture) StartAPIImporter

func (sf StartedSyncerFixture) StartAPIImporter(t *testing.T) *appliedSyncerFixture

StartAPIImporter starts the APIImporter the same way as the Syncer would have done if started. This will allow KCP to do the API compatibilitiy checks and update the SyncTarget accordingly. The real syncer is not started, and resource will be effectively synced after calling this method.

func (StartedSyncerFixture) StartHeartBeat

func (sf StartedSyncerFixture) StartHeartBeat(t *testing.T) *StartedSyncerFixture

StartHeartBeat starts the Heartbeat keeper to maintain the SyncTarget to the Ready state. No resource will be effectively synced after calling this method.

func (StartedSyncerFixture) StartSyncer

func (sf StartedSyncerFixture) StartSyncer(t *testing.T) *StartedSyncerFixture

StartSyncer starts a new Syncer against the upstream kcp workspaces Whether the syncer runs in-process or deployed on a pcluster will depend whether --pcluster-kubeconfig and --syncer-image are supplied to the test invocation.

func (StartedSyncerFixture) StartSyncerTunnel

func (sf StartedSyncerFixture) StartSyncerTunnel(t *testing.T) *StartedSyncerFixture

func (*StartedSyncerFixture) StopHeartBeat

func (sf *StartedSyncerFixture) StopHeartBeat(t *testing.T)

StopHeartBeat stop maintaining the heartbeat for this Syncer SyncTarget.

func (*StartedSyncerFixture) StopSyncerTunnel

func (sf *StartedSyncerFixture) StopSyncerTunnel(t *testing.T)

StopSyncerTunnel stops the syncer tunnel, the syncer will close the reverse connection and pod subresources will not be available anymore.

func (*StartedSyncerFixture) ToSyncTargetKey

func (sf *StartedSyncerFixture) ToSyncTargetKey() string

func (*StartedSyncerFixture) WaitForSyncTargetReady

func (sf *StartedSyncerFixture) WaitForSyncTargetReady(ctx context.Context, t *testing.T)

WaitForSyncTargetReady waits for the SyncTarget to be ready. The SyncTarget becoming ready indicates that the syncer on the related physical cluster is healthy and has successfully sent a heartbeat to kcp.

type SyncTargetOption

type SyncTargetOption func(cluster *workloadv1alpha1.SyncTarget)

type SyncerOption

type SyncerOption func(t *testing.T, fs *syncerFixture)

func WithAPIExports

func WithAPIExports(exports ...string) SyncerOption

func WithDownstreamPreparation

func WithDownstreamPreparation(prepare func(config *rest.Config, isFakePCluster bool)) SyncerOption

func WithExtraResources

func WithExtraResources(resources ...string) SyncerOption

func WithSyncTargetLabels

func WithSyncTargetLabels(labels map[string]string) SyncerOption

func WithSyncTargetName

func WithSyncTargetName(name string) SyncerOption

func WithSyncedUserWorkspaces

func WithSyncedUserWorkspaces(syncedUserWorkspaces ...*tenancyv1alpha1.Workspace) SyncerOption

type TmcConfigOption

type TmcConfigOption func(*tmcConfig) *tmcConfig

TmcConfigOption a function that wish to modify a given tmc configuration.

func WithCustomArguments

func WithCustomArguments(args ...string) TmcConfigOption

WithCustomArguments applies provided arguments to a given kcp configuration.

func WithScratchDirectories

func WithScratchDirectories(artifactDir, dataDir string) TmcConfigOption

WithScratchDirectories adds custom scratch directories to a kcp configuration.

type UnprivilegedWorkspaceOption

type UnprivilegedWorkspaceOption func(ws *tenancyv1alpha1.Workspace)

func TODO_WithoutMultiShardSupport

func TODO_WithoutMultiShardSupport() UnprivilegedWorkspaceOption

func WithName

func WithName(s string, formatArgs ...interface{}) UnprivilegedWorkspaceOption

func WithNameSuffix

func WithNameSuffix(suffix string) UnprivilegedWorkspaceOption

func WithRootShard

func WithRootShard() UnprivilegedWorkspaceOption

func WithShard

func WithShard(name string) UnprivilegedWorkspaceOption

func WithType

func WithType(path logicalcluster.Path, name tenancyv1alpha1.WorkspaceTypeName) UnprivilegedWorkspaceOption

type WorkspaceExpectation

type WorkspaceExpectation func(*tenancyv1alpha1.Workspace) error

WorkspaceExpectation evaluates an expectation about the object.

type WorkspaceOption

type WorkspaceOption interface {
	PrivilegedWorkspaceOption | UnprivilegedWorkspaceOption
}

type WorkspaceShardExpectation

type WorkspaceShardExpectation func(*corev1alpha1.Shard) error

WorkspaceShardExpectation evaluates an expectation about the object.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL