Documentation

Overview

Package clusterctl implements clusterctl interaction.

Index

Constants

View Source
const (
	// DefaultFlavor for ConfigClusterInput; use it for getting the cluster-template.yaml file.
	DefaultFlavor = ""
)
View Source
const (
	// DefaultInfrastructureProvider for ConfigClusterInput; use it for using the only infrastructure provider installed in a cluster.
	DefaultInfrastructureProvider = ""
)

Variables

This section is empty.

Functions

func ApplyClusterTemplateAndWait

func ApplyClusterTemplateAndWait(ctx context.Context, input ApplyClusterTemplateAndWaitInput, result *ApplyClusterTemplateAndWaitResult)

ApplyClusterTemplateAndWait gets a cluster template using clusterctl, and waits for the cluster to be ready. Important! this method assumes the cluster uses a KubeadmControlPlane and MachineDeployments.

func ConfigCluster

func ConfigCluster(ctx context.Context, input ConfigClusterInput) []byte

ConfigCluster gets a workload cluster based on a template.

func ConfigClusterWithBinary

func ConfigClusterWithBinary(_ context.Context, clusterctlBinaryPath string, input ConfigClusterInput) []byte

ConfigClusterWithBinary uses clusterctl binary to run config cluster.

func CreateRepository

func CreateRepository(ctx context.Context, input CreateRepositoryInput) string

CreateRepository creates a clusterctl local repository based on the e2e test config, and the returns the path to a clusterctl config file to be used for working with such repository.

func Init

func Init(ctx context.Context, input InitInput)

Init calls clusterctl init with the list of providers defined in the local repository.

func InitManagementClusterAndWatchControllerLogs

func InitManagementClusterAndWatchControllerLogs(ctx context.Context, input InitManagementClusterAndWatchControllerLogsInput, intervals ...interface{})

InitManagementClusterAndWatchControllerLogs initializes a management using clusterctl and setup watches for controller logs. Important: Considering we want to support test suites using existing clusters, clusterctl init is executed only in case there are no provider controllers in the cluster; but controller logs watchers are created regardless of the pre-existing providers.

func InitWithBinary

func InitWithBinary(_ context.Context, binary string, input InitInput)

InitWithBinary uses clusterctl binary to run init with the list of providers defined in the local repository.

func Move

func Move(ctx context.Context, input MoveInput)

Move moves workload clusters.

func Upgrade

func Upgrade(ctx context.Context, input UpgradeInput)

Upgrade calls clusterctl upgrade apply with the list of providers defined in the local repository.

func UpgradeManagementClusterAndWait

func UpgradeManagementClusterAndWait(ctx context.Context, input UpgradeManagementClusterAndWaitInput, intervals ...interface{})

UpgradeManagementClusterAndWait upgrades provider a management cluster using clusterctl, and waits for the cluster to be ready.

func YAMLForComponentSource

func YAMLForComponentSource(ctx context.Context, source ProviderVersionSource) ([]byte, error)

YAMLForComponentSource returns the YAML for the provided component source.

Types

type ApplyClusterTemplateAndWaitInput

type ApplyClusterTemplateAndWaitInput struct {
	ClusterProxy                 framework.ClusterProxy
	ConfigCluster                ConfigClusterInput
	CNIManifestPath              string
	WaitForClusterIntervals      []interface{}
	WaitForControlPlaneIntervals []interface{}
	WaitForMachineDeployments    []interface{}
	WaitForMachinePools          []interface{}
	Args                         []string // extra args to be used during `kubectl apply`
	ControlPlaneWaiters
}

ApplyClusterTemplateAndWaitInput is the input type for ApplyClusterTemplateAndWait.

type ApplyClusterTemplateAndWaitResult

type ApplyClusterTemplateAndWaitResult struct {
	Cluster            *clusterv1.Cluster
	ControlPlane       *controlplanev1.KubeadmControlPlane
	MachineDeployments []*clusterv1.MachineDeployment
	MachinePools       []*clusterv1exp.MachinePool
}

type ComponentConfig

type ComponentConfig struct {
	// Name is the name of the component.
	// This field is primarily used for logging.
	Name string `json:"name"`

	// Sources is an optional list of component YAML to apply to the management
	// cluster.
	// This field may be omitted when wanting only to block progress via one or
	// more Waiters.
	Sources []ProviderVersionSource `json:"sources,omitempty"`

	// Waiters is an optional list of checks to perform in order to determine
	// whether or not the installed components are ready.
	Waiters []ComponentWaiter `json:"waiters,omitempty"`
}

ComponentConfig describes a component required by the e2e test environment.

type ComponentReplacement

type ComponentReplacement struct {
	// Old is the pattern to replace.
	// A regular expression may be used.
	Old string `json:"old"`
	// New is the string used to replace the old pattern.
	// An empty string is valid.
	New string `json:"new,omitempty"`
}

ComponentReplacement is used to replace some of the generated YAML prior to application.

type ComponentSourceType

type ComponentSourceType string

ComponentSourceType indicates how a component's source should be obtained.

const (
	// URLSource is component YAML available directly via a URL.
	// The URL may begin with http://, https:// or file://(can be omitted, relative paths supported).
	URLSource ComponentSourceType = "url"

	// KustomizeSource is a valid kustomization root that can be used to produce
	// the component YAML.
	KustomizeSource ComponentSourceType = "kustomize"
)

type ComponentWaiter

type ComponentWaiter struct {
	// Value varies depending on the specified Type.
	// Please see the documentation for the different WaiterType constants to
	// understand the valid values for this field.
	Value string `json:"value"`

	// Type describes the type of check to perform.
	//
	// Defaults to "pods".
	Type ComponentWaiterType `json:"type,omitempty"`
}

ComponentWaiter contains information to help determine whether installed components are ready.

type ComponentWaiterType

type ComponentWaiterType string

ComponentWaiterType indicates the type of check to use to determine if the installed components are ready.

const (
	// ServiceWaiter indicates to wait until a service's condition is Available.
	// When ComponentWaiter.Value is set to "service", the ComponentWaiter.Value
	// should be set to the name of a Service resource.
	ServiceWaiter ComponentWaiterType = "service"

	// PodsWaiter indicates to wait until all the pods in a namespace have a
	// condition of Ready.
	// When ComponentWaiter.Value is set to "pods", the ComponentWaiter.Value
	// should be set to the name of a Namespace resource.
	PodsWaiter ComponentWaiterType = "pods"
)

type ConfigClusterInput

type ConfigClusterInput struct {
	LogFolder                string
	ClusterctlConfigPath     string
	KubeconfigPath           string
	InfrastructureProvider   string
	Namespace                string
	ClusterName              string
	KubernetesVersion        string
	ControlPlaneMachineCount *int64
	WorkerMachineCount       *int64
	Flavor                   string
}

ConfigClusterInput is the input for ConfigCluster.

type ContainerImage

type ContainerImage struct {
	// Name is the fully qualified name of the image.
	Name string

	// LoadBehavior may be used to dictate whether a failed load operation
	// should fail the test run. This is useful when wanting to load images
	// *if* they exist locally, but not wanting to fail if they don't.
	//
	// Defaults to MustLoadImage.
	LoadBehavior LoadImageBehavior
}

ContainerImage describes an image to load into a cluster and the behavior when loading the image.

type ControlPlaneWaiters

type ControlPlaneWaiters struct {
	WaitForControlPlaneInitialized   Waiter
	WaitForControlPlaneMachinesReady Waiter
}

ControlPlaneWaiters are Waiter functions for the control plane.

type CreateRepositoryInput

type CreateRepositoryInput struct {
	RepositoryFolder    string
	E2EConfig           *E2EConfig
	FileTransformations []RepositoryFileTransformation
}

CreateRepositoryInput is the input for CreateRepository.

func (*CreateRepositoryInput) RegisterClusterResourceSetConfigMapTransformation

func (i *CreateRepositoryInput) RegisterClusterResourceSetConfigMapTransformation(manifestPath, envSubstVar string)

RegisterClusterResourceSetConfigMapTransformation registers a FileTransformations that injects a manifests file into a ConfigMap that defines a ClusterResourceSet resource.

NOTE: this transformation is specifically designed for replacing "data: ${envSubstVar}".

type E2EConfig

type E2EConfig struct {
	// Name is the name of the Kind management cluster.
	// Defaults to test-[random generated suffix].
	ManagementClusterName string `json:"managementClusterName,omitempty"`

	// Images is a list of container images to load into the Kind cluster.
	Images []ContainerImage `json:"images,omitempty"`

	// Providers is a list of providers to be configured in the local repository that will be created for the e2e test.
	// It is required to provide following providers
	// - cluster-api
	// - bootstrap kubeadm
	// - control-plane kubeadm
	// - one infrastructure provider
	// The test will adapt to the selected infrastructure provider
	Providers []ProviderConfig `json:"providers,omitempty"`

	// Variables to be added to the clusterctl config file
	// Please note that clusterctl read variables from OS environment variables as well, so you can avoid to hard code
	// sensitive data in the config file.
	Variables map[string]string `json:"variables,omitempty"`

	// Intervals to be used for long operations during tests
	Intervals map[string][]string `json:"intervals,omitempty"`
}

E2EConfig defines the configuration of an e2e test environment.

func LoadE2EConfig

func LoadE2EConfig(ctx context.Context, input LoadE2EConfigInput) *E2EConfig

LoadE2EConfig loads the configuration for the e2e test environment.

func (*E2EConfig) AbsPaths

func (c *E2EConfig) AbsPaths(basePath string)

AbsPaths makes relative paths absolute using the given base path.

func (*E2EConfig) Defaults

func (c *E2EConfig) Defaults()

Defaults assigns default values to the object. More specifically: - ManagementClusterName gets a default name if empty. - Providers version gets type KustomizeSource if not otherwise specified. - Providers file gets targetName = sourceName if not otherwise specified. - Images gets LoadBehavior = MustLoadImage if not otherwise specified.

func (*E2EConfig) GetInt32PtrVariable

func (c *E2EConfig) GetInt32PtrVariable(varName string) *int32

GetInt32PtrVariable returns an Int32Ptr variable from the e2e config file.

func (*E2EConfig) GetInt64PtrVariable

func (c *E2EConfig) GetInt64PtrVariable(varName string) *int64

GetInt64PtrVariable returns an Int64Ptr variable from the e2e config file.

func (*E2EConfig) GetIntervals

func (c *E2EConfig) GetIntervals(spec, key string) []interface{}

GetIntervals returns the intervals to be applied to a Eventually operation. It searches for [spec]/[key] intervals first, and if it is not found, it searches for default/[key]. If also the default/[key] intervals are not found, ginkgo DefaultEventuallyTimeout and DefaultEventuallyPollingInterval are used.

func (*E2EConfig) GetProviderVersions

func (c *E2EConfig) GetProviderVersions(provider string) []string

GetProviderVersions returns the sorted list of versions defined for a provider.

func (*E2EConfig) GetProvidersWithOldestVersion

func (c *E2EConfig) GetProvidersWithOldestVersion(providers ...string) []string

func (*E2EConfig) GetVariable

func (c *E2EConfig) GetVariable(varName string) string

GetVariable returns a variable from environment variables or from the e2e config file.

func (*E2EConfig) HasDockerProvider

func (c *E2EConfig) HasDockerProvider() bool

func (*E2EConfig) HasVariable

func (c *E2EConfig) HasVariable(varName string) bool

func (*E2EConfig) InfrastructureProviders

func (c *E2EConfig) InfrastructureProviders() []string

InfrastructureProviders returns the infrastructure provider selected for running this E2E test.

func (*E2EConfig) Validate

func (c *E2EConfig) Validate() error

Validate validates the configuration. More specifically: - ManagementClusterName should not be empty. - There should be one CoreProvider (cluster-api), one BootstrapProvider (kubeadm), one ControlPlaneProvider (kubeadm). - There should be one InfraProvider (pick your own). - Image should have name and loadBehavior be one of [mustload, tryload]. - Intervals should be valid ginkgo intervals.

type Files

type Files struct {
	// SourcePath path of the file.
	SourcePath string `json:"sourcePath"`

	// TargetName name of the file copied into the local repository. if empty, the source name
	// Will be preserved
	TargetName string `json:"targetName,omitempty"`
}

Files contains information about files to be copied into the local repository.

type InitInput

type InitInput struct {
	LogFolder               string
	ClusterctlConfigPath    string
	KubeconfigPath          string
	CoreProvider            string
	BootstrapProviders      []string
	ControlPlaneProviders   []string
	InfrastructureProviders []string
}

InitInput is the input for Init.

type InitManagementClusterAndWatchControllerLogsInput

type InitManagementClusterAndWatchControllerLogsInput struct {
	ClusterProxy             framework.ClusterProxy
	ClusterctlConfigPath     string
	CoreProvider             string
	BootstrapProviders       []string
	ControlPlaneProviders    []string
	InfrastructureProviders  []string
	LogFolder                string
	DisableMetricsCollection bool
	ClusterctlBinaryPath     string
}

InitManagementClusterAndWatchControllerLogsInput is the input type for InitManagementClusterAndWatchControllerLogs.

type LoadE2EConfigInput

type LoadE2EConfigInput struct {
	// ConfigPath for the e2e test.
	ConfigPath string
}

LoadE2EConfigInput is the input for LoadE2EConfig.

type LoadImageBehavior

type LoadImageBehavior string

LoadImageBehavior indicates the behavior when loading an image.

const (
	// MustLoadImage causes a load operation to fail if the image cannot be
	// loaded.
	MustLoadImage LoadImageBehavior = "mustLoad"

	// TryLoadImage causes any errors that occur when loading an image to be
	// ignored.
	TryLoadImage LoadImageBehavior = "tryLoad"
)

type MoveInput

type MoveInput struct {
	LogFolder            string
	ClusterctlConfigPath string
	FromKubeconfigPath   string
	ToKubeconfigPath     string
	Namespace            string
}

MoveInput is the input for ClusterctlMove.

type ProviderConfig

type ProviderConfig struct {
	// Name is the name of the provider.
	Name string `json:"name"`

	// Type is the type of the provider.
	Type string `json:"type"`

	// Versions is a list of component YAML to be added to the local repository, one for each release.
	// Please note that the first source will be used a a default release for this provider.
	Versions []ProviderVersionSource `json:"versions,omitempty"`

	// Files is a list of files to be copied into the local repository for all the releases.
	Files []Files `json:"files,omitempty"`
}

ProviderConfig describes a provider to be configured in the local repository that will be created for the e2e test.

type ProviderVersionSource

type ProviderVersionSource struct {
	// Name is used for logging when a component has multiple sources.
	Name string `json:"name,omitempty"`

	// Value is the source of the component's YAML.
	// May be a URL or a kustomization root (specified by Type).
	// If a Type=url then Value may begin with file://, http://, or https://.
	// If a Type=kustomize then Value may be any valid go-getter URL. For
	// more information please see https://github.com/hashicorp/go-getter#url-format.
	Value string `json:"value"`

	// Type describes how to process the source of the component's YAML.
	//
	// Defaults to "kustomize".
	Type ComponentSourceType `json:"type,omitempty"`

	// Replacements is a list of patterns to replace in the component YAML
	// prior to application.
	Replacements []ComponentReplacement `json:"replacements,omitempty"`

	// Files is a list of files to be copied into the local repository for this release.
	Files []Files `json:"files,omitempty"`
}

ProviderVersionSource describes how to obtain a component's YAML.

type RepositoryFileTransformation

type RepositoryFileTransformation func([]byte) ([]byte, error)

RepositoryFileTransformation is a helpers for managing a clusterctl local repository to be used for running e2e tests in isolation.

type UpgradeInput

type UpgradeInput struct {
	LogFolder            string
	ClusterctlConfigPath string
	KubeconfigPath       string
	Contract             string
}

UpgradeInput is the input for Upgrade.

type UpgradeManagementClusterAndWaitInput

type UpgradeManagementClusterAndWaitInput struct {
	ClusterProxy         framework.ClusterProxy
	ClusterctlConfigPath string
	Contract             string
	LogFolder            string
}

UpgradeManagementClusterAndWaitInput is the input type for UpgradeManagementClusterAndWait.

type Waiter

Waiter is a function that runs and waits for a long running operation to finish and updates the result.

Directories

Path Synopsis
Package logger implements clusterctl logging functionality.
Package logger implements clusterctl logging functionality.