Skip to content

Commit 9af9589

Browse files
committed
Remediate unhealthy MachinePool machines
1 parent 781ff73 commit 9af9589

30 files changed

+749
-62
lines changed

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -603,6 +603,7 @@ generate-e2e-templates-v1.11: $(KUSTOMIZE)
603603
generate-e2e-templates-main: $(KUSTOMIZE)
604604
$(KUSTOMIZE) build $(DOCKER_TEMPLATES)/main/cluster-template --load-restrictor LoadRestrictionsNone > $(DOCKER_TEMPLATES)/main/cluster-template.yaml
605605
$(KUSTOMIZE) build $(DOCKER_TEMPLATES)/main/cluster-template-md-remediation --load-restrictor LoadRestrictionsNone > $(DOCKER_TEMPLATES)/main/cluster-template-md-remediation.yaml
606+
$(KUSTOMIZE) build $(DOCKER_TEMPLATES)/main/cluster-template-mp-remediation --load-restrictor LoadRestrictionsNone > $(DOCKER_TEMPLATES)/main/cluster-template-mp-remediation.yaml
606607
$(KUSTOMIZE) build $(DOCKER_TEMPLATES)/main/cluster-template-kcp-remediation --load-restrictor LoadRestrictionsNone > $(DOCKER_TEMPLATES)/main/cluster-template-kcp-remediation.yaml
607608
$(KUSTOMIZE) build $(DOCKER_TEMPLATES)/main/cluster-template-kcp-adoption/step1 --load-restrictor LoadRestrictionsNone > $(DOCKER_TEMPLATES)/main/cluster-template-kcp-adoption.yaml
608609
echo "---" >> $(DOCKER_TEMPLATES)/main/cluster-template-kcp-adoption.yaml

api/core/v1beta1/conversion.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1877,6 +1877,10 @@ func Convert_v1beta1_MachinePoolSpec_To_v1beta2_MachinePoolSpec(in *MachinePoolS
18771877
return autoConvert_v1beta1_MachinePoolSpec_To_v1beta2_MachinePoolSpec(in, out, s)
18781878
}
18791879

1880+
func Convert_v1beta2_MachinePoolSpec_To_v1beta1_MachinePoolSpec(in *clusterv1.MachinePoolSpec, out *MachinePoolSpec, s apimachineryconversion.Scope) error {
1881+
return autoConvert_v1beta2_MachinePoolSpec_To_v1beta1_MachinePoolSpec(in, out, s)
1882+
}
1883+
18801884
func Convert_v1beta1_ClusterClassStatusVariableDefinition_To_v1beta2_ClusterClassStatusVariableDefinition(in *ClusterClassStatusVariableDefinition, out *clusterv1.ClusterClassStatusVariableDefinition, s apimachineryconversion.Scope) error {
18811885
if err := autoConvert_v1beta1_ClusterClassStatusVariableDefinition_To_v1beta2_ClusterClassStatusVariableDefinition(in, out, s); err != nil {
18821886
return err

api/core/v1beta1/conversion_test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -784,6 +784,7 @@ func spokeObjectReference(in *corev1.ObjectReference, c randfill.Continue) {
784784

785785
func MachinePoolFuzzFuncs(_ runtimeserializer.CodecFactory) []interface{} {
786786
return []interface{}{
787+
hubMachinePoolSpec,
787788
hubMachinePoolStatus,
788789
hubMachineSpec,
789790
spokeMachinePool,
@@ -792,6 +793,13 @@ func MachinePoolFuzzFuncs(_ runtimeserializer.CodecFactory) []interface{} {
792793
}
793794
}
794795

796+
func hubMachinePoolSpec(in *clusterv1.MachinePoolSpec, c randfill.Continue) {
797+
c.FillNoCustom(in)
798+
799+
// Readded in v1beta2 with different type than in v1alpha's, no conversion possible
800+
in.Remediation = clusterv1.MachinePoolRemediationSpec{}
801+
}
802+
795803
func hubMachinePoolStatus(in *clusterv1.MachinePoolStatus, c randfill.Continue) {
796804
c.FillNoCustom(in)
797805
// Always create struct with at least one mandatory fields.

api/core/v1beta1/machinepool_types.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,17 @@ type MachinePoolSpec struct {
104104
FailureDomains []string `json:"failureDomains,omitempty"`
105105
}
106106

107+
// MachinePoolStrategy describes how to replace existing machines
108+
// with new ones.
109+
type MachinePoolStrategy struct {
110+
// remediation controls the strategy of remediating unhealthy machines
111+
// as marked by a MachineHealthCheck. This only applies to infrastructure
112+
// providers supporting "MachinePool Machines". For other providers,
113+
// no remediation is done.
114+
// +optional
115+
Remediation *RemediationStrategy `json:"remediation,omitempty"`
116+
}
117+
107118
// MachinePoolStatus defines the observed state of MachinePool.
108119
type MachinePoolStatus struct {
109120
// nodeRefs will point to the corresponding Nodes if it they exist.

api/core/v1beta1/zz_generated.conversion.go

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

api/core/v1beta1/zz_generated.deepcopy.go

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

api/core/v1beta1/zz_generated.openapi.go

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

api/core/v1beta2/machinepool_types.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package v1beta2
1919
import (
2020
corev1 "k8s.io/api/core/v1"
2121
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
22+
"k8s.io/apimachinery/pkg/util/intstr"
2223

2324
capierrors "sigs.k8s.io/cluster-api/errors"
2425
)
@@ -97,6 +98,29 @@ type MachinePoolSpec struct {
9798
// +kubebuilder:validation:items:MinLength=1
9899
// +kubebuilder:validation:items:MaxLength=256
99100
FailureDomains []string `json:"failureDomains,omitempty"`
101+
102+
// remediation controls how unhealthy Machines are remediated (through a MachineHealthCheck).
103+
// This only applies to infrastructure providers supporting and enabling the
104+
// "MachinePool Machines" feature. For other setups, no remediation is done.
105+
// +optional
106+
Remediation MachinePoolRemediationSpec `json:"remediation,omitempty,omitzero"`
107+
}
108+
109+
// MachinePoolRemediationSpec controls how unhealthy Machines are remediated (through a MachineHealthCheck).
110+
// This only applies to infrastructure providers supporting and enabling the
111+
// "MachinePool Machines" feature. For other setups, no remediation is done.
112+
// +kubebuilder:validation:MinProperties=1
113+
type MachinePoolRemediationSpec struct {
114+
// maxInFlight determines how many in flight remediations should happen at the same time.
115+
//
116+
// MaxInFlight can be set to a fixed number or a percentage.
117+
// Example: when this is set to 20%, the MachinePool controller deletes at most 20% of
118+
// the desired replicas.
119+
//
120+
// If not set, remediation is limited to all machines under the active MachinePool's management.
121+
//
122+
// +optional
123+
MaxInFlight *intstr.IntOrString `json:"maxInFlight,omitempty"`
100124
}
101125

102126
// MachinePoolStatus defines the observed state of MachinePool.

api/core/v1beta2/zz_generated.deepcopy.go

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

api/core/v1beta2/zz_generated.openapi.go

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

0 commit comments

Comments
 (0)