Skip to content

Commit 80c4450

Browse files
authored
Merge pull request #7199 from ykakarap/patchable-mhc-managed-clusters
✨ Add support to configure MachineHealthChecks for managed Clusters
2 parents a2b11c7 + 241c193 commit 80c4450

File tree

17 files changed

+1582
-11
lines changed

17 files changed

+1582
-11
lines changed

api/v1alpha4/conversion.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ func (src *Cluster) ConvertTo(dstRaw conversion.Hub) error {
4343
}
4444
dst.Spec.Topology.Variables = restored.Spec.Topology.Variables
4545

46+
if restored.Spec.Topology.ControlPlane.MachineHealthCheck != nil {
47+
dst.Spec.Topology.ControlPlane.MachineHealthCheck = restored.Spec.Topology.ControlPlane.MachineHealthCheck
48+
}
49+
4650
if restored.Spec.Topology.ControlPlane.NodeDrainTimeout != nil {
4751
dst.Spec.Topology.ControlPlane.NodeDrainTimeout = restored.Spec.Topology.ControlPlane.NodeDrainTimeout
4852
}
@@ -65,6 +69,7 @@ func (src *Cluster) ConvertTo(dstRaw conversion.Hub) error {
6569
dst.Spec.Topology.Workers.MachineDeployments[i].NodeDrainTimeout = restored.Spec.Topology.Workers.MachineDeployments[i].NodeDrainTimeout
6670
dst.Spec.Topology.Workers.MachineDeployments[i].NodeVolumeDetachTimeout = restored.Spec.Topology.Workers.MachineDeployments[i].NodeVolumeDetachTimeout
6771
dst.Spec.Topology.Workers.MachineDeployments[i].NodeDeletionTimeout = restored.Spec.Topology.Workers.MachineDeployments[i].NodeDeletionTimeout
72+
dst.Spec.Topology.Workers.MachineDeployments[i].MachineHealthCheck = restored.Spec.Topology.Workers.MachineDeployments[i].MachineHealthCheck
6873
}
6974
}
7075
}

api/v1alpha4/zz_generated.conversion.go

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

api/v1beta1/cluster_types.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,11 @@ type ControlPlaneTopology struct {
116116
// +optional
117117
Replicas *int32 `json:"replicas,omitempty"`
118118

119+
// MachineHealthCheck allows to enable, disable and override
120+
// the MachineHealthCheck configuration in the ClusterClass for this control plane.
121+
// +optional
122+
MachineHealthCheck *MachineHealthCheckTopology `json:"machineHealthCheck,omitempty"`
123+
119124
// NodeDrainTimeout is the total amount of time that the controller will spend on draining a node.
120125
// The default value is 0, meaning that the node can be drained without any time limitations.
121126
// NOTE: NodeDrainTimeout is different from `kubectl drain --timeout`
@@ -172,6 +177,11 @@ type MachineDeploymentTopology struct {
172177
// +optional
173178
Replicas *int32 `json:"replicas,omitempty"`
174179

180+
// MachineHealthCheck allows to enable, disable and override
181+
// the MachineHealthCheck configuration in the ClusterClass for this MachineDeployment.
182+
// +optional
183+
MachineHealthCheck *MachineHealthCheckTopology `json:"machineHealthCheck,omitempty"`
184+
175185
// NodeDrainTimeout is the total amount of time that the controller will spend on draining a node.
176186
// The default value is 0, meaning that the node can be drained without any time limitations.
177187
// NOTE: NodeDrainTimeout is different from `kubectl drain --timeout`
@@ -194,6 +204,25 @@ type MachineDeploymentTopology struct {
194204
Variables *MachineDeploymentVariables `json:"variables,omitempty"`
195205
}
196206

207+
// MachineHealthCheckTopology defines a MachineHealthCheck for a group of machines.
208+
type MachineHealthCheckTopology struct {
209+
// Enable controls if a MachineHealthCheck should be created for the target machines.
210+
//
211+
// If false: No MachineHealthCheck will be created.
212+
//
213+
// If not set(default): A MachineHealthCheck will be created if it is defined here or
214+
// in the associated ClusterClass. If no MachineHealthCheck is defined then none will be created.
215+
//
216+
// If true: A MachineHealthCheck is guaranteed to be created. Cluster validation will
217+
// block if `enable` is true and no MachineHealthCheck definition is available.
218+
// +optional
219+
Enable *bool `json:"enable,omitempty"`
220+
221+
// MachineHealthCheckClass defines a MachineHealthCheck for a group of machines.
222+
// If specified (any field is set), it entirely overrides the MachineHealthCheckClass defined in ClusterClass.
223+
MachineHealthCheckClass `json:",inline"`
224+
}
225+
197226
// ClusterVariable can be used to customize the Cluster through
198227
// patches. It must comply to the corresponding
199228
// ClusterClassVariable defined in the ClusterClass.

api/v1beta1/clusterclass_types.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ limitations under the License.
1717
package v1beta1
1818

1919
import (
20+
"reflect"
21+
2022
corev1 "k8s.io/api/core/v1"
2123
apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
2224
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -177,6 +179,11 @@ type MachineHealthCheckClass struct {
177179
RemediationTemplate *corev1.ObjectReference `json:"remediationTemplate,omitempty"`
178180
}
179181

182+
// IsZero returns true if none of the values of MachineHealthCheckClass are defined.
183+
func (m MachineHealthCheckClass) IsZero() bool {
184+
return reflect.ValueOf(m).IsZero()
185+
}
186+
180187
// ClusterClassVariable defines a variable which can
181188
// be configured in the Cluster topology and used in patches.
182189
type ClusterClassVariable struct {

api/v1beta1/zz_generated.deepcopy.go

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

api/v1beta1/zz_generated.openapi.go

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

0 commit comments

Comments
 (0)