Skip to content

Commit

Permalink
✨ Add remediation strategy support for MachineSet
Browse files Browse the repository at this point in the history
Signed-off-by: Vince Prignano <vince@prigna.com>

tests

Signed-off-by: Vince Prignano <vince@prigna.com>
  • Loading branch information
vincepri committed Jun 12, 2024
1 parent f1f8f38 commit cc82df0
Show file tree
Hide file tree
Showing 16 changed files with 746 additions and 53 deletions.
30 changes: 30 additions & 0 deletions api/v1beta1/machinedeployment_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,11 @@ type MachineDeploymentStrategy struct {
// MachineDeploymentStrategyType = RollingUpdate.
// +optional
RollingUpdate *MachineRollingUpdateDeployment `json:"rollingUpdate,omitempty"`

// Remediation controls the strategy of remediating unhealthy machines
// and how remediating operations should occur during the lifecycle of the dependant MachineSets.
// +optional
Remediation *RemediationStrategy `json:"remediation,omitempty"`
}

// ANCHOR_END: MachineDeploymentStrategy
Expand Down Expand Up @@ -211,6 +216,31 @@ type MachineRollingUpdateDeployment struct {

// ANCHOR_END: MachineRollingUpdateDeployment

// ANCHOR: RemediationStrategy

// RemediationStrategy allows to define how the MachineSet can control scaling operations.
type RemediationStrategy struct {
// MaxInFlight determines how many in flight remediations should happen at the same time.
//
// Remediation only happens on the MachineSet with the most current revision, while
// older MachineSets (usually present during rollout operations) aren't allowed to remediate.
//
// Note: In general (independent of remediations), unhealthy machines are always
// prioritized during scale down operations over healthy ones.
//
// MaxInFlight can be set to a fixed number or a percentage.
// Example: when this is set to 20%, the MachineSet controller deletes at most 20% of
// the desired replicas.
//
// If not set, remediation is limited to all machines (bounded by replicas)
// under the active MachineSet's management.
//
// +optional
MaxInFlight *intstr.IntOrString `json:"maxInFlight,omitempty"`
}

// ANCHOR_END: RemediationStrategy

// ANCHOR: MachineDeploymentStatus

// MachineDeploymentStatus defines the observed state of MachineDeployment.
Expand Down
25 changes: 25 additions & 0 deletions api/v1beta1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 29 additions & 1 deletion api/v1beta1/zz_generated.openapi.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 30 additions & 0 deletions config/crd/bases/cluster.x-k8s.io_clusterclasses.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 30 additions & 0 deletions config/crd/bases/cluster.x-k8s.io_clusters.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 30 additions & 0 deletions config/crd/bases/cluster.x-k8s.io_machinedeployments.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions exp/topology/desiredstate/desired_state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1329,6 +1329,9 @@ func TestComputeMachineDeployment(t *testing.T) {
var clusterClassMinReadySeconds int32 = 20
clusterClassStrategy := clusterv1.MachineDeploymentStrategy{
Type: clusterv1.OnDeleteMachineDeploymentStrategyType,
Remediation: &clusterv1.RemediationStrategy{
MaxInFlight: ptr.To(intstr.FromInt32(5)),
},
}
md1 := builder.MachineDeploymentClass("linux-worker").
WithLabels(labels).
Expand Down Expand Up @@ -1390,6 +1393,9 @@ func TestComputeMachineDeployment(t *testing.T) {
var topologyMinReadySeconds int32 = 10
topologyStrategy := clusterv1.MachineDeploymentStrategy{
Type: clusterv1.RollingUpdateMachineDeploymentStrategyType,
Remediation: &clusterv1.RemediationStrategy{
MaxInFlight: ptr.To(intstr.FromInt32(5)),
},
}
mdTopology := clusterv1.MachineDeploymentTopology{
Metadata: clusterv1.ObjectMeta{
Expand Down
19 changes: 15 additions & 4 deletions internal/apis/core/v1alpha3/conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,14 +187,17 @@ func (src *MachineDeployment) ConvertTo(dstRaw conversion.Hub) error {
return err
}

if restored.Spec.Strategy != nil && restored.Spec.Strategy.RollingUpdate != nil {
if restored.Spec.Strategy != nil {
if dst.Spec.Strategy == nil {
dst.Spec.Strategy = &clusterv1.MachineDeploymentStrategy{}
}
if dst.Spec.Strategy.RollingUpdate == nil {
dst.Spec.Strategy.RollingUpdate = &clusterv1.MachineRollingUpdateDeployment{}
if restored.Spec.Strategy.RollingUpdate != nil {
if dst.Spec.Strategy.RollingUpdate == nil {
dst.Spec.Strategy.RollingUpdate = &clusterv1.MachineRollingUpdateDeployment{}
}
dst.Spec.Strategy.RollingUpdate.DeletePolicy = restored.Spec.Strategy.RollingUpdate.DeletePolicy
}
dst.Spec.Strategy.RollingUpdate.DeletePolicy = restored.Spec.Strategy.RollingUpdate.DeletePolicy
dst.Spec.Strategy.Remediation = restored.Spec.Strategy.Remediation
}

dst.Spec.Template.Spec.NodeDeletionTimeout = restored.Spec.Template.Spec.NodeDeletionTimeout
Expand Down Expand Up @@ -330,3 +333,11 @@ func Convert_v1alpha3_MachineStatus_To_v1beta1_MachineStatus(in *MachineStatus,
// Status.version has been removed in v1beta1, thus requiring custom conversion function. the information will be dropped.
return autoConvert_v1alpha3_MachineStatus_To_v1beta1_MachineStatus(in, out, s)
}

func Convert_v1beta1_MachineDeploymentStrategy_To_v1alpha3_MachineDeploymentStrategy(in *clusterv1.MachineDeploymentStrategy, out *MachineDeploymentStrategy, s apiconversion.Scope) error {
return autoConvert_v1beta1_MachineDeploymentStrategy_To_v1alpha3_MachineDeploymentStrategy(in, out, s)
}

func Convert_v1beta1_MachineSetSpec_To_v1alpha3_MachineSetSpec(in *clusterv1.MachineSetSpec, out *MachineSetSpec, s apiconversion.Scope) error {
return autoConvert_v1beta1_MachineSetSpec_To_v1alpha3_MachineSetSpec(in, out, s)
}
Loading

0 comments on commit cc82df0

Please sign in to comment.