Skip to content

Commit fba0337

Browse files
committed
✨ Add remediation strategy support for MachineSet
Signed-off-by: Vince Prignano <[email protected]> tests Signed-off-by: Vince Prignano <[email protected]>
1 parent 9cb5d3c commit fba0337

16 files changed

+746
-53
lines changed

Diff for: api/v1beta1/machinedeployment_types.go

+30
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,11 @@ type MachineDeploymentStrategy struct {
162162
// MachineDeploymentStrategyType = RollingUpdate.
163163
// +optional
164164
RollingUpdate *MachineRollingUpdateDeployment `json:"rollingUpdate,omitempty"`
165+
166+
// Remediation controls the strategy of remediating unhealthy machines
167+
// and how remediating operations should occur during the lifecycle of the dependant MachineSets.
168+
// +optional
169+
Remediation *RemediationStrategy `json:"remediation,omitempty"`
165170
}
166171

167172
// ANCHOR_END: MachineDeploymentStrategy
@@ -211,6 +216,31 @@ type MachineRollingUpdateDeployment struct {
211216

212217
// ANCHOR_END: MachineRollingUpdateDeployment
213218

219+
// ANCHOR: RemediationStrategy
220+
221+
// RemediationStrategy allows to define how the MachineSet can control scaling operations.
222+
type RemediationStrategy struct {
223+
// MaxInFlight determines how many in flight remediations should happen at the same time.
224+
//
225+
// Remediation only happens on the MachineSet with the most current revision, while
226+
// older MachineSets (usually present during rollout operations) aren't allowed to remediate.
227+
//
228+
// Note: In general (independent of remediations), unhealthy machines are always
229+
// prioritized during scale down operations over healthy ones.
230+
//
231+
// MaxInFlight can be set to a fixed number or a percentage.
232+
// Example: when this is set to 20%, the MachineSet controller deletes at most 20% of
233+
// the desired replicas.
234+
//
235+
// If not set, remediation is limited to all machines (bounded by replicas)
236+
// under the active MachineSet's management.
237+
//
238+
// +optional
239+
MaxInFlight *intstr.IntOrString `json:"maxInFlight,omitempty"`
240+
}
241+
242+
// ANCHOR_END: RemediationStrategy
243+
214244
// ANCHOR: MachineDeploymentStatus
215245

216246
// MachineDeploymentStatus defines the observed state of MachineDeployment.

Diff for: api/v1beta1/zz_generated.deepcopy.go

+25
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: api/v1beta1/zz_generated.openapi.go

+29-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: config/crd/bases/cluster.x-k8s.io_clusterclasses.yaml

+30
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: config/crd/bases/cluster.x-k8s.io_clusters.yaml

+30
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: config/crd/bases/cluster.x-k8s.io_machinedeployments.yaml

+30
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: exp/topology/desiredstate/desired_state_test.go

+6
Original file line numberDiff line numberDiff line change
@@ -1329,6 +1329,9 @@ func TestComputeMachineDeployment(t *testing.T) {
13291329
var clusterClassMinReadySeconds int32 = 20
13301330
clusterClassStrategy := clusterv1.MachineDeploymentStrategy{
13311331
Type: clusterv1.OnDeleteMachineDeploymentStrategyType,
1332+
Remediation: &clusterv1.RemediationStrategy{
1333+
MaxInFlight: ptr.To(intstr.FromInt32(5)),
1334+
},
13321335
}
13331336
md1 := builder.MachineDeploymentClass("linux-worker").
13341337
WithLabels(labels).
@@ -1390,6 +1393,9 @@ func TestComputeMachineDeployment(t *testing.T) {
13901393
var topologyMinReadySeconds int32 = 10
13911394
topologyStrategy := clusterv1.MachineDeploymentStrategy{
13921395
Type: clusterv1.RollingUpdateMachineDeploymentStrategyType,
1396+
Remediation: &clusterv1.RemediationStrategy{
1397+
MaxInFlight: ptr.To(intstr.FromInt32(5)),
1398+
},
13931399
}
13941400
mdTopology := clusterv1.MachineDeploymentTopology{
13951401
Metadata: clusterv1.ObjectMeta{

Diff for: internal/apis/core/v1alpha3/conversion.go

+15-4
Original file line numberDiff line numberDiff line change
@@ -187,14 +187,17 @@ func (src *MachineDeployment) ConvertTo(dstRaw conversion.Hub) error {
187187
return err
188188
}
189189

190-
if restored.Spec.Strategy != nil && restored.Spec.Strategy.RollingUpdate != nil {
190+
if restored.Spec.Strategy != nil {
191191
if dst.Spec.Strategy == nil {
192192
dst.Spec.Strategy = &clusterv1.MachineDeploymentStrategy{}
193193
}
194-
if dst.Spec.Strategy.RollingUpdate == nil {
195-
dst.Spec.Strategy.RollingUpdate = &clusterv1.MachineRollingUpdateDeployment{}
194+
if restored.Spec.Strategy.RollingUpdate != nil {
195+
if dst.Spec.Strategy.RollingUpdate == nil {
196+
dst.Spec.Strategy.RollingUpdate = &clusterv1.MachineRollingUpdateDeployment{}
197+
}
198+
dst.Spec.Strategy.RollingUpdate.DeletePolicy = restored.Spec.Strategy.RollingUpdate.DeletePolicy
196199
}
197-
dst.Spec.Strategy.RollingUpdate.DeletePolicy = restored.Spec.Strategy.RollingUpdate.DeletePolicy
200+
dst.Spec.Strategy.Remediation = restored.Spec.Strategy.Remediation
198201
}
199202

200203
dst.Spec.Template.Spec.NodeDeletionTimeout = restored.Spec.Template.Spec.NodeDeletionTimeout
@@ -330,3 +333,11 @@ func Convert_v1alpha3_MachineStatus_To_v1beta1_MachineStatus(in *MachineStatus,
330333
// Status.version has been removed in v1beta1, thus requiring custom conversion function. the information will be dropped.
331334
return autoConvert_v1alpha3_MachineStatus_To_v1beta1_MachineStatus(in, out, s)
332335
}
336+
337+
func Convert_v1beta1_MachineDeploymentStrategy_To_v1alpha3_MachineDeploymentStrategy(in *clusterv1.MachineDeploymentStrategy, out *MachineDeploymentStrategy, s apiconversion.Scope) error {
338+
return autoConvert_v1beta1_MachineDeploymentStrategy_To_v1alpha3_MachineDeploymentStrategy(in, out, s)
339+
}
340+
341+
func Convert_v1beta1_MachineSetSpec_To_v1alpha3_MachineSetSpec(in *clusterv1.MachineSetSpec, out *MachineSetSpec, s apiconversion.Scope) error {
342+
return autoConvert_v1beta1_MachineSetSpec_To_v1alpha3_MachineSetSpec(in, out, s)
343+
}

0 commit comments

Comments
 (0)