Skip to content

Commit b2517cc

Browse files
committed
Move maxInFlight
1 parent bffb64e commit b2517cc

26 files changed

+446
-147
lines changed

api/core/v1beta1/conversion.go

Lines changed: 48 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -829,13 +829,21 @@ func Convert_v1beta1_MachineDeploymentClass_To_v1beta2_MachineDeploymentClass(in
829829
if in.Strategy.RollingUpdate != nil && in.Strategy.RollingUpdate.DeletePolicy != nil {
830830
out.Deletion.Order = clusterv1.MachineSetDeletionOrder(*in.Strategy.RollingUpdate.DeletePolicy)
831831
}
832+
if in.Strategy.Remediation != nil && in.Strategy.Remediation.MaxInFlight != nil {
833+
if out.HealthCheck == nil {
834+
out.HealthCheck = &clusterv1.MachineDeploymentClassHealthCheck{}
835+
}
836+
out.HealthCheck.Remediation.MaxInFlight = in.Strategy.Remediation.MaxInFlight
837+
}
832838
}
833839
out.Deletion.NodeDrainTimeoutSeconds = clusterv1.ConvertToSeconds(in.NodeDrainTimeout)
834840
out.Deletion.NodeVolumeDetachTimeoutSeconds = clusterv1.ConvertToSeconds(in.NodeVolumeDetachTimeout)
835841
out.Deletion.NodeDeletionTimeoutSeconds = clusterv1.ConvertToSeconds(in.NodeDeletionTimeout)
836842

837843
if in.MachineHealthCheck != nil {
838-
out.HealthCheck = &clusterv1.MachineDeploymentClassHealthCheck{}
844+
if out.HealthCheck == nil {
845+
out.HealthCheck = &clusterv1.MachineDeploymentClassHealthCheck{}
846+
}
839847
for _, c := range in.MachineHealthCheck.UnhealthyConditions {
840848
out.HealthCheck.Checks.UnhealthyNodeConditions = append(out.HealthCheck.Checks.UnhealthyNodeConditions, clusterv1.UnhealthyNodeCondition{
841849
Type: c.Type,
@@ -884,6 +892,15 @@ func Convert_v1beta2_MachineDeploymentClass_To_v1beta1_MachineDeploymentClass(in
884892
}
885893
out.Strategy.RollingUpdate.DeletePolicy = ptr.To(string(in.Deletion.Order))
886894
}
895+
if in.HealthCheck != nil && in.HealthCheck.Remediation.MaxInFlight != nil {
896+
if out.Strategy == nil {
897+
out.Strategy = &MachineDeploymentStrategy{}
898+
}
899+
if out.Strategy.Remediation == nil {
900+
out.Strategy.Remediation = &RemediationStrategy{}
901+
}
902+
out.Strategy.Remediation.MaxInFlight = in.HealthCheck.Remediation.MaxInFlight
903+
}
887904
out.NodeDrainTimeout = clusterv1.ConvertFromSeconds(in.Deletion.NodeDrainTimeoutSeconds)
888905
out.NodeVolumeDetachTimeout = clusterv1.ConvertFromSeconds(in.Deletion.NodeVolumeDetachTimeoutSeconds)
889906
out.NodeDeletionTimeout = clusterv1.ConvertFromSeconds(in.Deletion.NodeDeletionTimeoutSeconds)
@@ -928,13 +945,21 @@ func Convert_v1beta1_MachineDeploymentTopology_To_v1beta2_MachineDeploymentTopol
928945
if in.Strategy.RollingUpdate != nil && in.Strategy.RollingUpdate.DeletePolicy != nil {
929946
out.Deletion.Order = clusterv1.MachineSetDeletionOrder(*in.Strategy.RollingUpdate.DeletePolicy)
930947
}
948+
if in.Strategy.Remediation != nil && in.Strategy.Remediation.MaxInFlight != nil {
949+
if out.HealthCheck == nil {
950+
out.HealthCheck = &clusterv1.MachineDeploymentTopologyHealthCheck{}
951+
}
952+
out.HealthCheck.Remediation.MaxInFlight = in.Strategy.Remediation.MaxInFlight
953+
}
931954
}
932955
out.Deletion.NodeDrainTimeoutSeconds = clusterv1.ConvertToSeconds(in.NodeDrainTimeout)
933956
out.Deletion.NodeVolumeDetachTimeoutSeconds = clusterv1.ConvertToSeconds(in.NodeVolumeDetachTimeout)
934957
out.Deletion.NodeDeletionTimeoutSeconds = clusterv1.ConvertToSeconds(in.NodeDeletionTimeout)
935958

936959
if in.MachineHealthCheck != nil {
937-
out.HealthCheck = &clusterv1.MachineDeploymentTopologyHealthCheck{}
960+
if out.HealthCheck == nil {
961+
out.HealthCheck = &clusterv1.MachineDeploymentTopologyHealthCheck{}
962+
}
938963
out.HealthCheck.Enabled = in.MachineHealthCheck.Enable
939964
for _, c := range in.MachineHealthCheck.UnhealthyConditions {
940965
out.HealthCheck.Checks.UnhealthyNodeConditions = append(out.HealthCheck.Checks.UnhealthyNodeConditions, clusterv1.UnhealthyNodeCondition{
@@ -981,6 +1006,15 @@ func Convert_v1beta2_MachineDeploymentTopology_To_v1beta1_MachineDeploymentTopol
9811006
}
9821007
out.Strategy.RollingUpdate.DeletePolicy = ptr.To(string(in.Deletion.Order))
9831008
}
1009+
if in.HealthCheck != nil && in.HealthCheck.Remediation.MaxInFlight != nil {
1010+
if out.Strategy == nil {
1011+
out.Strategy = &MachineDeploymentStrategy{}
1012+
}
1013+
if out.Strategy.Remediation == nil {
1014+
out.Strategy.Remediation = &RemediationStrategy{}
1015+
}
1016+
out.Strategy.Remediation.MaxInFlight = in.HealthCheck.Remediation.MaxInFlight
1017+
}
9841018
out.NodeDrainTimeout = clusterv1.ConvertFromSeconds(in.Deletion.NodeDrainTimeoutSeconds)
9851019
out.NodeVolumeDetachTimeout = clusterv1.ConvertFromSeconds(in.Deletion.NodeVolumeDetachTimeoutSeconds)
9861020
out.NodeDeletionTimeout = clusterv1.ConvertFromSeconds(in.Deletion.NodeDeletionTimeoutSeconds)
@@ -2028,6 +2062,9 @@ func Convert_v1beta1_MachineDeploymentSpec_To_v1beta2_MachineDeploymentSpec(in *
20282062
if in.Strategy.RollingUpdate != nil && in.Strategy.RollingUpdate.DeletePolicy != nil {
20292063
out.Deletion.Order = clusterv1.MachineSetDeletionOrder(*in.Strategy.RollingUpdate.DeletePolicy)
20302064
}
2065+
if in.Strategy.Remediation != nil && in.Strategy.Remediation.MaxInFlight != nil {
2066+
out.Remediation.MaxInFlight = in.Strategy.Remediation.MaxInFlight
2067+
}
20312068
}
20322069

20332070
return nil
@@ -2052,6 +2089,15 @@ func Convert_v1beta2_MachineDeploymentSpec_To_v1beta1_MachineDeploymentSpec(in *
20522089
}
20532090
out.Strategy.RollingUpdate.DeletePolicy = ptr.To(string(in.Deletion.Order))
20542091
}
2092+
if in.Remediation.MaxInFlight != nil {
2093+
if out.Strategy == nil {
2094+
out.Strategy = &MachineDeploymentStrategy{}
2095+
}
2096+
if out.Strategy.Remediation == nil {
2097+
out.Strategy.Remediation = &RemediationStrategy{}
2098+
}
2099+
out.Strategy.Remediation.MaxInFlight = in.Remediation.MaxInFlight
2100+
}
20552101

20562102
return nil
20572103
}
@@ -2065,11 +2111,6 @@ func Convert_v1beta1_MachineDeploymentStrategy_To_v1beta2_MachineDeploymentStrat
20652111
return err
20662112
}
20672113
}
2068-
if in.Remediation != nil {
2069-
if err := Convert_v1beta1_RemediationStrategy_To_v1beta2_RemediationStrategy(in.Remediation, &out.Remediation, s); err != nil {
2070-
return err
2071-
}
2072-
}
20732114

20742115
return nil
20752116
}
@@ -2084,12 +2125,6 @@ func Convert_v1beta2_MachineDeploymentStrategy_To_v1beta1_MachineDeploymentStrat
20842125
return err
20852126
}
20862127
}
2087-
if !reflect.DeepEqual(in.Remediation, clusterv1.RemediationStrategy{}) {
2088-
out.Remediation = &RemediationStrategy{}
2089-
if err := Convert_v1beta2_RemediationStrategy_To_v1beta1_RemediationStrategy(&in.Remediation, out.Remediation, s); err != nil {
2090-
return err
2091-
}
2092-
}
20932128

20942129
return nil
20952130
}

api/core/v1beta1/conversion_test.go

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import (
3333
"k8s.io/apimachinery/pkg/runtime/schema"
3434
runtimeserializer "k8s.io/apimachinery/pkg/runtime/serializer"
3535
"k8s.io/apimachinery/pkg/types"
36+
"k8s.io/apimachinery/pkg/util/intstr"
3637
"k8s.io/utils/ptr"
3738
"sigs.k8s.io/randfill"
3839

@@ -125,6 +126,15 @@ func hubClusterSpec(in *clusterv1.ClusterSpec, c randfill.Continue) {
125126
in.ControlPlaneRef.APIGroup = gvk.Group
126127
in.ControlPlaneRef.Kind = gvk.Kind
127128
}
129+
130+
if in.Topology != nil && len(in.Topology.Workers.MachineDeployments) > 0 {
131+
if in.Topology.Workers.MachineDeployments[0].HealthCheck != nil {
132+
if c.Bool() {
133+
// Somehow this field doesn't get set otherwise.
134+
in.Topology.Workers.MachineDeployments[0].HealthCheck.Remediation.MaxInFlight = ptr.To(intstr.FromInt32(c.Int31n(50)))
135+
}
136+
}
137+
}
128138
}
129139

130140
func hubClusterStatus(in *clusterv1.ClusterStatus, c randfill.Continue) {
@@ -254,6 +264,7 @@ func spokeClusterVariable(in *ClusterVariable, c randfill.Continue) {
254264

255265
func ClusterClassFuncs(_ runtimeserializer.CodecFactory) []interface{} {
256266
return []interface{}{
267+
hubClusterClassSpec,
257268
hubClusterClassStatus,
258269
hubJSONPatch,
259270
hubJSONSchemaProps,
@@ -271,6 +282,19 @@ func ClusterClassFuncs(_ runtimeserializer.CodecFactory) []interface{} {
271282
}
272283
}
273284

285+
func hubClusterClassSpec(in *clusterv1.ClusterClassSpec, c randfill.Continue) {
286+
c.FillNoCustom(in)
287+
288+
if len(in.Workers.MachineDeployments) > 0 {
289+
if in.Workers.MachineDeployments[0].HealthCheck != nil {
290+
if c.Bool() {
291+
// Somehow this field doesn't get set otherwise.
292+
in.Workers.MachineDeployments[0].HealthCheck.Remediation.MaxInFlight = ptr.To(intstr.FromInt32(c.Int31n(50)))
293+
}
294+
}
295+
}
296+
}
297+
274298
func hubClusterClassStatus(in *clusterv1.ClusterClassStatus, c randfill.Continue) {
275299
c.FillNoCustom(in)
276300
// Drop empty structs with only omit empty fields.
@@ -579,6 +603,7 @@ func spokeMachineSetStatus(in *MachineSetStatus, c randfill.Continue) {
579603

580604
func MachineDeploymentFuzzFuncs(_ runtimeserializer.CodecFactory) []interface{} {
581605
return []interface{}{
606+
hubMachineDeploymentSpec,
582607
hubMachineDeploymentStatus,
583608
hubMachineSpec,
584609
spokeMachineDeployment,
@@ -588,6 +613,25 @@ func MachineDeploymentFuzzFuncs(_ runtimeserializer.CodecFactory) []interface{}
588613
}
589614
}
590615

616+
func hubMachineDeploymentSpec(in *clusterv1.MachineDeploymentSpec, c randfill.Continue) {
617+
c.FillNoCustom(in)
618+
619+
// Ensure ref fields are always set to realistic values.
620+
gvk := testGVKs[c.Int31n(4)]
621+
in.Template.Spec.InfrastructureRef.APIGroup = gvk.Group
622+
in.Template.Spec.InfrastructureRef.Kind = gvk.Kind
623+
if in.Template.Spec.Bootstrap.ConfigRef != nil {
624+
gvk := testGVKs[c.Int31n(4)]
625+
in.Template.Spec.Bootstrap.ConfigRef.APIGroup = gvk.Group
626+
in.Template.Spec.Bootstrap.ConfigRef.Kind = gvk.Kind
627+
}
628+
629+
if c.Bool() {
630+
// Somehow this field doesn't get set otherwise.
631+
in.Remediation.MaxInFlight = ptr.To(intstr.FromInt32(c.Int31n(50)))
632+
}
633+
}
634+
591635
func hubMachineDeploymentStatus(in *clusterv1.MachineDeploymentStatus, c randfill.Continue) {
592636
c.FillNoCustom(in)
593637
// Always create struct with at least one mandatory fields.
@@ -631,6 +675,12 @@ func spokeMachineDeploymentSpec(in *MachineDeploymentSpec, c randfill.Continue)
631675
in.Strategy.RollingUpdate = nil
632676
}
633677
}
678+
if in.Strategy.Remediation != nil {
679+
if c.Bool() {
680+
// Somehow this field doesn't get set otherwise.
681+
in.Strategy.Remediation.MaxInFlight = ptr.To(intstr.FromInt32(c.Int31n(50)))
682+
}
683+
}
634684
if in.Strategy.Remediation != nil && reflect.DeepEqual(in.Strategy.Remediation, &RemediationStrategy{}) {
635685
in.Strategy.Remediation = nil
636686
}
@@ -790,6 +840,12 @@ func spokeMachineDeploymentTopology(in *MachineDeploymentTopology, c randfill.Co
790840
in.Strategy.RollingUpdate = nil
791841
}
792842
}
843+
if in.Strategy.Remediation != nil {
844+
if c.Bool() {
845+
// Somehow this field doesn't get set otherwise.
846+
in.Strategy.Remediation.MaxInFlight = ptr.To(intstr.FromInt32(c.Int31n(50)))
847+
}
848+
}
793849
if in.Strategy.Remediation != nil && reflect.DeepEqual(in.Strategy.Remediation, &RemediationStrategy{}) {
794850
in.Strategy.Remediation = nil
795851
}
@@ -860,6 +916,12 @@ func spokeMachineDeploymentClass(in *MachineDeploymentClass, c randfill.Continue
860916
in.Strategy.RollingUpdate = nil
861917
}
862918
}
919+
if in.Strategy.Remediation != nil {
920+
if c.Bool() {
921+
// Somehow this field doesn't get set otherwise.
922+
in.Strategy.Remediation.MaxInFlight = ptr.To(intstr.FromInt32(c.Int31n(50)))
923+
}
924+
}
863925
if in.Strategy.Remediation != nil && reflect.DeepEqual(in.Strategy.Remediation, &RemediationStrategy{}) {
864926
in.Strategy.Remediation = nil
865927
}

api/core/v1beta1/zz_generated.conversion.go

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/core/v1beta2/cluster_types.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -946,6 +946,24 @@ type MachineDeploymentTopologyHealthCheckChecks struct {
946946
// MachineDeploymentTopologyHealthCheckRemediation configures if and how remediations are triggered if a MachineDeployment Machine is unhealthy.
947947
// +kubebuilder:validation:MinProperties=1
948948
type MachineDeploymentTopologyHealthCheckRemediation struct {
949+
// maxInFlight determines how many in flight remediations should happen at the same time.
950+
//
951+
// Remediation only happens on the MachineSet with the most current revision, while
952+
// older MachineSets (usually present during rollout operations) aren't allowed to remediate.
953+
//
954+
// Note: In general (independent of remediations), unhealthy machines are always
955+
// prioritized during scale down operations over healthy ones.
956+
//
957+
// MaxInFlight can be set to a fixed number or a percentage.
958+
// Example: when this is set to 20%, the MachineSet controller deletes at most 20% of
959+
// the desired replicas.
960+
//
961+
// If not set, remediation is limited to all machines (bounded by replicas)
962+
// under the active MachineSet's management.
963+
//
964+
// +optional
965+
MaxInFlight *intstr.IntOrString `json:"maxInFlight,omitempty"`
966+
949967
// triggerIf configures if remediations are triggered.
950968
// If this field is not set, remediations are always triggered.
951969
// +optional

api/core/v1beta2/clusterclass_types.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -498,6 +498,24 @@ type MachineDeploymentClassHealthCheckChecks struct {
498498
// MachineDeploymentClassHealthCheckRemediation configures if and how remediations are triggered if a MachineDeployment Machine is unhealthy.
499499
// +kubebuilder:validation:MinProperties=1
500500
type MachineDeploymentClassHealthCheckRemediation struct {
501+
// maxInFlight determines how many in flight remediations should happen at the same time.
502+
//
503+
// Remediation only happens on the MachineSet with the most current revision, while
504+
// older MachineSets (usually present during rollout operations) aren't allowed to remediate.
505+
//
506+
// Note: In general (independent of remediations), unhealthy machines are always
507+
// prioritized during scale down operations over healthy ones.
508+
//
509+
// MaxInFlight can be set to a fixed number or a percentage.
510+
// Example: when this is set to 20%, the MachineSet controller deletes at most 20% of
511+
// the desired replicas.
512+
//
513+
// If not set, remediation is limited to all machines (bounded by replicas)
514+
// under the active MachineSet's management.
515+
//
516+
// +optional
517+
MaxInFlight *intstr.IntOrString `json:"maxInFlight,omitempty"`
518+
501519
// triggerIf configures if remediations are triggered.
502520
// If this field is not set, remediations are always triggered.
503521
// +optional

api/core/v1beta2/machinedeployment_types.go

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,10 @@ type MachineDeploymentSpec struct {
291291
// +optional
292292
MachineNamingStrategy *MachineNamingStrategy `json:"machineNamingStrategy,omitempty"`
293293

294+
// remediation controls how unhealthy Machines are remediated.
295+
// +optional
296+
Remediation MachineDeploymentRemediationSpec `json:"remediation,omitempty,omitzero"`
297+
294298
// deletion contains configuration options for MachineDeployment deletion.
295299
// +optional
296300
Deletion MachineDeploymentDeletionSpec `json:"deletion,omitempty,omitzero"`
@@ -317,11 +321,6 @@ type MachineDeploymentStrategy struct {
317321
// MachineDeploymentStrategyType = RollingUpdate.
318322
// +optional
319323
RollingUpdate MachineDeploymentStrategyRollingUpdate `json:"rollingUpdate,omitempty,omitzero"`
320-
321-
// remediation controls the strategy of remediating unhealthy machines
322-
// and how remediating operations should occur during the lifecycle of the dependant MachineSets.
323-
// +optional
324-
Remediation RemediationStrategy `json:"remediation,omitempty,omitzero"`
325324
}
326325

327326
// ANCHOR_END: MachineDeploymentStrategy
@@ -391,6 +390,28 @@ type RemediationStrategy struct {
391390

392391
// ANCHOR_END: RemediationStrategy
393392

393+
// MachineDeploymentRemediationSpec controls how unhealthy Machines are remediated.
394+
// +kubebuilder:validation:MinProperties=1
395+
type MachineDeploymentRemediationSpec struct {
396+
// maxInFlight determines how many in flight remediations should happen at the same time.
397+
//
398+
// Remediation only happens on the MachineSet with the most current revision, while
399+
// older MachineSets (usually present during rollout operations) aren't allowed to remediate.
400+
//
401+
// Note: In general (independent of remediations), unhealthy machines are always
402+
// prioritized during scale down operations over healthy ones.
403+
//
404+
// MaxInFlight can be set to a fixed number or a percentage.
405+
// Example: when this is set to 20%, the MachineSet controller deletes at most 20% of
406+
// the desired replicas.
407+
//
408+
// If not set, remediation is limited to all machines (bounded by replicas)
409+
// under the active MachineSet's management.
410+
//
411+
// +optional
412+
MaxInFlight *intstr.IntOrString `json:"maxInFlight,omitempty"`
413+
}
414+
394415
// MachineNamingStrategy allows changing the naming pattern used when creating
395416
// Machines.
396417
// Note: InfraMachines & BootstrapConfigs will use the same name as the corresponding Machines.

0 commit comments

Comments
 (0)