Skip to content

Commit

Permalink
✨ Add v1beta2 structs to object status (#11234)
Browse files Browse the repository at this point in the history
* Add v1beta2 structs and implement new condition interface

* Generated files and fix conversions

* Fix tests and in place propagation for MachineDeployment and MachineSet

* Address comments

* More comments

* Add MaxItems=32 to conditions
  • Loading branch information
fabriziopandini authored Oct 4, 2024
1 parent 8ca912f commit 9569cd6
Show file tree
Hide file tree
Showing 75 changed files with 3,947 additions and 226 deletions.
111 changes: 111 additions & 0 deletions api/v1beta1/cluster_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,27 @@ type ClusterSpec struct {
// this feature is highly experimental, and parts of it might still be not implemented.
// +optional
Topology *Topology `json:"topology,omitempty"`

// availabilityGates specifies additional conditions to include when evaluating Cluster Available condition.
//
// NOTE: this field is considered only for computing v1beta2 conditions.
// +optional
// +listType=map
// +listMapKey=conditionType
// +kubebuilder:validation:MaxItems=32
AvailabilityGates []ClusterAvailabilityGate `json:"availabilityGates,omitempty"`
}

// ClusterAvailabilityGate contains the type of a Cluster condition to be used as availability gate.
type ClusterAvailabilityGate struct {
// conditionType refers to a positive polarity condition (status true means good) with matching type in the Cluster's condition list.
// If the conditions doesn't exist, it will be treated as unknown.
// Note: Both Cluster API conditions or conditions added by 3rd party controllers can be used as availability gates.
// +required
// +kubebuilder:validation:Pattern=`^([a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*/)?(([A-Za-z0-9][-A-Za-z0-9_.]*)?[A-Za-z0-9])$`
// +kubebuilder:validation:MaxLength=316
// +kubebuilder:validation:MinLength=1
ConditionType string `json:"conditionType"`
}

// Topology encapsulates the information of the managed resources.
Expand Down Expand Up @@ -451,6 +472,80 @@ type ClusterStatus struct {
// ObservedGeneration is the latest generation observed by the controller.
// +optional
ObservedGeneration int64 `json:"observedGeneration,omitempty"`

// v1beta2 groups all the fields that will be added or modified in Cluster's status with the V1Beta2 version.
// +optional
V1Beta2 *ClusterV1Beta2Status `json:"v1beta2,omitempty"`
}

// ClusterV1Beta2Status groups all the fields that will be added or modified in Cluster with the V1Beta2 version.
// See https://github.com/kubernetes-sigs/cluster-api/blob/main/docs/proposals/20240916-improve-status-in-CAPI-resources.md for more context.
type ClusterV1Beta2Status struct {
// conditions represents the observations of a Cluster's current state.
// Known condition types are Available, InfrastructureReady, ControlPlaneInitialized, ControlPlaneAvailable, WorkersAvailable, MachinesReady
// MachinesUpToDate, RemoteConnectionProbe, ScalingUp, ScalingDown, Remediating, Deleting, Paused.
// Additionally, a TopologyReconciled condition will be added in case the Cluster is referencing a ClusterClass / defining a managed Topology.
// +optional
// +listType=map
// +listMapKey=type
// +kubebuilder:validation:MaxItems=32
Conditions []metav1.Condition `json:"conditions,omitempty"`

// controlPlane groups all the observations about Cluster's ControlPlane current state.
// +optional
ControlPlane *ClusterControlPlaneStatus `json:"controlPlane,omitempty"`

// workers groups all the observations about Cluster's Workers current state.
// +optional
Workers *WorkersStatus `json:"workers,omitempty"`
}

// ClusterControlPlaneStatus groups all the observations about control plane current state.
type ClusterControlPlaneStatus struct {
// desiredReplicas is the total number of desired control plane machines in this cluster.
// +optional
DesiredReplicas *int32 `json:"desiredReplicas,omitempty"`

// replicas is the total number of control plane machines in this cluster.
// NOTE: replicas also includes machines still being provisioned or being deleted.
// +optional
Replicas *int32 `json:"replicas,omitempty"`

// upToDateReplicas is the number of up-to-date control plane machines in this cluster. A machine is considered up-to-date when Machine's UpToDate condition is true.
// +optional
UpToDateReplicas *int32 `json:"upToDateReplicas,omitempty"`

// readyReplicas is the total number of ready control plane machines in this cluster. A machine is considered ready when Machine's Ready condition is true.
// +optional
ReadyReplicas *int32 `json:"readyReplicas,omitempty"`

// availableReplicas is the total number of available control plane machines in this cluster. A machine is considered available when Machine's Available condition is true.
// +optional
AvailableReplicas *int32 `json:"availableReplicas,omitempty"`
}

// WorkersStatus groups all the observations about workers current state.
type WorkersStatus struct {
// desiredReplicas is the total number of desired worker machines in this cluster.
// +optional
DesiredReplicas *int32 `json:"desiredReplicas,omitempty"`

// replicas is the total number of worker machines in this cluster.
// NOTE: replicas also includes machines still being provisioned or being deleted.
// +optional
Replicas *int32 `json:"replicas,omitempty"`

// upToDateReplicas is the number of up-to-date worker machines in this cluster. A machine is considered up-to-date when Machine's UpToDate condition is true.
// +optional
UpToDateReplicas *int32 `json:"upToDateReplicas,omitempty"`

// readyReplicas is the total number of ready worker machines in this cluster. A machine is considered ready when Machine's Ready condition is true.
// +optional
ReadyReplicas *int32 `json:"readyReplicas,omitempty"`

// availableReplicas is the total number of available worker machines in this cluster. A machine is considered available when Machine's Available condition is true.
// +optional
AvailableReplicas *int32 `json:"availableReplicas,omitempty"`
}

// ANCHOR_END: ClusterStatus
Expand Down Expand Up @@ -540,6 +635,22 @@ func (c *Cluster) SetConditions(conditions Conditions) {
c.Status.Conditions = conditions
}

// GetV1Beta2Conditions returns the set of conditions for this object.
func (c *Cluster) GetV1Beta2Conditions() []metav1.Condition {
if c.Status.V1Beta2 == nil {
return nil
}
return c.Status.V1Beta2.Conditions
}

// SetV1Beta2Conditions sets conditions for an API object.
func (c *Cluster) SetV1Beta2Conditions(conditions []metav1.Condition) {
if c.Status.V1Beta2 == nil && conditions != nil {
c.Status.V1Beta2 = &ClusterV1Beta2Status{}
}
c.Status.V1Beta2.Conditions = conditions
}

// GetIPFamily returns a ClusterIPFamily from the configuration provided.
//
// Deprecated: IPFamily is not a concept in Kubernetes. It was originally introduced in CAPI for CAPD.
Expand Down
32 changes: 32 additions & 0 deletions api/v1beta1/clusterclass_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -943,6 +943,22 @@ type ClusterClassStatus struct {
// ObservedGeneration is the latest generation observed by the controller.
// +optional
ObservedGeneration int64 `json:"observedGeneration,omitempty"`

// v1beta2 groups all the fields that will be added or modified in ClusterClass's status with the V1Beta2 version.
// +optional
V1Beta2 *ClusterClassV1Beta2Status `json:"v1beta2,omitempty"`
}

// ClusterClassV1Beta2Status groups all the fields that will be added or modified in ClusterClass with the V1Beta2 version.
// See https://github.com/kubernetes-sigs/cluster-api/blob/main/docs/proposals/20240916-improve-status-in-CAPI-resources.md for more context.
type ClusterClassV1Beta2Status struct {
// conditions represents the observations of a ClusterClass's current state.
// Known condition types are VariablesReady, RefVersionsUpToDate, Paused.
// +optional
// +listType=map
// +listMapKey=type
// +kubebuilder:validation:MaxItems=32
Conditions []metav1.Condition `json:"conditions,omitempty"`
}

// ClusterClassStatusVariable defines a variable which appears in the status of a ClusterClass.
Expand Down Expand Up @@ -994,6 +1010,22 @@ func (c *ClusterClass) SetConditions(conditions Conditions) {
c.Status.Conditions = conditions
}

// GetV1Beta2Conditions returns the set of conditions for this object.
func (c *ClusterClass) GetV1Beta2Conditions() []metav1.Condition {
if c.Status.V1Beta2 == nil {
return nil
}
return c.Status.V1Beta2.Conditions
}

// SetV1Beta2Conditions sets conditions for an API object.
func (c *ClusterClass) SetV1Beta2Conditions(conditions []metav1.Condition) {
if c.Status.V1Beta2 == nil && conditions != nil {
c.Status.V1Beta2 = &ClusterClassV1Beta2Status{}
}
c.Status.V1Beta2.Conditions = conditions
}

// ANCHOR_END: ClusterClassStatus

// +kubebuilder:object:root=true
Expand Down
72 changes: 72 additions & 0 deletions api/v1beta1/machine_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,30 @@ type MachineSpec struct {
// +optional
FailureDomain *string `json:"failureDomain,omitempty"`

// The minimum number of seconds for which a Machine should be ready before considering it available.
// Defaults to 0 (Machine will be considered available as soon as the Machine is ready)
// NOTE: this field will be considered only for computing v1beta2 conditions.
// +optional
// TODO: This field will be added in the v1beta2 API, and act as a replacement of existing MinReadySeconds in
// MachineDeployment, MachineSet and MachinePool
// MinReadySeconds int32 `json:"minReadySeconds,omitempty"`

// readinessGates specifies additional conditions to include when evaluating Machine Ready condition.
//
// This field can be used e.g. by Cluster API control plane providers to extend the semantic of the
// Ready condition for the Machine they control, like the kubeadm control provider adding ReadinessGates
// for the APIServerPodHealthy, SchedulerPodHealthy conditions, etc.
//
// Another example are external controllers, e.g. responsible to install special software/hardware on the Machines;
// they can include the status of those components with a new condition and add this condition to ReadinessGates.
//
// NOTE: this field is considered only for computing v1beta2 conditions.
// +optional
// +listType=map
// +listMapKey=conditionType
// +kubebuilder:validation:MaxItems=32
ReadinessGates []MachineReadinessGate `json:"readinessGates,omitempty"`

// NodeDrainTimeout is the total amount of time that the controller will spend on draining a node.
// The default value is 0, meaning that the node can be drained without any time limitations.
// NOTE: NodeDrainTimeout is different from `kubectl drain --timeout`
Expand All @@ -143,6 +167,18 @@ type MachineSpec struct {
NodeDeletionTimeout *metav1.Duration `json:"nodeDeletionTimeout,omitempty"`
}

// MachineReadinessGate contains the type of a Machine condition to be used as a readiness gate.
type MachineReadinessGate struct {
// conditionType refers to a positive polarity condition (status true means good) with matching type in the Machine's condition list.
// If the conditions doesn't exist, it will be treated as unknown.
// Note: Both Cluster API conditions or conditions added by 3rd party controllers can be used as readiness gates.
// +required
// +kubebuilder:validation:Pattern=`^([a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*/)?(([A-Za-z0-9][-A-Za-z0-9_.]*)?[A-Za-z0-9])$`
// +kubebuilder:validation:MaxLength=316
// +kubebuilder:validation:MinLength=1
ConditionType string `json:"conditionType"`
}

// ANCHOR_END: MachineSpec

// ANCHOR: MachineStatus
Expand Down Expand Up @@ -235,6 +271,26 @@ type MachineStatus struct {
// Only present when the Machine has a deletionTimestamp and drain or wait for volume detach started.
// +optional
Deletion *MachineDeletionStatus `json:"deletion,omitempty"`

// v1beta2 groups all the fields that will be added or modified in Machine's status with the V1Beta2 version.
// +optional
V1Beta2 *MachineV1Beta2Status `json:"v1beta2,omitempty"`
}

// MachineV1Beta2Status groups all the fields that will be added or modified in MachineStatus with the V1Beta2 version.
// See https://github.com/kubernetes-sigs/cluster-api/blob/main/docs/proposals/20240916-improve-status-in-CAPI-resources.md for more context.
type MachineV1Beta2Status struct {
// conditions represents the observations of a Machine's current state.
// Known condition types are Available, Ready, UpToDate, BootstrapConfigReady, InfrastructureReady, NodeReady,
// NodeHealthy, Deleting, Paused.
// If a MachineHealthCheck is targeting this machine, also HealthCheckSucceeded, OwnerRemediated conditions are added.
// Additionally control plane Machines controlled by KubeadmControlPlane will have following additional conditions:
// APIServerPodHealthy, ControllerManagerPodHealthy, SchedulerPodHealthy, EtcdPodHealthy, EtcdMemberHealthy.
// +optional
// +listType=map
// +listMapKey=type
// +kubebuilder:validation:MaxItems=32
Conditions []metav1.Condition `json:"conditions,omitempty"`
}

// ANCHOR_END: MachineStatus
Expand Down Expand Up @@ -328,6 +384,22 @@ func (m *Machine) SetConditions(conditions Conditions) {
m.Status.Conditions = conditions
}

// GetV1Beta2Conditions returns the set of conditions for this object.
func (m *Machine) GetV1Beta2Conditions() []metav1.Condition {
if m.Status.V1Beta2 == nil {
return nil
}
return m.Status.V1Beta2.Conditions
}

// SetV1Beta2Conditions sets conditions for an API object.
func (m *Machine) SetV1Beta2Conditions(conditions []metav1.Condition) {
if m.Status.V1Beta2 == nil && conditions != nil {
m.Status.V1Beta2 = &MachineV1Beta2Status{}
}
m.Status.V1Beta2.Conditions = conditions
}

// +kubebuilder:object:root=true

// MachineList contains a list of Machine.
Expand Down
44 changes: 44 additions & 0 deletions api/v1beta1/machinedeployment_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,34 @@ type MachineDeploymentStatus struct {
// Conditions defines current service state of the MachineDeployment.
// +optional
Conditions Conditions `json:"conditions,omitempty"`

// v1beta2 groups all the fields that will be added or modified in MachineDeployment's status with the V1Beta2 version.
// +optional
V1Beta2 *MachineDeploymentV1Beta2Status `json:"v1beta2,omitempty"`
}

// MachineDeploymentV1Beta2Status groups all the fields that will be added or modified in MachineDeployment with the V1Beta2 version.
// See https://github.com/kubernetes-sigs/cluster-api/blob/main/docs/proposals/20240916-improve-status-in-CAPI-resources.md for more context.
type MachineDeploymentV1Beta2Status struct {
// conditions represents the observations of a MachineDeployment's current state.
// Known condition types are Available, MachinesReady, MachinesUpToDate, ScalingUp, ScalingDown, Remediating, Deleting, Paused.
// +optional
// +listType=map
// +listMapKey=type
// +kubebuilder:validation:MaxItems=32
Conditions []metav1.Condition `json:"conditions,omitempty"`

// readyReplicas is the number of ready replicas for this MachineDeployment. A machine is considered ready when Machine's Ready condition is true.
// +optional
ReadyReplicas *int32 `json:"readyReplicas,omitempty"`

// availableReplicas is the number of available replicas for this MachineDeployment. A machine is considered available when Machine's Available condition is true.
// +optional
AvailableReplicas *int32 `json:"availableReplicas,omitempty"`

// upToDateReplicas is the number of up-to-date replicas targeted by this deployment. A machine is considered up-to-date when Machine's UpToDate condition is true.
// +optional
UpToDateReplicas *int32 `json:"upToDateReplicas,omitempty"`
}

// ANCHOR_END: MachineDeploymentStatus
Expand Down Expand Up @@ -388,3 +416,19 @@ func (m *MachineDeployment) GetConditions() Conditions {
func (m *MachineDeployment) SetConditions(conditions Conditions) {
m.Status.Conditions = conditions
}

// GetV1Beta2Conditions returns the set of conditions for this object.
func (m *MachineDeployment) GetV1Beta2Conditions() []metav1.Condition {
if m.Status.V1Beta2 == nil {
return nil
}
return m.Status.V1Beta2.Conditions
}

// SetV1Beta2Conditions sets conditions for an API object.
func (m *MachineDeployment) SetV1Beta2Conditions(conditions []metav1.Condition) {
if m.Status.V1Beta2 == nil && conditions != nil {
m.Status.V1Beta2 = &MachineDeploymentV1Beta2Status{}
}
m.Status.V1Beta2.Conditions = conditions
}
32 changes: 32 additions & 0 deletions api/v1beta1/machinehealthcheck_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,22 @@ type MachineHealthCheckStatus struct {
// Conditions defines current service state of the MachineHealthCheck.
// +optional
Conditions Conditions `json:"conditions,omitempty"`

// v1beta2 groups all the fields that will be added or modified in MachineHealthCheck's status with the V1Beta2 version.
// +optional
V1Beta2 *MachineHealthCheckV1Beta2Status `json:"v1beta2,omitempty"`
}

// MachineHealthCheckV1Beta2Status groups all the fields that will be added or modified in MachineHealthCheck with the V1Beta2 version.
// See https://github.com/kubernetes-sigs/cluster-api/blob/main/docs/proposals/20240916-improve-status-in-CAPI-resources.md for more context.
type MachineHealthCheckV1Beta2Status struct {
// conditions represents the observations of a MachineHealthCheck's current state.
// Known condition types are RemediationAllowed, Paused.
// +optional
// +listType=map
// +listMapKey=type
// +kubebuilder:validation:MaxItems=32
Conditions []metav1.Condition `json:"conditions,omitempty"`
}

// ANCHOR_END: MachineHealthCheckStatus
Expand Down Expand Up @@ -183,6 +199,22 @@ func (m *MachineHealthCheck) SetConditions(conditions Conditions) {
m.Status.Conditions = conditions
}

// GetV1Beta2Conditions returns the set of conditions for this object.
func (m *MachineHealthCheck) GetV1Beta2Conditions() []metav1.Condition {
if m.Status.V1Beta2 == nil {
return nil
}
return m.Status.V1Beta2.Conditions
}

// SetV1Beta2Conditions sets conditions for an API object.
func (m *MachineHealthCheck) SetV1Beta2Conditions(conditions []metav1.Condition) {
if m.Status.V1Beta2 == nil && conditions != nil {
m.Status.V1Beta2 = &MachineHealthCheckV1Beta2Status{}
}
m.Status.V1Beta2.Conditions = conditions
}

// +kubebuilder:object:root=true

// MachineHealthCheckList contains a list of MachineHealthCheck.
Expand Down
Loading

0 comments on commit 9569cd6

Please sign in to comment.