cluster

package
v1.1.2 Latest Latest
Warning

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

Go to latest
Published: Feb 16, 2022 License: Apache-2.0 Imports: 63 Imported by: 10

Documentation

Overview

Package cluster implements clusterctl cluster functionality.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

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 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() error

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

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

	// Images return the list of images required for installing the cert-manager.
	Images() ([]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(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(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() 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 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() error

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

	// List returns the inventory items for all the provider instances installed in the cluster.
	List() (*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(providerType clusterctlv1.ProviderType) (string, error)

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

	// GetProviderNamespace returns the namespace for a given provider.
	GetProviderNamespace(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(...CheckCAPIContractOption) error

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

	// CheckSingleProviderInstance ensures that only one instance of a provider is running, returns error otherwise.
	CheckSingleProviderInstance() 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(namespace string, toCluster Client, dryRun bool) error
	// Backup saves all the Cluster API objects existing in a namespace (or from all the namespaces if empty) to a target management cluster.
	Backup(namespace string, directory string) error
	// Restore restores all the Cluster API objects existing in a configured directory to a target management cluster.
	Restore(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 PatchSummary added in v1.1.0

type PatchSummary = dryrun.PatchSummary

PatchSummary defined the patch observed on an object.

type PollImmediateWaiter

type PollImmediateWaiter func(interval, timeout time.Duration, condition wait.ConditionFunc) 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(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)
	Validate() 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, and more specifically:
	//   - Upgrade to the latest version in the the v1alpha3 series: ....
	//   - Upgrade to the latest version in the the v1alpha4 series: ....
	Plan() ([]UpgradePlan, error)

	// ApplyPlan executes an upgrade following an UpgradePlan generated by clusterctl.
	ApplyPlan(clusterAPIVersion string) error

	// ApplyCustomPlan plan executes an upgrade using the UpgradeItems provided by the user.
	ApplyCustomPlan(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() (client.Client, error)

	// CheckClusterAvailable checks if a a cluster is available and reachable.
	CheckClusterAvailable() 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(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(groupVersion, kind string, options []client.ListOption, prefix string) ([]string, error)
}

Proxy defines a client proxy interface.

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.

type RepositoryClientFactory

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

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

type TemplateClient

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

	// GetFromURL returns a workload cluster template from the given URL.
	GetFromURL(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(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 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(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