Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ Add v1beta2 condition to MD controller #11338

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
123 changes: 123 additions & 0 deletions api/v1beta1/machinedeployment_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,129 @@ const (
MachineDeploymentUniqueLabel = "machine-template-hash"
)

// MachineDeployment's Available condition and corresponding reasons that will be used in v1Beta2 API version.
const (
// MachineDeploymentAvailableV1Beta2Condition is true if the MachineDeployment is not deleted, and it has minimum
// availability according to parameters specified in the deployment strategy, e.g. If using RollingUpgrade strategy,
// availableReplicas must be greater or equal than desired replicas - MaxUnavailable replicas.
MachineDeploymentAvailableV1Beta2Condition = AvailableV1Beta2Condition

// MachineDeploymentAvailableWaitingForReplicasSetV1Beta2Reason surfaces when the .spec.replicas
// field of the MachineDeployment is not set.
MachineDeploymentAvailableWaitingForReplicasSetV1Beta2Reason = WaitingForReplicasSetV1Beta2Reason

// MachineDeploymentAvailableWaitingForAvailableReplicasSetV1Beta2Reason surfaces when the .status.v1beta2.availableReplicas
// field of the MachineDeployment is not set.
MachineDeploymentAvailableWaitingForAvailableReplicasSetV1Beta2Reason = "WaitingForAvailableReplicasSet"

// MachineDeploymentAvailableV1Beta2Reason surfaces when a Deployment is available.
MachineDeploymentAvailableV1Beta2Reason = AvailableV1Beta2Reason

// MachineDeploymentNotAvailableV1Beta2Reason surfaces when a Deployment is not available.
MachineDeploymentNotAvailableV1Beta2Reason = NotAvailableV1Beta2Reason

// MachineDeploymentAvailableInternalErrorV1Beta2Reason surfaces unexpected failures when computing the Available condition.
MachineDeploymentAvailableInternalErrorV1Beta2Reason = InternalErrorV1Beta2Reason
)

// MachineDeployment's MachinesReady condition and corresponding reasons that will be used in v1Beta2 API version.
const (
// MachineDeploymentMachinesReadyV1Beta2Condition surfaces detail of issues on the controlled machines, if any.
MachineDeploymentMachinesReadyV1Beta2Condition = MachinesReadyV1Beta2Condition

// MachineDeploymentMachinesReadyNoReplicasV1Beta2Reason surfaces when no machines exist for the MachineDeployment.
MachineDeploymentMachinesReadyNoReplicasV1Beta2Reason = NoReplicasV1Beta2Reason

// MachineDeploymentMachinesReadyInternalErrorV1Beta2Reason surfaces unexpected failures when listing machines
// or aggregating machine's conditions.
MachineDeploymentMachinesReadyInternalErrorV1Beta2Reason = InternalErrorV1Beta2Reason
)

// MachineDeployment's MachinesUpToDate condition and corresponding reasons that will be used in v1Beta2 API version.
const (
// MachineDeploymentMachinesUpToDateV1Beta2Condition surfaces details of controlled machines not up to date, if any.
MachineDeploymentMachinesUpToDateV1Beta2Condition = MachinesUpToDateV1Beta2Condition

// MachineDeploymentMachinesUpToDateNoReplicasV1Beta2Reason surfaces when no machines exist for the MachineDeployment.
MachineDeploymentMachinesUpToDateNoReplicasV1Beta2Reason = NoReplicasV1Beta2Reason

// MachineDeploymentMachinesUpToDateInternalErrorV1Beta2Reason surfaces unexpected failures when listing machines
// or aggregating status.
MachineDeploymentMachinesUpToDateInternalErrorV1Beta2Reason = InternalErrorV1Beta2Reason
)

// MachineDeployment's ScalingUp condition and corresponding reasons that will be used in v1Beta2 API version.
const (
// MachineDeploymentScalingUpV1Beta2Condition is true if actual replicas < desired replicas.
MachineDeploymentScalingUpV1Beta2Condition = ScalingUpV1Beta2Condition

// MachineDeploymentScalingUpV1Beta2Reason surfaces when actual replicas < desired replicas.
MachineDeploymentScalingUpV1Beta2Reason = ScalingUpV1Beta2Reason

// MachineDeploymentNotScalingUpV1Beta2Reason surfaces when actual replicas >= desired replicas.
MachineDeploymentNotScalingUpV1Beta2Reason = NotScalingUpV1Beta2Reason

// MachineDeploymentScalingUpInternalErrorV1Beta2Reason surfaces unexpected failures when listing machines.
MachineDeploymentScalingUpInternalErrorV1Beta2Reason = InternalErrorV1Beta2Reason

// MachineDeploymentScalingUpWaitingForReplicasSetV1Beta2Reason surfaces when the .spec.replicas
// field of the MachineDeployment is not set.
MachineDeploymentScalingUpWaitingForReplicasSetV1Beta2Reason = WaitingForReplicasSetV1Beta2Reason
)

// MachineDeployment's ScalingDown condition and corresponding reasons that will be used in v1Beta2 API version.
const (
// MachineDeploymentScalingDownV1Beta2Condition is true if actual replicas > desired replicas.
MachineDeploymentScalingDownV1Beta2Condition = ScalingDownV1Beta2Condition

// MachineDeploymentScalingDownV1Beta2Reason surfaces when actual replicas > desired replicas.
MachineDeploymentScalingDownV1Beta2Reason = ScalingDownV1Beta2Reason

// MachineDeploymentNotScalingDownV1Beta2Reason surfaces when actual replicas <= desired replicas.
MachineDeploymentNotScalingDownV1Beta2Reason = NotScalingDownV1Beta2Reason

// MachineDeploymentScalingDownInternalErrorV1Beta2Reason surfaces unexpected failures when listing machines.
MachineDeploymentScalingDownInternalErrorV1Beta2Reason = InternalErrorV1Beta2Reason

// MachineDeploymentScalingDownWaitingForReplicasSetV1Beta2Reason surfaces when the .spec.replicas
// field of the MachineDeployment is not set.
MachineDeploymentScalingDownWaitingForReplicasSetV1Beta2Reason = WaitingForReplicasSetV1Beta2Reason
)

// MachineDeployment's Remediating condition and corresponding reasons that will be used in v1Beta2 API version.
const (
// MachineDeploymentRemediatingV1Beta2Condition surfaces details about ongoing remediation of the controlled machines, if any.
MachineDeploymentRemediatingV1Beta2Condition = RemediatingV1Beta2Condition

// MachineDeploymentRemediatingV1Beta2Reason surfaces when the MachineDeployment has at least one machine with HealthCheckSucceeded set to false
// and with the OwnerRemediated condition set to false.
MachineDeploymentRemediatingV1Beta2Reason = RemediatingV1Beta2Reason

// MachineDeploymentNotRemediatingV1Beta2Reason surfaces when the MachineDeployment does not have any machine with HealthCheckSucceeded set to false
// and with the OwnerRemediated condition set to false.
MachineDeploymentNotRemediatingV1Beta2Reason = NotRemediatingV1Beta2Reason

// MachineDeploymentRemediatingInternalErrorV1Beta2Reason surfaces unexpected failures when computing the Remediating condition.
MachineDeploymentRemediatingInternalErrorV1Beta2Reason = InternalErrorV1Beta2Reason
)

// MachineDeployment's Deleting condition and corresponding reasons that will be used in v1Beta2 API version.
const (
// MachineDeploymentDeletingV1Beta2Condition surfaces details about ongoing deletion of the controlled machines.
MachineDeploymentDeletingV1Beta2Condition = DeletingV1Beta2Condition

// MachineDeploymentDeletingDeletionTimestampNotSetV1Beta2Reason surfaces when the MachineDeployment is not deleting because the
// DeletionTimestamp is not set.
MachineDeploymentDeletingDeletionTimestampNotSetV1Beta2Reason = DeletionTimestampNotSetV1Beta2Reason

// MachineDeploymentDeletingDeletionTimestampSetV1Beta2Reason surfaces when the MachineDeployment is deleting because the
// DeletionTimestamp is set.
MachineDeploymentDeletingDeletionTimestampSetV1Beta2Reason = DeletionTimestampSetV1Beta2Reason

// MachineDeploymentDeletingInternalErrorV1Beta2Reason surfaces unexpected failures when deleting a MachineDeployment.
MachineDeploymentDeletingInternalErrorV1Beta2Reason = InternalErrorV1Beta2Reason
)

// ANCHOR: MachineDeploymentSpec

// MachineDeploymentSpec defines the desired state of MachineDeployment.
Expand Down
29 changes: 3 additions & 26 deletions api/v1beta1/v1beta2_condition_consts.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@ const (
// AvailableV1Beta2Reason applies to a condition surfacing object availability.
AvailableV1Beta2Reason = "Available"

// NotAvailableV1Beta2Reason applies to a condition surfacing object not satisfying availability criteria.
NotAvailableV1Beta2Reason = "NotAvailable"

// ScalingUpV1Beta2Reason surfaces when an object is scaling up.
ScalingUpV1Beta2Reason = "ScalingUp"

Expand Down Expand Up @@ -170,32 +173,6 @@ const (
InspectionFailedV1Beta2Reason = "InspectionFailed"
)

// Conditions that will be used for the MachineDeployment object in v1Beta2 API version.
const (
// MachineDeploymentAvailableV1Beta2Condition is true if the MachineDeployment is not deleted, and it has minimum
// availability according to parameters specified in the deployment strategy, e.g. If using RollingUpgrade strategy,
// availableReplicas must be greater or equal than desired replicas - MaxUnavailable replicas.
MachineDeploymentAvailableV1Beta2Condition = AvailableV1Beta2Condition

// MachineDeploymentMachinesReadyV1Beta2Condition surfaces detail of issues on the controlled machines, if any.
MachineDeploymentMachinesReadyV1Beta2Condition = MachinesReadyV1Beta2Condition

// MachineDeploymentMachinesUpToDateV1Beta2Condition surfaces details of controlled machines not up to date, if any.
MachineDeploymentMachinesUpToDateV1Beta2Condition = MachinesUpToDateV1Beta2Condition

// MachineDeploymentScalingUpV1Beta2Condition is true if available replicas < desired replicas.
MachineDeploymentScalingUpV1Beta2Condition = ScalingUpV1Beta2Condition

// MachineDeploymentScalingDownV1Beta2Condition is true if replicas > desired replicas.
MachineDeploymentScalingDownV1Beta2Condition = ScalingDownV1Beta2Condition

// MachineDeploymentRemediatingV1Beta2Condition details about ongoing remediation of the controlled machines, if any.
MachineDeploymentRemediatingV1Beta2Condition = RemediatingV1Beta2Condition

// MachineDeploymentDeletingV1Beta2Condition surfaces details about ongoing deletion of the controlled machines.
MachineDeploymentDeletingV1Beta2Condition = DeletingV1Beta2Condition
)

// Conditions that will be used for the Cluster object in v1Beta2 API version.
const (
// ClusterAvailableV1Beta2Condition is true if the Cluster's is not deleted, and RemoteConnectionProbe, InfrastructureReady,
Expand Down
4 changes: 2 additions & 2 deletions controlplane/kubeadm/api/v1beta1/v1beta2_condition_consts.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,11 +154,11 @@ const (
// Note: KubeadmControlPlane only remediates machines with HealthCheckSucceeded set to false and with the OwnerRemediated condition set to false.
KubeadmControlPlaneRemediatingV1Beta2Condition = clusterv1.RemediatingV1Beta2Condition

// KubeadmControlPlaneRemediatingV1Beta2Reason surfaces when kcp has at least one machine with HealthCheckSucceeded set to false
// KubeadmControlPlaneRemediatingV1Beta2Reason surfaces when the KubeadmControlPlane has at least one machine with HealthCheckSucceeded set to false
// and with the OwnerRemediated condition set to false.
KubeadmControlPlaneRemediatingV1Beta2Reason = clusterv1.RemediatingV1Beta2Reason

// KubeadmControlPlaneNotRemediatingV1Beta2Reason surfaces when kcp does not have any machine with HealthCheckSucceeded set to false
// KubeadmControlPlaneNotRemediatingV1Beta2Reason surfaces when the KubeadmControlPlane does not have any machine with HealthCheckSucceeded set to false
// and with the OwnerRemediated condition set to false.
KubeadmControlPlaneNotRemediatingV1Beta2Reason = clusterv1.NotRemediatingV1Beta2Reason

Expand Down
13 changes: 10 additions & 3 deletions controlplane/kubeadm/internal/controllers/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ import (
clog "sigs.k8s.io/cluster-api/util/log"
)

// updateStatus is called after every reconcilitation loop in a defer statement to always make sure we have the
// resource status subresourcs up-to-date.
// updateStatus is called after every reconciliation loop in a defer statement to always make sure we have the
// KubeadmControlPlane status up-to-date.
func (r *KubeadmControlPlaneReconciler) updateStatus(ctx context.Context, controlPlane *internal.ControlPlane) error {
selector := collections.ControlPlaneSelectorForCluster(controlPlane.Cluster.Name)
// Copy label selector to its status counterpart in string format.
Expand Down Expand Up @@ -380,7 +380,6 @@ func setRemediatingCondition(ctx context.Context, kcp *controlplanev1.KubeadmCon
return
}

// TODO: Bring together externally remediated machines and owner remediated machines
remediatingCondition, err := v1beta2conditions.NewAggregateCondition(
machinesToBeRemediated.UnsortedList(), clusterv1.MachineOwnerRemediatedV1Beta2Condition,
v1beta2conditions.TargetConditionType(controlplanev1.KubeadmControlPlaneRemediatingV1Beta2Condition),
Expand All @@ -407,6 +406,10 @@ func setRemediatingCondition(ctx context.Context, kcp *controlplanev1.KubeadmCon
}

func aggregateStaleMachines(machines collections.Machines) string {
if len(machines) == 0 {
return ""
}

machineNames := []string{}
for _, machine := range machines {
if !machine.GetDeletionTimestamp().IsZero() && time.Since(machine.GetDeletionTimestamp().Time) > time.Minute*30 {
Expand Down Expand Up @@ -437,6 +440,10 @@ func aggregateStaleMachines(machines collections.Machines) string {
}

func aggregateUnhealthyMachines(machines collections.Machines) string {
if len(machines) == 0 {
return ""
}

machineNames := []string{}
for _, machine := range machines {
machineNames = append(machineNames, machine.GetName())
Expand Down
2 changes: 1 addition & 1 deletion internal/controllers/machine/machine_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ func (r *Reconciler) Reconcile(ctx context.Context, req ctrl.Request) (_ ctrl.Re
}

defer func() {
r.reconcileStatus(ctx, s)
r.updateStatus(ctx, s)

// Always attempt to patch the object and status after each reconciliation.
// Patch ObservedGeneration only if the reconciliation completed successfully
Expand Down
4 changes: 2 additions & 2 deletions internal/controllers/machine/machine_controller_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,13 @@ import (
v1beta2conditions "sigs.k8s.io/cluster-api/util/conditions/v1beta2"
)

// reconcileStatus reconciles Machine's status during the entire lifecycle of the machine.
// updateStatus update Machine's status.
// This implies that the code in this function should account for several edge cases e.g. machine being partially provisioned,
// machine being partially deleted but also for running machines being disrupted e.g. by deleting the node.
// Additionally, this func should ensure that the conditions managed by this controller are always set in order to
// comply with the recommendation in the Kubernetes API guidelines.
// Note: v1beta1 conditions are not managed by this func.
func (r *Reconciler) reconcileStatus(ctx context.Context, s *scope) {
func (r *Reconciler) updateStatus(ctx context.Context, s *scope) {
// Update status from the Bootstrap Config external resource.
// Note: some of the status fields derived from the Bootstrap Config are managed in reconcileBootstrap, e.g. status.BootstrapReady, etc.
// here we are taking care only of the delta (condition).
Expand Down
Loading