envtest

package
v0.104.0 Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2024 License: Apache-2.0 Imports: 39 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	InstallationGVK  schema.GroupVersionKind
	ExecutionGVK     schema.GroupVersionKind
	DeployItemGVK    schema.GroupVersionKind
	DataObjectGVK    schema.GroupVersionKind
	TargetGVK        schema.GroupVersionKind
	TargetSyncGVK    schema.GroupVersionKind
	ContextGVK       schema.GroupVersionKind
	SecretGVK        schema.GroupVersionKind
	ConfigMapGVK     schema.GroupVersionKind
	DeploymentGVK    schema.GroupVersionKind
	LSHealthCheckGVK schema.GroupVersionKind
)

Functions

func CleanupForDeployItem

func CleanupForDeployItem(ctx context.Context, log utils.Logger, c client.Client, obj *lsv1alpha1.DeployItem, timeout time.Duration) error

CleanupForDeployItem cleans up a deploy item from a cluster

func CleanupForExecution

func CleanupForExecution(ctx context.Context, log utils.Logger, c client.Client, obj *lsv1alpha1.Execution, timeout time.Duration) error

CleanupForExecution cleans up an execution from a cluster

func CleanupForObject

func CleanupForObject(ctx context.Context, log utils.Logger, c client.Client, obj client.Object, timeout time.Duration) error

CleanupForObject cleans up a object from a cluster

func NewRetryingClient

func NewRetryingClient(innerClient client.Client, log utils.Logger) client.Client

func RegisterFakeClientToMock

func RegisterFakeClientToMock(mockClient *mock_client.MockClient, fakeClient client.Client) error

RegisterFakeClientToMock adds fake client calls to a mockclient

func WaitForObjectToBeDeleted

func WaitForObjectToBeDeleted(ctx context.Context, log utils.Logger, c client.Client, obj client.Object, timeout time.Duration) error

WaitForObjectToBeDeleted waits for a object to be deleted.

Types

type CleanupOption

type CleanupOption interface {
	ApplyOption(options *CleanupOptions) error
}

type CleanupOptions

type CleanupOptions struct {
	// Timeout defines the timout to wait the cleanup of an object.
	Timeout *time.Duration
	// WaitForDeletion waits until all resources all successfully deleted.
	WaitForDeletion bool
	// RestConfig specify the rest config which is used to remove the namespace.
	RestConfig *rest.Config
}

func (*CleanupOptions) ApplyOptions

func (o *CleanupOptions) ApplyOptions(options ...CleanupOption) error

ApplyOptions applies all options from create options to the object

type CreateOption

type CreateOption interface {
	ApplyOption(options *CreateOptions) error
}

type CreateOptions

type CreateOptions struct {
	// UpdateStatus also updates the status after the objects creation
	UpdateStatus bool
}

func (*CreateOptions) ApplyOptions

func (o *CreateOptions) ApplyOptions(options ...CreateOption) error

ApplyOptions applies all options from create options to the object

type Environment

type Environment struct {
	Env    *envtest.Environment
	Client client.Client
}

Environment is a internal landscaper test environment

func New

func New(projectRoot string) (*Environment, error)

New creates a new test environment with the landscaper known crds.

func (*Environment) CleanupState

func (e *Environment) CleanupState(ctx context.Context, state *State) error

CleanupState cleans up a test environment.

func (*Environment) InitDefaultContextFromInst

func (e *Environment) InitDefaultContextFromInst(ctx context.Context, state *State, inst *lsv1alpha1.Installation) error

InitDefaultContextFromInst creates a default landsacpe context object from a installation.

func (*Environment) InitResources

func (e *Environment) InitResources(ctx context.Context, resourcesPath string) (*State, error)

InitResources creates a new isolated environment with its own namespace.

func (*Environment) InitResourcesWithTwoNamespaces

func (e *Environment) InitResourcesWithTwoNamespaces(ctx context.Context, resourcesPath string) (*State, error)

func (*Environment) InitState

func (e *Environment) InitState(ctx context.Context) (*State, error)

InitState creates a new isolated environment with its own namespace.

func (*Environment) Start

func (e *Environment) Start() (client.Client, error)

Start starts the fake environment and creates a client for the started kubernetes cluster.

func (*Environment) Stop

func (e *Environment) Stop() error

Stop stops the running dev environment

type State

type State struct {
	Client        client.Client
	Namespace     string
	Namespace2    string
	Installations map[string]*lsv1alpha1.Installation
	Executions    map[string]*lsv1alpha1.Execution
	DeployItems   map[string]*lsv1alpha1.DeployItem
	DataObjects   map[string]*lsv1alpha1.DataObject
	Targets       map[string]*lsv1alpha1.Target
	TargetSyncs   map[string]*lsv1alpha1.TargetSync
	Secrets       map[string]*corev1.Secret
	ConfigMaps    map[string]*corev1.ConfigMap
	Generic       map[string]client.Object
	// contains filtered or unexported fields
}

State contains the state of initialized fake client

func InitStateWithNamespace

func InitStateWithNamespace(ctx context.Context, c client.Client, log utils.Logger, createSecondNamespace bool) (*State, error)

InitStateWithNamespace creates a new isolated environment with its own namespace.

func NewFakeClientFromPath

func NewFakeClientFromPath(path string) (client.Client, *State, error)

NewFakeClientFromPath reads all landscaper related files from the given path adds them to the controller runtime's fake client.

func NewState

func NewState(log utils.Logger) *State

NewState initializes a new state.

func NewStateWithClient

func NewStateWithClient(log utils.Logger, kubeClient client.Client) *State

NewStateWithClient initializes a new state with a client.

func (*State) AddResources

func (s *State) AddResources(objects ...client.Object) error

AddResources to the current state

func (*State) CleanupForInstallation

func (s *State) CleanupForInstallation(ctx context.Context, c client.Client, obj *lsv1alpha1.Installation,
	timeout time.Duration) error

CleanupForInstallation cleans up an installation from a cluster

func (*State) CleanupState

func (s *State) CleanupState(ctx context.Context, opts ...CleanupOption) error

CleanupState cleans up a test environment. todo: remove finalizers of all objects in state

func (*State) CleanupStateWithClient

func (s *State) CleanupStateWithClient(ctx context.Context, c client.Client, opts ...CleanupOption) error

CleanupStateWithClient cleans up a test environment. todo: remove finalizers of all objects in state

func (*State) Create

func (s *State) Create(ctx context.Context, obj client.Object, opts ...CreateOption) error

Create creates or updates a kubernetes resources and adds it to the current state

func (*State) CreateWithClient

func (s *State) CreateWithClient(ctx context.Context, c client.Client, obj client.Object, opts ...CreateOption) error

CreateWithClient creates or updates a kubernetes resource and adds it to the current state

func (*State) HasClient

func (s *State) HasClient() bool

HasClient returns whether a client is configured or not

func (*State) InitResources

func (s *State) InitResources(ctx context.Context, resourcesPath string) error

InitResources creates a new isolated environment with its own namespace.

func (*State) InitResourcesWithClient

func (s *State) InitResourcesWithClient(ctx context.Context, c client.Client, resourcesPath string) error

InitResourcesWithClient creates a new isolated environment with its own namespace.

func (*State) SetInitTime

func (s *State) SetInitTime(ctx context.Context, deployItem *lsv1alpha1.DeployItem) error

SetInitTime prepares the status of a DeployItem with an init timestamp. It is needed for timeout checks during reconciliation. Normally, the deployers set the init timestamp, but some tests skip this part of the reconciliation and therefore must set the init timestamp by itself.

func (*State) Update

func (s *State) Update(ctx context.Context, obj client.Object, opts ...client.UpdateOption) error

Update a kubernetes resources

func (*State) UpdateWithClient

func (s *State) UpdateWithClient(ctx context.Context, cl client.Client, obj client.Object, opts ...client.UpdateOption) error

type UpdateStatus

type UpdateStatus bool

func (UpdateStatus) ApplyOption

func (s UpdateStatus) ApplyOption(options *CreateOptions) error

type WaitForDeletion

type WaitForDeletion bool

WaitForDeletion configures the cleanup to wait for all resources to be deleted.

func (WaitForDeletion) ApplyOption

func (s WaitForDeletion) ApplyOption(options *CleanupOptions) error

type WithCleanupTimeout

type WithCleanupTimeout time.Duration

WithCleanupTimeout configures the cleanup timeout

func (WithCleanupTimeout) ApplyOption

func (s WithCleanupTimeout) ApplyOption(options *CleanupOptions) error

type WithRestConfigOption

type WithRestConfigOption struct {
	RestConfig *rest.Config
}

WithRestConfigOption configures the rest config

func WithRestConfig

func WithRestConfig(cfg *rest.Config) WithRestConfigOption

WithRestConfig configures the rest config

func (WithRestConfigOption) ApplyOption

func (s WithRestConfigOption) ApplyOption(options *CleanupOptions) error

Jump to

Keyboard shortcuts

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