cluster

package
v1.9.1 Latest Latest
Warning

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

Go to latest
Published: Dec 17, 2024 License: Apache-2.0 Imports: 68 Imported by: 12

Documentation

Overview

Package cluster implements clusterctl cluster functionality.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FilterClusterObjectsWithNameFilter added in v1.7.2

func FilterClusterObjectsWithNameFilter(s string) func(u unstructured.Unstructured) bool

FilterClusterObjectsWithNameFilter is used in e2e tests where the owner graph gets queried to filter out cluster-wide objects which don't have the s in their object name. This avoids assertions on objects which are part of in-parallel running tests like ExtensionConfig. NOTE: this function signature is exposed to allow implementation of E2E tests; there is no guarantee about the stability of this API.

Types

type AllowCAPIAnyContract added in v0.99.99

type AllowCAPIAnyContract struct{}

AllowCAPIAnyContract instructs CheckCAPIContract to tolerate management clusters with Cluster API with any contract. NOTE: This allows clusterctl generate cluster with managed topologies to work properly by performing checks to see if CAPI is installed.

func (AllowCAPIAnyContract) Apply added in v0.99.99

Apply applies this configuration to the given CheckCAPIContractOptions.

type AllowCAPIContract added in v0.3.15

type AllowCAPIContract struct {
	Contract string
}

AllowCAPIContract instructs CheckCAPIContract to tolerate management clusters with Cluster API with the given contract. NOTE: This allows clusterctl upgrade to work on management clusters with old contract.

func (AllowCAPIContract) Apply added in v0.3.15

Apply applies this configuration to the given CheckCAPIContractOptions.

type AllowCAPINotInstalled added in v0.3.15

type AllowCAPINotInstalled struct{}

AllowCAPINotInstalled instructs CheckCAPIContract to tolerate management clusters without Cluster API installed yet. NOTE: This allows clusterctl init to run on empty management clusters.

func (AllowCAPINotInstalled) Apply added in v0.3.15

Apply applies this configuration to the given CheckCAPIContractOptions.

type CRDMigrator added in v1.7.0

type CRDMigrator interface {
	Run(ctx context.Context, objs []unstructured.Unstructured) error
}

CRDMigrator interface defines methods for migrating CRs to the storage version of new CRDs.

func NewCRDMigrator added in v1.7.0

func NewCRDMigrator(client client.Client) CRDMigrator

NewCRDMigrator creates a new CRD migrator.

type CertManagerClient

type CertManagerClient interface {
	// EnsureInstalled makes sure cert-manager is running and its API is available.
	// This is required to install a new provider.
	EnsureInstalled(ctx context.Context) error

	// EnsureLatestVersion checks the cert-manager version currently installed, and if it is
	// older than the version currently suggested by clusterctl, upgrades it.
	EnsureLatestVersion(ctx context.Context) error

	// PlanUpgrade retruns a CertManagerUpgradePlan with information regarding
	// a cert-manager upgrade if necessary.
	PlanUpgrade(ctx context.Context) (CertManagerUpgradePlan, error)

	// Images return the list of images required for installing the cert-manager.
	Images(ctx context.Context) ([]string, error)
}

CertManagerClient has methods to work with cert-manager components in the cluster.

type CertManagerUpgradePlan added in v0.3.10

type CertManagerUpgradePlan struct {
	ExternallyManaged bool
	From, To          string
	ShouldUpgrade     bool
}

CertManagerUpgradePlan defines the upgrade plan if cert-manager needs to be upgraded to a different version.

type ChangeSummary added in v1.1.0

type ChangeSummary = dryrun.ChangeSummary

ChangeSummary defines all the changes detected by the plan operation.

type CheckCAPIContractOption added in v0.3.15

type CheckCAPIContractOption interface {
	// Apply applies this configuration to the given CheckCAPIContractOptions.
	Apply(*CheckCAPIContractOptions)
}

CheckCAPIContractOption is some configuration that modifies options for CheckCAPIContract.

type CheckCAPIContractOptions added in v0.3.15

type CheckCAPIContractOptions struct {
	// AllowCAPINotInstalled instructs CheckCAPIContract to tolerate management clusters without Cluster API installed yet.
	AllowCAPINotInstalled bool

	// AllowCAPIContracts instructs CheckCAPIContract to tolerate management clusters with Cluster API with the given contract.
	AllowCAPIContracts []string

	// AllowCAPIAnyContract instructs CheckCAPIContract to tolerate management clusters with Cluster API installed with any contract.
	AllowCAPIAnyContract bool
}

CheckCAPIContractOptions contains options for CheckCAPIContract.

type Client

type Client interface {
	// Kubeconfig returns the kubeconfig used to access to a management cluster.
	Kubeconfig() Kubeconfig

	// Proxy return the Proxy used for operating objects in the management cluster.
	Proxy() Proxy

	// CertManager returns a CertManagerClient that can be used for
	// operating the cert-manager components in the cluster.
	CertManager() CertManagerClient

	// ProviderComponents returns a ComponentsClient object that can be used for
	// operating provider components objects in the management cluster (e.g. the CRDs, controllers, RBAC).
	ProviderComponents() ComponentsClient

	// ProviderInventory returns a InventoryClient object that can be used for
	// operating provider inventory stored in the management cluster (e.g. the list of installed providers/versions).
	ProviderInventory() InventoryClient

	// ProviderInstaller returns a ProviderInstaller that enforces consistency rules for provider installation,
	// trying to prevent e.g. controllers fighting for objects, inconsistent versions, etc.
	ProviderInstaller() ProviderInstaller

	// ObjectMover returns an ObjectMover that implements support for moving Cluster API objects (e.g. clusters, AWS clusters, machines, etc.).
	// from one management cluster to another management cluster.
	ObjectMover() ObjectMover

	// ProviderUpgrader returns a ProviderUpgrader that supports upgrading Cluster API providers.
	ProviderUpgrader() ProviderUpgrader

	// Template has methods to work with templates stored in the cluster.
	Template() TemplateClient

	// WorkloadCluster has methods for fetching kubeconfig of workload cluster from management cluster.
	WorkloadCluster() WorkloadCluster

	// Topology returns a TopologyClient that can be used for performing dry run executions of the topology reconciler.
	Topology() TopologyClient
}

Client is used to interact with a management cluster. A management cluster contains following categories of objects: - provider components (e.g. the CRDs, controllers, RBAC) - provider inventory items (e.g. the list of installed providers/versions) - provider objects (e.g. clusters, AWS clusters, machines etc.)

func New

func New(kubeconfig Kubeconfig, configClient config.Client, options ...Option) Client

New returns a cluster.Client.

type ComponentsClient

type ComponentsClient interface {
	// Create creates the provider components in the management cluster.
	Create(ctx context.Context, objs []unstructured.Unstructured) error

	// Delete deletes the provider components from the management cluster.
	// The operation is designed to prevent accidental deletion of user created objects, so
	// it is required to explicitly opt-in for the deletion of the namespace where the provider components are hosted
	// and for the deletion of the provider's CRDs.
	Delete(ctx context.Context, options DeleteOptions) error

	// DeleteWebhookNamespace deletes the core provider webhook namespace (eg. capi-webhook-system).
	// This is required when upgrading to v1alpha4 where webhooks are included in the controller itself.
	DeleteWebhookNamespace(ctx context.Context) error

	// ValidateNoObjectsExist checks if custom resources of the custom resource definitions exist and returns an error if so.
	ValidateNoObjectsExist(ctx context.Context, provider clusterctlv1.Provider) error
}

ComponentsClient has methods to work with provider components in the cluster.

type DeleteOptions

type DeleteOptions struct {
	Provider         clusterctlv1.Provider
	IncludeNamespace bool
	IncludeCRDs      bool
	SkipInventory    bool
}

DeleteOptions holds options for ComponentsClient.Delete func.

type GetOwnerGraphFilterFunction added in v1.7.2

type GetOwnerGraphFilterFunction func(u unstructured.Unstructured) bool

GetOwnerGraphFilterFunction allows filtering the objects returned by GetOwnerGraph. The function has to return true for objects which should be kept. NOTE: this function signature is exposed to allow implementation of E2E tests; there is no guarantee about the stability of this API.

type InstallOptions added in v0.4.1

type InstallOptions struct {
	WaitProviders       bool
	WaitProviderTimeout time.Duration
}

InstallOptions defines the options used to configure installation.

type InventoryClient

type InventoryClient interface {
	// EnsureCustomResourceDefinitions installs the CRD required for creating inventory items, if necessary.
	// Nb. In order to provide a simpler out-of-the box experience, the inventory CRD
	// is embedded in the clusterctl binary.
	EnsureCustomResourceDefinitions(ctx context.Context) error

	// Create an inventory item for a provider instance installed in the cluster.
	Create(context.Context, clusterctlv1.Provider) error

	// List returns the inventory items for all the provider instances installed in the cluster.
	List(ctx context.Context) (*clusterctlv1.ProviderList, error)

	// GetDefaultProviderName returns the default provider for a given ProviderType.
	// In case there is only a single provider for a given type, e.g. only the AWS infrastructure Provider, it returns
	// this as the default provider; In case there are more provider of the same type, there is no default provider.
	GetDefaultProviderName(ctx context.Context, providerType clusterctlv1.ProviderType) (string, error)

	// GetProviderVersion returns the version for a given provider.
	GetProviderVersion(ctx context.Context, provider string, providerType clusterctlv1.ProviderType) (string, error)

	// GetProviderNamespace returns the namespace for a given provider.
	GetProviderNamespace(ctx context.Context, provider string, providerType clusterctlv1.ProviderType) (string, error)

	// CheckCAPIContract checks the Cluster API version installed in the management cluster, and fails if this version
	// does not match the current one supported by clusterctl.
	CheckCAPIContract(context.Context, ...CheckCAPIContractOption) error

	// CheckCAPIInstalled checks if Cluster API is installed on the management cluster.
	CheckCAPIInstalled(ctx context.Context) (bool, error)

	// CheckSingleProviderInstance ensures that only one instance of a provider is running, returns error otherwise.
	CheckSingleProviderInstance(ctx context.Context) error
}

InventoryClient exposes methods to interface with a cluster's provider inventory.

type Kubeconfig added in v0.3.4

type Kubeconfig struct {
	// Path to the kubeconfig file
	Path string
	// Specify context within the kubeconfig file. If empty, cluster client
	// will use the current context.
	Context string
}

Kubeconfig is a type that specifies inputs related to the actual kubeconfig.

type ObjectMover

type ObjectMover interface {
	// Move moves all the Cluster API objects existing in a namespace (or from all the namespaces if empty) to a target management cluster.
	Move(ctx context.Context, namespace string, toCluster Client, dryRun bool, mutators ...ResourceMutatorFunc) error

	// ToDirectory writes all the Cluster API objects existing in a namespace (or from all the namespaces if empty) to a target directory.
	ToDirectory(ctx context.Context, namespace string, directory string) error

	// FromDirectory reads all the Cluster API objects existing in a configured directory to a target management cluster.
	FromDirectory(ctx context.Context, toCluster Client, directory string) error
}

ObjectMover defines methods for moving Cluster API objects to another management cluster.

type Option

type Option func(*clusterClient)

Option is a configuration option supplied to New.

func InjectPollImmediateWaiter

func InjectPollImmediateWaiter(pollImmediateWaiter PollImmediateWaiter) Option

InjectPollImmediateWaiter allows to override the default PollImmediateWaiter used by clusterctl.

func InjectProxy

func InjectProxy(proxy Proxy) Option

InjectProxy allows to override the default proxy used by clusterctl.

func InjectRepositoryFactory

func InjectRepositoryFactory(factory RepositoryClientFactory) Option

InjectRepositoryFactory allows to override the default factory used for creating RepositoryClient objects.

func InjectYamlProcessor added in v0.3.7

func InjectYamlProcessor(p yaml.Processor) Option

InjectYamlProcessor allows you to override the yaml processor that the cluster client uses. By default, the SimpleProcessor is used. This is true even if a nil processor is injected.

type OwnerGraph added in v1.4.0

type OwnerGraph map[string]OwnerGraphNode

OwnerGraph contains a graph with all the objects considered by clusterctl move as nodes and the OwnerReference relationship between those objects as edges.

func GetOwnerGraph added in v1.4.0

func GetOwnerGraph(ctx context.Context, namespace, kubeconfigPath string, filterFn GetOwnerGraphFilterFunction) (OwnerGraph, error)

GetOwnerGraph returns a graph with all the objects considered by clusterctl move as nodes and the OwnerReference relationship between those objects as edges. NOTE: this data structure is exposed to allow implementation of E2E tests verifying that CAPI can properly rebuild its own owner references; there is no guarantee about the stability of this API. Using this test with providers may require a custom implementation of this function, or the OwnerGraph it returns.

type OwnerGraphNode added in v1.4.0

type OwnerGraphNode struct {
	Object corev1.ObjectReference
	Owners []metav1.OwnerReference
}

OwnerGraphNode is a single node linking an ObjectReference to its OwnerReferences.

type PatchSummary added in v1.1.0

type PatchSummary = dryrun.PatchSummary

PatchSummary defined the patch observed on an object.

type PollImmediateWaiter

type PollImmediateWaiter func(ctx context.Context, interval, timeout time.Duration, condition wait.ConditionWithContextFunc) error

PollImmediateWaiter tries a condition func until it returns true, an error, or the timeout is reached.

type ProviderInstaller

type ProviderInstaller interface {
	// Add adds a provider to the install queue.
	// NB. By deferring the installation, the installer service can perform validation of the target state of the management cluster
	// before actually starting the installation of new providers.
	Add(repository.Components)

	// Install performs the installation of the providers ready in the install queue.
	Install(context.Context, InstallOptions) ([]repository.Components, error)

	// Validate performs steps to validate a management cluster by looking at the current state and the providers in the queue.
	// The following checks are performed in order to ensure a fully operational cluster:
	// - There must be only one instance of the same provider
	// - All the providers in must support the same API Version of Cluster API (contract)
	// - All provider CRDs that are referenced in core Cluster API CRDs must comply with the CRD naming scheme,
	//   otherwise a warning is logged.
	Validate(context.Context) error

	// Images returns the list of images required for installing the providers ready in the install queue.
	Images() []string
}

ProviderInstaller defines methods for enforcing consistency rules for provider installation.

type ProviderUpgrader

type ProviderUpgrader interface {
	// Plan returns a set of suggested Upgrade plans for the management cluster.
	Plan(ctx context.Context) ([]UpgradePlan, error)

	// ApplyPlan executes an upgrade following an UpgradePlan generated by clusterctl.
	ApplyPlan(ctx context.Context, opts UpgradeOptions, clusterAPIVersion string) error

	// ApplyCustomPlan plan executes an upgrade using the UpgradeItems provided by the user.
	ApplyCustomPlan(ctx context.Context, opts UpgradeOptions, providersToUpgrade ...UpgradeItem) error
}

ProviderUpgrader defines methods for supporting provider upgrade.

type Proxy

type Proxy interface {
	// GetConfig returns the rest.Config
	GetConfig() (*rest.Config, error)

	// CurrentNamespace returns the namespace from the current context in the kubeconfig file.
	CurrentNamespace() (string, error)

	// ValidateKubernetesVersion returns an error if management cluster version less than MinimumKubernetesVersion.
	ValidateKubernetesVersion() error

	// NewClient returns a new controller runtime Client object for working on the management cluster.
	NewClient(ctx context.Context) (client.Client, error)

	// CheckClusterAvailable checks if a cluster is available and reachable.
	CheckClusterAvailable(ctx context.Context) error

	// ListResources lists namespaced and cluster-wide resources for a component matching the labels. Namespaced resources are only listed
	// in the given namespaces.
	// Please note that we are not returning resources for the component's CRD (e.g. we are not returning
	// Certificates for cert-manager, Clusters for CAPI, AWSCluster for CAPA and so on).
	// This is done to avoid errors when listing resources of providers which have already been deleted/scaled down to 0 replicas/with
	// malfunctioning webhooks.
	ListResources(ctx context.Context, labels map[string]string, namespaces ...string) ([]unstructured.Unstructured, error)

	// GetContexts returns the list of contexts in kubeconfig which begin with prefix.
	GetContexts(prefix string) ([]string, error)

	// GetResourceNames returns the list of resource names which begin with prefix.
	GetResourceNames(ctx context.Context, groupVersion, kind string, options []client.ListOption, prefix string) ([]string, error)
}

Proxy defines a client proxy interface.

func NewProxy added in v1.9.0

func NewProxy(kubeconfig Kubeconfig, opts ...ProxyOption) Proxy

NewProxy returns a proxy used for operating objects in a cluster.

type ProxyOption added in v0.3.4

type ProxyOption func(p *proxy)

ProxyOption defines a function that can change proxy options.

func InjectKubeconfigPaths added in v0.3.6

func InjectKubeconfigPaths(paths []string) ProxyOption

InjectKubeconfigPaths sets the kubeconfig paths loading rules.

func InjectProxyTimeout added in v0.3.4

func InjectProxyTimeout(t time.Duration) ProxyOption

InjectProxyTimeout sets the proxy timeout.

func InjectWarningHandler added in v1.9.0

func InjectWarningHandler(handler rest.WarningHandler) ProxyOption

InjectWarningHandler sets the handler for warnings returned by the Kubernetes API server.

type RepositoryClientFactory

type RepositoryClientFactory func(ctx context.Context, provider config.Provider, configClient config.Client, options ...repository.Option) (repository.Client, error)

RepositoryClientFactory defines a function that returns a new repository.Client.

type ResourceMutatorFunc added in v1.5.0

type ResourceMutatorFunc func(u *unstructured.Unstructured) error

ResourceMutatorFunc holds the type for mutators to be applied on resources during a move operation.

type TemplateClient

type TemplateClient interface {
	// GetFromConfigMap returns a workload cluster template from the given ConfigMap.
	GetFromConfigMap(ctx context.Context, namespace, name, dataKey, targetNamespace string, skipTemplateProcess bool) (repository.Template, error)

	// GetFromURL returns a workload cluster template from the given URL.
	GetFromURL(ctx context.Context, templateURL, targetNamespace string, skipTemplateProcess bool) (repository.Template, error)
}

TemplateClient has methods to work with templates stored in the cluster/out of the provider repository.

type TemplateClientInput added in v0.3.7

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

TemplateClientInput is an input struct for newTemplateClient.

type TopologyClient added in v1.1.0

type TopologyClient interface {
	Plan(ctx context.Context, in *TopologyPlanInput) (*TopologyPlanOutput, error)
}

TopologyClient has methods to work with ClusterClass and ManagedTopologies.

type TopologyPlanInput added in v1.1.0

type TopologyPlanInput struct {
	Objs              []*unstructured.Unstructured
	TargetClusterName string
	TargetNamespace   string
}

TopologyPlanInput defines the input for the Plan function.

type TopologyPlanOutput added in v1.1.0

type TopologyPlanOutput struct {
	// Clusters is the list clusters affected by the input.
	Clusters []client.ObjectKey
	// ClusterClasses is the list of clusters affected by the input.
	ClusterClasses []client.ObjectKey
	// ReconciledCluster is the cluster on which the topology reconciler loop is executed.
	// If there is only one affected cluster then it becomes the ReconciledCluster. If not,
	// the ReconciledCluster is chosen using additional information in the TopologyPlanInput.
	// ReconciledCluster can be empty if no single target cluster is provided.
	ReconciledCluster *client.ObjectKey
	// ChangeSummary is the full list of changes (objects created, modified and deleted) observed
	// on the ReconciledCluster. ChangeSummary is empty if ReconciledCluster is empty.
	*ChangeSummary
}

TopologyPlanOutput defines the output of the Plan function.

type UpgradeItem

type UpgradeItem struct {
	clusterctlv1.Provider
	NextVersion string
}

UpgradeItem defines a possible upgrade target for a provider in the management cluster.

func (*UpgradeItem) UpgradeRef

func (u *UpgradeItem) UpgradeRef() string

UpgradeRef returns a string identifying the upgrade item; this string is derived by the provider.

type UpgradeOptions added in v1.2.0

type UpgradeOptions struct {
	WaitProviders       bool
	WaitProviderTimeout time.Duration
}

UpgradeOptions defines the options used to upgrade installation.

type UpgradePlan

type UpgradePlan struct {
	Contract  string
	Providers []UpgradeItem
}

UpgradePlan defines a list of possible upgrade targets for a management cluster.

type WorkloadCluster added in v0.3.9

type WorkloadCluster interface {
	// GetKubeconfig returns the kubeconfig of the workload cluster.
	GetKubeconfig(ctx context.Context, workloadClusterName string, namespace string) (string, error)
}

WorkloadCluster has methods for fetching kubeconfig of workload cluster from management cluster.

Directories

Path Synopsis
internal
dryrun
Package dryrun implements clusterctl dryrun functionality.
Package dryrun implements clusterctl dryrun functionality.

Jump to

Keyboard shortcuts

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