scope

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: 15 Imported by: 0

Documentation

Overview

Package scope provides types for handling all the information to process a request in the topology/ClusterReconciler controller.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ClusterBlueprint

type ClusterBlueprint struct {
	// Topology holds the topology info from Cluster.Spec.
	Topology *clusterv1.Topology

	// ClusterClass holds the ClusterClass object referenced from Cluster.Spec.Topology.
	ClusterClass *clusterv1.ClusterClass

	// InfrastructureClusterTemplate holds the InfrastructureClusterTemplate referenced from ClusterClass.
	InfrastructureClusterTemplate *unstructured.Unstructured

	// ControlPlane holds the ControlPlaneBlueprint derived from ClusterClass.
	ControlPlane *ControlPlaneBlueprint

	// MachineDeployments holds the MachineDeploymentBlueprints derived from ClusterClass.
	MachineDeployments map[string]*MachineDeploymentBlueprint

	// MachinePools holds the MachinePoolBlueprints derived from ClusterClass.
	MachinePools map[string]*MachinePoolBlueprint
}

ClusterBlueprint holds all the objects required for computing the desired state of a managed Cluster topology, including the ClusterClass and all the referenced templates.

func (*ClusterBlueprint) ControlPlaneMachineHealthCheckClass

func (b *ClusterBlueprint) ControlPlaneMachineHealthCheckClass() *clusterv1.MachineHealthCheckClass

ControlPlaneMachineHealthCheckClass returns the MachineHealthCheckClass that should be used to create the MachineHealthCheck object.

func (*ClusterBlueprint) HasControlPlaneInfrastructureMachine

func (b *ClusterBlueprint) HasControlPlaneInfrastructureMachine() bool

HasControlPlaneInfrastructureMachine checks whether the clusterClass mandates the controlPlane has infrastructureMachines.

func (*ClusterBlueprint) HasControlPlaneMachineHealthCheck

func (b *ClusterBlueprint) HasControlPlaneMachineHealthCheck() bool

HasControlPlaneMachineHealthCheck returns true if the ControlPlaneClass has both MachineInfrastructure and a MachineHealthCheck defined.

func (*ClusterBlueprint) HasMachineDeployments

func (b *ClusterBlueprint) HasMachineDeployments() bool

HasMachineDeployments checks whether the topology has MachineDeployments.

func (*ClusterBlueprint) HasMachinePools

func (b *ClusterBlueprint) HasMachinePools() bool

HasMachinePools checks whether the topology has MachinePools.

func (*ClusterBlueprint) IsControlPlaneMachineHealthCheckEnabled

func (b *ClusterBlueprint) IsControlPlaneMachineHealthCheckEnabled() bool

IsControlPlaneMachineHealthCheckEnabled returns true if a MachineHealthCheck should be created for the control plane. Returns false otherwise.

func (*ClusterBlueprint) IsMachineDeploymentMachineHealthCheckEnabled

func (b *ClusterBlueprint) IsMachineDeploymentMachineHealthCheckEnabled(md *clusterv1.MachineDeploymentTopology) bool

IsMachineDeploymentMachineHealthCheckEnabled returns true if a MachineHealthCheck should be created for the MachineDeployment. Returns false otherwise.

func (*ClusterBlueprint) MachineDeploymentMachineHealthCheckClass

func (b *ClusterBlueprint) MachineDeploymentMachineHealthCheckClass(md *clusterv1.MachineDeploymentTopology) *clusterv1.MachineHealthCheckClass

MachineDeploymentMachineHealthCheckClass return the MachineHealthCheckClass that should be used to create the MachineHealthCheck object.

type ClusterState

type ClusterState struct {
	// Cluster holds the Cluster object.
	Cluster *clusterv1.Cluster

	// InfrastructureCluster holds the infrastructure cluster object referenced by the Cluster.
	InfrastructureCluster *unstructured.Unstructured

	// ControlPlane holds the controlplane object referenced by the Cluster.
	ControlPlane *ControlPlaneState

	// MachineDeployments holds the machine deployments in the Cluster.
	MachineDeployments MachineDeploymentsStateMap

	// MachinePools holds the MachinePools in the Cluster.
	MachinePools MachinePoolsStateMap
}

ClusterState holds all the objects representing the state of a managed Cluster topology. NOTE: please note that we are going to deal with two different type state, the current state as read from the API server, and the desired state resulting from processing the ClusterBlueprint.

type ControlPlaneBlueprint

type ControlPlaneBlueprint struct {
	// Template holds the control plane template referenced from ClusterClass.
	Template *unstructured.Unstructured

	// InfrastructureMachineTemplate holds the infrastructure machine template for the control plane, if defined in the ClusterClass.
	InfrastructureMachineTemplate *unstructured.Unstructured

	// MachineHealthCheck holds the MachineHealthCheckClass for this ControlPlane.
	// +optional
	MachineHealthCheck *clusterv1.MachineHealthCheckClass
}

ControlPlaneBlueprint holds the templates required for computing the desired state of a managed control plane.

type ControlPlaneState

type ControlPlaneState struct {
	// Object holds the ControlPlane object.
	Object *unstructured.Unstructured

	// InfrastructureMachineTemplate holds the infrastructure template referenced by the ControlPlane object.
	InfrastructureMachineTemplate *unstructured.Unstructured

	// MachineHealthCheckClass holds the MachineHealthCheck for this ControlPlane.
	// +optional
	MachineHealthCheck *clusterv1.MachineHealthCheck
}

ControlPlaneState holds all the objects representing the state of a managed control plane.

type ControlPlaneUpgradeTracker

type ControlPlaneUpgradeTracker struct {
	// IsPendingUpgrade is true if the Control Plane version needs to be updated. False otherwise.
	// If IsPendingUpgrade is true it also means the Control Plane is not going to pick up the new version
	// in the current reconcile loop.
	// Example cases when IsPendingUpgrade is set to true:
	// - Upgrade is blocked by BeforeClusterUpgrade hook
	// - Upgrade is blocked because the current ControlPlane is not stable (provisioning OR scaling OR upgrading)
	// - Upgrade is blocked because any of the current MachineDeployments or MachinePools are upgrading.
	IsPendingUpgrade bool

	// IsProvisioning is true if the current Control Plane is being provisioned for the first time. False otherwise.
	IsProvisioning bool

	// IsUpgrading is true if the Control Plane is in the middle of an upgrade.
	// Note: Refer to Control Plane contract for definition of upgrading.
	// IsUpgrading is set to true if the current ControlPlane (ControlPlane at the beginning of the reconcile)
	// is upgrading.
	// Note: IsUpgrading only represents the current ControlPlane state. If the Control Plane is about to pick up the
	// version in the reconcile loop IsUpgrading will not be true, because the current ControlPlane is not upgrading,
	// the desired ControlPlane is.
	// Also look at: IsStartingUpgrade.
	IsUpgrading bool

	// IsStartingUpgrade is true if the Control Plane is picking up the new version in the current reconcile loop.
	// If IsStartingUpgrade is true it implies that the desired Control Plane version and the current Control Plane
	// versions are different.
	IsStartingUpgrade bool

	// IsScaling is true if the current Control Plane is scaling. False otherwise.
	// IsScaling only represents the state of the current Control Plane. IsScaling does not represent the state
	// of the desired Control Plane.
	// Example:
	// - IsScaling will be true if the current ControlPlane is scaling.
	// - IsScaling will not be true if the current Control Plane is stable and the reconcile loop is going to scale the Control Plane.
	// Note: Refer to control plane contract for definition of scaling.
	// Note: IsScaling will be false if the Control Plane does not support replicas.
	IsScaling bool
}

ControlPlaneUpgradeTracker holds the current upgrade status of the Control Plane.

func (*ControlPlaneUpgradeTracker) IsControlPlaneStable

func (t *ControlPlaneUpgradeTracker) IsControlPlaneStable() bool

IsControlPlaneStable returns true is the ControlPlane is stable.

type HookResponseTracker

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

HookResponseTracker is a helper to capture the responses of the various lifecycle hooks.

func NewHookResponseTracker

func NewHookResponseTracker() *HookResponseTracker

NewHookResponseTracker returns a new HookResponseTracker.

func (*HookResponseTracker) Add

Add add the response of a hook to the tracker.

func (*HookResponseTracker) AggregateMessage

func (h *HookResponseTracker) AggregateMessage() string

AggregateMessage returns a human friendly message about the blocking status of hooks.

func (*HookResponseTracker) AggregateRetryAfter

func (h *HookResponseTracker) AggregateRetryAfter() time.Duration

AggregateRetryAfter calculates the lowest non-zero retryAfterSeconds time from all the tracked responses.

func (*HookResponseTracker) IsBlocking

func (h *HookResponseTracker) IsBlocking(hook runtimecatalog.Hook) bool

IsBlocking returns true if the hook returned a blocking response. If the hook is not called or did not return a blocking response it returns false.

type MachineDeploymentBlueprint

type MachineDeploymentBlueprint struct {
	// Metadata holds the metadata for a MachineDeployment.
	// NOTE: This is a convenience copy of the metadata field from Cluster.Spec.Topology.Workers.MachineDeployments[x].
	Metadata clusterv1.ObjectMeta

	// BootstrapTemplate holds the bootstrap template for a MachineDeployment referenced from ClusterClass.
	BootstrapTemplate *unstructured.Unstructured

	// InfrastructureMachineTemplate holds the infrastructure machine template for a MachineDeployment referenced from ClusterClass.
	InfrastructureMachineTemplate *unstructured.Unstructured

	// MachineHealthCheck holds the MachineHealthCheckClass for this MachineDeployment.
	// +optional
	MachineHealthCheck *clusterv1.MachineHealthCheckClass
}

MachineDeploymentBlueprint holds the templates required for computing the desired state of a managed MachineDeployment; it also holds a copy of the MachineDeployment metadata from Cluster.Topology, thus providing all the required info in a single place.

type MachineDeploymentState

type MachineDeploymentState struct {
	// Object holds the MachineDeployment object.
	Object *clusterv1.MachineDeployment

	// BootstrapTemplate holds the bootstrap template referenced by the MachineDeployment object.
	BootstrapTemplate *unstructured.Unstructured

	// InfrastructureMachineTemplate holds the infrastructure machine template referenced by the MachineDeployment object.
	InfrastructureMachineTemplate *unstructured.Unstructured

	// MachineHealthCheck holds a MachineHealthCheck linked to the MachineDeployment object.
	// +optional
	MachineHealthCheck *clusterv1.MachineHealthCheck
}

MachineDeploymentState holds all the objects representing the state of a managed deployment.

func (*MachineDeploymentState) IsUpgrading

func (md *MachineDeploymentState) IsUpgrading(ctx context.Context, c client.Reader) (bool, error)

IsUpgrading determines if the MachineDeployment is upgrading. A machine deployment is considered upgrading if at least one of the Machines of this MachineDeployment has a different version.

type MachineDeploymentsStateMap

type MachineDeploymentsStateMap map[string]*MachineDeploymentState

MachineDeploymentsStateMap holds a collection of MachineDeployment states.

func (MachineDeploymentsStateMap) Upgrading

func (mds MachineDeploymentsStateMap) Upgrading(ctx context.Context, c client.Reader) ([]string, error)

Upgrading returns the list of the machine deployments that are upgrading.

type MachinePoolBlueprint

type MachinePoolBlueprint struct {
	// Metadata holds the metadata for a MachinePool.
	// NOTE: This is a convenience copy of the metadata field from Cluster.Spec.Topology.Workers.MachinePools[x].
	Metadata clusterv1.ObjectMeta

	// BootstrapTemplate holds the bootstrap template for a MachinePool referenced from ClusterClass.
	BootstrapTemplate *unstructured.Unstructured

	// InfrastructureMachinePoolTemplate holds the infrastructure machine pool template for a MachinePool referenced from ClusterClass.
	InfrastructureMachinePoolTemplate *unstructured.Unstructured
}

MachinePoolBlueprint holds the templates required for computing the desired state of a managed MachinePool; it also holds a copy of the MachinePool metadata from Cluster.Topology, thus providing all the required info in a single place.

type MachinePoolState

type MachinePoolState struct {
	// Object holds the MachinePool object.
	Object *expv1.MachinePool

	// BootstrapObject holds the MachinePool bootstrap object.
	BootstrapObject *unstructured.Unstructured

	// InfrastructureMachinePoolObject holds the infrastructure machine template referenced by the MachinePool object.
	InfrastructureMachinePoolObject *unstructured.Unstructured
}

MachinePoolState holds all the objects representing the state of a managed pool.

func (*MachinePoolState) IsUpgrading

func (mp *MachinePoolState) IsUpgrading(ctx context.Context, c client.Reader) (bool, error)

IsUpgrading determines if the MachinePool is upgrading. A machine pool is considered upgrading if at least one of the Machines of this MachinePool has a different version.

type MachinePoolsStateMap

type MachinePoolsStateMap map[string]*MachinePoolState

MachinePoolsStateMap holds a collection of MachinePool states.

func (MachinePoolsStateMap) Upgrading

func (mps MachinePoolsStateMap) Upgrading(ctx context.Context, c client.Reader) ([]string, error)

Upgrading returns the list of the machine pools that are upgrading.

type MaxMDUpgradeConcurrency

type MaxMDUpgradeConcurrency int

MaxMDUpgradeConcurrency sets the upper limit for the number of Machine Deployments that can upgrade concurrently.

func (MaxMDUpgradeConcurrency) ApplyToUpgradeTracker

func (m MaxMDUpgradeConcurrency) ApplyToUpgradeTracker(options *UpgradeTrackerOptions)

ApplyToUpgradeTracker applies the given UpgradeTrackerOptions.

type MaxMPUpgradeConcurrency

type MaxMPUpgradeConcurrency int

MaxMPUpgradeConcurrency sets the upper limit for the number of Machine Pools that can upgrade concurrently.

func (MaxMPUpgradeConcurrency) ApplyToUpgradeTracker

func (m MaxMPUpgradeConcurrency) ApplyToUpgradeTracker(options *UpgradeTrackerOptions)

ApplyToUpgradeTracker applies the given UpgradeTrackerOptions.

type Scope

type Scope struct {
	// Blueprint holds all the objects required for computing the desired state of a managed topology.
	Blueprint *ClusterBlueprint

	// Current holds the current state of the managed topology.
	Current *ClusterState

	// Desired holds the desired state of the managed topology.
	Desired *ClusterState

	// UpgradeTracker holds information about ongoing upgrades in the managed topology.
	UpgradeTracker *UpgradeTracker

	// HookResponseTracker holds the hook responses that will be used to
	// calculate a combined reconcile result.
	HookResponseTracker *HookResponseTracker
}

Scope holds all the information to process a request in the topology/ClusterReconciler controller.

func New

func New(cluster *clusterv1.Cluster) *Scope

New returns a new Scope with only the cluster; while processing a request in the topology/ClusterReconciler controller additional information will be added about the Cluster blueprint, current state and desired state.

type UpgradeTracker

type UpgradeTracker struct {
	ControlPlane       ControlPlaneUpgradeTracker
	MachineDeployments WorkerUpgradeTracker
	MachinePools       WorkerUpgradeTracker
}

UpgradeTracker is a helper to capture the upgrade status and make upgrade decisions.

func NewUpgradeTracker

func NewUpgradeTracker(opts ...UpgradeTrackerOption) *UpgradeTracker

NewUpgradeTracker returns an upgrade tracker with empty tracking information.

type UpgradeTrackerOption

type UpgradeTrackerOption interface {
	ApplyToUpgradeTracker(options *UpgradeTrackerOptions)
}

UpgradeTrackerOption returns an option for the NewUpgradeTracker function.

type UpgradeTrackerOptions

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

UpgradeTrackerOptions contains the options for NewUpgradeTracker.

type WorkerUpgradeTracker

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

WorkerUpgradeTracker holds the current upgrade status of MachineDeployments or MachinePools.

func (*WorkerUpgradeTracker) DeferredUpgrade

func (m *WorkerUpgradeTracker) DeferredUpgrade() bool

DeferredUpgrade returns true if the upgrade has been deferred for any of the MachineDeployments/MachinePools. Returns false, otherwise.

func (*WorkerUpgradeTracker) DeferredUpgradeNames

func (m *WorkerUpgradeTracker) DeferredUpgradeNames() []string

DeferredUpgradeNames returns the list of MachineDeployment/MachinePool names for which the upgrade has been deferred.

func (*WorkerUpgradeTracker) IsAnyPendingCreate

func (m *WorkerUpgradeTracker) IsAnyPendingCreate() bool

IsAnyPendingCreate returns true if any of the machine deployments are pending to be created. Returns false, otherwise.

func (*WorkerUpgradeTracker) IsAnyPendingUpgrade

func (m *WorkerUpgradeTracker) IsAnyPendingUpgrade() bool

IsAnyPendingUpgrade returns true if any of the machine deployments are pending an upgrade. Returns false, otherwise.

func (*WorkerUpgradeTracker) IsPendingCreate

func (m *WorkerUpgradeTracker) IsPendingCreate(mdTopologyName string) bool

IsPendingCreate returns true is the MachineDeployment/MachinePool topology is marked as pending create.

func (*WorkerUpgradeTracker) IsPendingUpgrade

func (m *WorkerUpgradeTracker) IsPendingUpgrade(name string) bool

IsPendingUpgrade returns true is the MachineDeployment/MachinePool marked as pending upgrade.

func (*WorkerUpgradeTracker) MarkDeferredUpgrade

func (m *WorkerUpgradeTracker) MarkDeferredUpgrade(name string)

MarkDeferredUpgrade marks that the upgrade for a MachineDeployment/MachinePool has been deferred.

func (*WorkerUpgradeTracker) MarkPendingCreate

func (m *WorkerUpgradeTracker) MarkPendingCreate(mdTopologyName string)

MarkPendingCreate marks a machine deployment topology that is pending to be created. This is generally used to capture machine deployments that are yet to be created because the control plane is not yet stable.

func (*WorkerUpgradeTracker) MarkPendingUpgrade

func (m *WorkerUpgradeTracker) MarkPendingUpgrade(name string)

MarkPendingUpgrade marks a machine deployment as in need of an upgrade. This is generally used to capture machine deployments that have not yet picked up the topology version.

func (*WorkerUpgradeTracker) MarkUpgrading

func (m *WorkerUpgradeTracker) MarkUpgrading(names ...string)

MarkUpgrading marks a MachineDeployment/MachinePool as currently upgrading or about to upgrade.

func (*WorkerUpgradeTracker) PendingCreateTopologyNames

func (m *WorkerUpgradeTracker) PendingCreateTopologyNames() []string

PendingCreateTopologyNames returns the list of machine deployment topology names that are pending create.

func (*WorkerUpgradeTracker) PendingUpgradeNames

func (m *WorkerUpgradeTracker) PendingUpgradeNames() []string

PendingUpgradeNames returns the list of machine deployment names that are pending an upgrade.

func (*WorkerUpgradeTracker) UpgradeConcurrencyReached

func (m *WorkerUpgradeTracker) UpgradeConcurrencyReached() bool

UpgradeConcurrencyReached returns true if the number of MachineDeployments/MachinePools upgrading is at the concurrency limit.

func (*WorkerUpgradeTracker) UpgradingNames

func (m *WorkerUpgradeTracker) UpgradingNames() []string

UpgradingNames returns the list of machine deployments that are upgrading or are about to upgrade.

Jump to

Keyboard shortcuts

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