Skip to content

Commit

Permalink
MachinePool annotation for externally managed autoscaler
Browse files Browse the repository at this point in the history
  • Loading branch information
jackfrancis committed Aug 23, 2022
1 parent fa70f61 commit 3fb89fa
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
4 changes: 4 additions & 0 deletions api/v1beta1/common_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,10 @@ const (
// any changes to the actual object because it is a dry run) and the topology controller
// will receive the resulting object.
TopologyDryRunAnnotation = "topology.cluster.x-k8s.io/dry-run"

// ReplicasManagedByAutoscalerAnnotation is an annotation that indicates an external autoscaler controls replica count.
// This annotation can be used to inform MachinePool status during in-progress scaling scenarios.
ReplicasManagedByAutoscalerAnnotation = "cluster.x-k8s.io/replicas-managed-by-autoscaler"
)

const (
Expand Down
12 changes: 10 additions & 2 deletions exp/internal/controllers/machinepool_controller_phases.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,20 @@ func (r *MachinePoolReconciler) reconcilePhase(mp *expv1.MachinePool) {

// Set the phase to "scalingUp" if the infrastructure is scaling up.
if mp.Status.InfrastructureReady && *mp.Spec.Replicas > mp.Status.ReadyReplicas {
mp.Status.SetTypedPhase(expv1.MachinePoolPhaseScalingUp)
if mp.Annotations[clusterv1.ReplicasManagedByAutoscalerAnnotation] == "true" {
mp.Status.SetTypedPhase(expv1.MachinePoolPhasePending)
} else {
mp.Status.SetTypedPhase(expv1.MachinePoolPhaseScalingUp)
}
}

// Set the phase to "scalingDown" if the infrastructure is scaling down.
if mp.Status.InfrastructureReady && *mp.Spec.Replicas < mp.Status.ReadyReplicas {
mp.Status.SetTypedPhase(expv1.MachinePoolPhaseScalingDown)
if mp.Annotations[clusterv1.ReplicasManagedByAutoscalerAnnotation] == "true" {
mp.Status.SetTypedPhase(expv1.MachinePoolPhasePending)
} else {
mp.Status.SetTypedPhase(expv1.MachinePoolPhaseScalingDown)
}
}

// Set the phase to "failed" if any of Status.FailureReason or Status.FailureMessage is not-nil.
Expand Down

0 comments on commit 3fb89fa

Please sign in to comment.