Skip to content

Commit a7f8d81

Browse files
committed
Restructure MHC fields in MHC, Cluster and ClusterClass CRDs
Signed-off-by: Stefan Büringer buringerst@vmware.com
1 parent ad7b7b1 commit a7f8d81

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+3272
-1894
lines changed

.golangci-kal.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,10 @@ linters:
178178
text: "optionalfields: field (Workers|Metadata|ControlPlane|Strategy|Infrastructure|DeprecatedV1Beta1Metadata) is optional and should (be a pointer|have the omitempty tag)"
179179
linters:
180180
- kubeapilinter
181+
- path: "api/core/v1beta2/(cluster_types.go|clusterclass_types.go|machinehealthcheck_types.go)"
182+
text: "optionalfields: field (Checks|Remediation|TriggerIf) is optional and should (be a pointer|have the omitempty tag)"
183+
linters:
184+
- kubeapilinter
181185
- path: "api/core/v1beta2/machinedeployment_types.go"
182186
text: "optionalfields: field (Strategy|RollingUpdate|Remediation) is optional and should (be a pointer|have the omitempty tag)"
183187
linters:

api/core/v1beta1/conversion.go

Lines changed: 194 additions & 57 deletions
Large diffs are not rendered by default.

api/core/v1beta1/conversion_test.go

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,20 @@ func spokeCluster(in *Cluster, c randfill.Continue) {
194194
}
195195

196196
dropEmptyStringsCluster(in)
197+
if in.Spec.Topology != nil {
198+
if in.Spec.Topology.ControlPlane.MachineHealthCheck != nil {
199+
dropEmptyString(&in.Spec.Topology.ControlPlane.MachineHealthCheck.UnhealthyRange)
200+
}
201+
if in.Spec.Topology.Workers != nil {
202+
for i, md := range in.Spec.Topology.Workers.MachineDeployments {
203+
dropEmptyString(&md.FailureDomain)
204+
if md.MachineHealthCheck != nil {
205+
dropEmptyString(&md.MachineHealthCheck.UnhealthyRange)
206+
}
207+
in.Spec.Topology.Workers.MachineDeployments[i] = md
208+
}
209+
}
210+
}
197211

198212
if in.Spec.ClusterNetwork != nil {
199213
if in.Spec.ClusterNetwork.Services != nil && reflect.DeepEqual(in.Spec.ClusterNetwork.Services, &NetworkRanges{}) {
@@ -332,6 +346,15 @@ func spokeClusterClass(in *ClusterClass, c randfill.Continue) {
332346
in.Namespace = "foo"
333347

334348
dropEmptyStringsClusterClass(in)
349+
if in.Spec.ControlPlane.MachineHealthCheck != nil {
350+
dropEmptyString(&in.Spec.ControlPlane.MachineHealthCheck.UnhealthyRange)
351+
}
352+
for i, md := range in.Spec.Workers.MachineDeployments {
353+
if md.MachineHealthCheck != nil {
354+
dropEmptyString(&md.MachineHealthCheck.UnhealthyRange)
355+
}
356+
in.Spec.Workers.MachineDeployments[i] = md
357+
}
335358
}
336359

337360
func spokeClusterClassStatus(in *ClusterClassStatus, c randfill.Continue) {
@@ -653,7 +676,7 @@ func spokeMachineHealthCheck(in *MachineHealthCheck, c randfill.Continue) {
653676

654677
in.Namespace = "foo"
655678

656-
dropEmptyStringsMachineHealthCheck(in)
679+
dropEmptyString(&in.Spec.UnhealthyRange)
657680
}
658681

659682
func spokeMachineHealthCheckStatus(in *MachineHealthCheckStatus, c randfill.Continue) {

api/core/v1beta1/zz_generated.conversion.go

Lines changed: 13 additions & 184 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: 208 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,13 @@ import (
2020
"cmp"
2121
"fmt"
2222
"net"
23+
"reflect"
2324
"strings"
2425

2526
apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
2627
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2728
"k8s.io/apimachinery/pkg/types"
29+
"k8s.io/apimachinery/pkg/util/intstr"
2830

2931
capierrors "sigs.k8s.io/cluster-api/errors"
3032
)
@@ -609,10 +611,10 @@ type ControlPlaneTopology struct {
609611
// +optional
610612
Replicas *int32 `json:"replicas,omitempty"`
611613

612-
// machineHealthCheck allows to enable, disable and override
614+
// healthCheck allows to enable, disable and override
613615
// the MachineHealthCheck configuration in the ClusterClass for this control plane.
614616
// +optional
615-
MachineHealthCheck *MachineHealthCheckTopology `json:"machineHealthCheck,omitempty"`
617+
HealthCheck *ControlPlaneTopologyMachineHealthCheck `json:"healthCheck,omitempty"`
616618

617619
// deletion contains configuration options for Machine deletion.
618620
// +optional
@@ -639,6 +641,107 @@ type ControlPlaneTopology struct {
639641
Variables ControlPlaneVariables `json:"variables,omitempty,omitzero"`
640642
}
641643

644+
// ControlPlaneTopologyMachineHealthCheck defines a MachineHealthCheck for a group of machines.
645+
// +kubebuilder:validation:MinProperties=1
646+
type ControlPlaneTopologyMachineHealthCheck struct {
647+
// enabled controls if a MachineHealthCheck should be created for the target machines.
648+
//
649+
// If false: No MachineHealthCheck will be created.
650+
//
651+
// If not set(default): A MachineHealthCheck will be created if it is defined here or
652+
// in the associated ClusterClass. If no MachineHealthCheck is defined then none will be created.
653+
//
654+
// If true: A MachineHealthCheck is guaranteed to be created. Cluster validation will
655+
// block if `enable` is true and no MachineHealthCheck definition is available.
656+
// +optional
657+
Enabled *bool `json:"enabled,omitempty"`
658+
659+
// checks are the checks that are used to evaluate if a Machine is healthy.
660+
// +optional
661+
Checks ControlPlaneTopologyMachineHealthCheckChecks `json:"checks,omitempty,omitzero"`
662+
663+
// remediation configures if and how remediations are triggered if a Machine is unhealthy.
664+
// +optional
665+
Remediation ControlPlaneTopologyMachineHealthCheckRemediation `json:"remediation,omitempty,omitzero"`
666+
}
667+
668+
// IsHealthCheckConfigZero returns true if both checks and remediation are zero.
669+
func (m *ControlPlaneTopologyMachineHealthCheck) IsHealthCheckConfigZero() bool {
670+
return reflect.ValueOf(m.Checks).IsZero() && reflect.ValueOf(m.Remediation).IsZero()
671+
}
672+
673+
// ControlPlaneTopologyMachineHealthCheckChecks are the checks that are used to evaluate if a Machine is healthy.
674+
// +kubebuilder:validation:MinProperties=1
675+
type ControlPlaneTopologyMachineHealthCheckChecks struct {
676+
// nodeStartupTimeoutSeconds allows to set the maximum time for MachineHealthCheck
677+
// to consider a Machine unhealthy if a corresponding Node isn't associated
678+
// through a `Spec.ProviderID` field.
679+
//
680+
// The duration set in this field is compared to the greatest of:
681+
// - Cluster's infrastructure ready condition timestamp (if and when available)
682+
// - Control Plane's initialized condition timestamp (if and when available)
683+
// - Machine's infrastructure ready condition timestamp (if and when available)
684+
// - Machine's metadata creation timestamp
685+
//
686+
// Defaults to 10 minutes.
687+
// If you wish to disable this feature, set the value explicitly to 0.
688+
// +optional
689+
// +kubebuilder:validation:Minimum=0
690+
NodeStartupTimeoutSeconds *int32 `json:"nodeStartupTimeoutSeconds,omitempty"`
691+
692+
// unhealthyNodeConditions contains a list of conditions that determine
693+
// whether a node is considered unhealthy. The conditions are combined in a
694+
// logical OR, i.e. if any of the conditions is met, the node is unhealthy.
695+
//
696+
// +optional
697+
// +listType=atomic
698+
// +kubebuilder:validation:MinItems=1
699+
// +kubebuilder:validation:MaxItems=100
700+
UnhealthyNodeConditions []UnhealthyNodeCondition `json:"unhealthyNodeConditions,omitempty"`
701+
}
702+
703+
// ControlPlaneTopologyMachineHealthCheckRemediation configures if and how remediations are triggered if a Machine is unhealthy.
704+
// +kubebuilder:validation:MinProperties=1
705+
type ControlPlaneTopologyMachineHealthCheckRemediation struct {
706+
// triggerIf configures if remediations are triggered.
707+
// If this field is not set, remediations are always triggered.
708+
// +optional
709+
TriggerIf ControlPlaneTopologyMachineHealthCheckRemediationTriggerIf `json:"triggerIf,omitempty,omitzero"`
710+
711+
// templateRef is a reference to a remediation template
712+
// provided by an infrastructure provider.
713+
//
714+
// This field is completely optional, when filled, the MachineHealthCheck controller
715+
// creates a new object from the template referenced and hands off remediation of the machine to
716+
// a controller that lives outside of Cluster API.
717+
// +optional
718+
TemplateRef *MachineHealthCheckRemediationTemplateReference `json:"templateRef,omitempty"`
719+
}
720+
721+
// ControlPlaneTopologyMachineHealthCheckRemediationTriggerIf configures if remediations are triggered.
722+
// +kubebuilder:validation:MinProperties=1
723+
type ControlPlaneTopologyMachineHealthCheckRemediationTriggerIf struct {
724+
// unhealthyLessThanOrEqualTo specifies that remediations are only triggered if the number of
725+
// unhealthy Machines is less than or equal to the configured value.
726+
// unhealthyInRange takes precedence if set.
727+
//
728+
// +optional
729+
UnhealthyLessThanOrEqualTo *intstr.IntOrString `json:"unhealthyLessThanOrEqualTo,omitempty"`
730+
731+
// unhealthyInRange specifies that remediations are only triggered if the number of
732+
// unhealthy Machines is in the configured range.
733+
// Takes precedence over unhealthyLessThanOrEqualTo.
734+
// Eg. "[3-5]" - This means that remediation will be allowed only when:
735+
// (a) there are at least 3 unhealthy Machines (and)
736+
// (b) there are at most 5 unhealthy Machines
737+
//
738+
// +optional
739+
// +kubebuilder:validation:Pattern=^\[[0-9]+-[0-9]+\]$
740+
// +kubebuilder:validation:MinLength=1
741+
// +kubebuilder:validation:MaxLength=32
742+
UnhealthyInRange string `json:"unhealthyInRange,omitempty"`
743+
}
744+
642745
// ControlPlaneTopologyMachineDeletionSpec contains configuration options for Machine deletion.
643746
// +kubebuilder:validation:MinProperties=1
644747
type ControlPlaneTopologyMachineDeletionSpec struct {
@@ -722,10 +825,10 @@ type MachineDeploymentTopology struct {
722825
// +optional
723826
Replicas *int32 `json:"replicas,omitempty"`
724827

725-
// machineHealthCheck allows to enable, disable and override
828+
// healthCheck allows to enable, disable and override
726829
// the MachineHealthCheck configuration in the ClusterClass for this MachineDeployment.
727830
// +optional
728-
MachineHealthCheck *MachineHealthCheckTopology `json:"machineHealthCheck,omitempty"`
831+
HealthCheck *MachineDeploymentTopologyMachineHealthCheck `json:"healthCheck,omitempty"`
729832

730833
// deletion contains configuration options for Machine deletion.
731834
// +optional
@@ -763,6 +866,107 @@ type MachineDeploymentTopology struct {
763866
Variables MachineDeploymentVariables `json:"variables,omitempty,omitzero"`
764867
}
765868

869+
// MachineDeploymentTopologyMachineHealthCheck defines a MachineHealthCheck for a group of machines.
870+
// +kubebuilder:validation:MinProperties=1
871+
type MachineDeploymentTopologyMachineHealthCheck struct {
872+
// enabled controls if a MachineHealthCheck should be created for the target machines.
873+
//
874+
// If false: No MachineHealthCheck will be created.
875+
//
876+
// If not set(default): A MachineHealthCheck will be created if it is defined here or
877+
// in the associated ClusterClass. If no MachineHealthCheck is defined then none will be created.
878+
//
879+
// If true: A MachineHealthCheck is guaranteed to be created. Cluster validation will
880+
// block if `enable` is true and no MachineHealthCheck definition is available.
881+
// +optional
882+
Enabled *bool `json:"enabled,omitempty"`
883+
884+
// checks are the checks that are used to evaluate if a Machine is healthy.
885+
// +optional
886+
Checks MachineDeploymentTopologyMachineHealthCheckChecks `json:"checks,omitempty,omitzero"`
887+
888+
// remediation configures if and how remediations are triggered if a Machine is unhealthy.
889+
// +optional
890+
Remediation MachineDeploymentTopologyMachineHealthCheckRemediation `json:"remediation,omitempty,omitzero"`
891+
}
892+
893+
// IsHealthCheckConfigZero returns true if both checks and remediation are zero.
894+
func (m *MachineDeploymentTopologyMachineHealthCheck) IsHealthCheckConfigZero() bool {
895+
return reflect.ValueOf(m.Checks).IsZero() && reflect.ValueOf(m.Remediation).IsZero()
896+
}
897+
898+
// MachineDeploymentTopologyMachineHealthCheckChecks are the checks that are used to evaluate if a Machine is healthy.
899+
// +kubebuilder:validation:MinProperties=1
900+
type MachineDeploymentTopologyMachineHealthCheckChecks struct {
901+
// nodeStartupTimeoutSeconds allows to set the maximum time for MachineHealthCheck
902+
// to consider a Machine unhealthy if a corresponding Node isn't associated
903+
// through a `Spec.ProviderID` field.
904+
//
905+
// The duration set in this field is compared to the greatest of:
906+
// - Cluster's infrastructure ready condition timestamp (if and when available)
907+
// - Control Plane's initialized condition timestamp (if and when available)
908+
// - Machine's infrastructure ready condition timestamp (if and when available)
909+
// - Machine's metadata creation timestamp
910+
//
911+
// Defaults to 10 minutes.
912+
// If you wish to disable this feature, set the value explicitly to 0.
913+
// +optional
914+
// +kubebuilder:validation:Minimum=0
915+
NodeStartupTimeoutSeconds *int32 `json:"nodeStartupTimeoutSeconds,omitempty"`
916+
917+
// unhealthyNodeConditions contains a list of conditions that determine
918+
// whether a node is considered unhealthy. The conditions are combined in a
919+
// logical OR, i.e. if any of the conditions is met, the node is unhealthy.
920+
//
921+
// +optional
922+
// +listType=atomic
923+
// +kubebuilder:validation:MinItems=1
924+
// +kubebuilder:validation:MaxItems=100
925+
UnhealthyNodeConditions []UnhealthyNodeCondition `json:"unhealthyNodeConditions,omitempty"`
926+
}
927+
928+
// MachineDeploymentTopologyMachineHealthCheckRemediation configures if and how remediations are triggered if a Machine is unhealthy.
929+
// +kubebuilder:validation:MinProperties=1
930+
type MachineDeploymentTopologyMachineHealthCheckRemediation struct {
931+
// triggerIf configures if remediations are triggered.
932+
// If this field is not set, remediations are always triggered.
933+
// +optional
934+
TriggerIf MachineDeploymentTopologyMachineHealthCheckRemediationTriggerIf `json:"triggerIf,omitempty,omitzero"`
935+
936+
// templateRef is a reference to a remediation template
937+
// provided by an infrastructure provider.
938+
//
939+
// This field is completely optional, when filled, the MachineHealthCheck controller
940+
// creates a new object from the template referenced and hands off remediation of the machine to
941+
// a controller that lives outside of Cluster API.
942+
// +optional
943+
TemplateRef *MachineHealthCheckRemediationTemplateReference `json:"templateRef,omitempty"`
944+
}
945+
946+
// MachineDeploymentTopologyMachineHealthCheckRemediationTriggerIf configures if remediations are triggered.
947+
// +kubebuilder:validation:MinProperties=1
948+
type MachineDeploymentTopologyMachineHealthCheckRemediationTriggerIf struct {
949+
// unhealthyLessThanOrEqualTo specifies that remediations are only triggered if the number of
950+
// unhealthy Machines is less than or equal to the configured value.
951+
// unhealthyInRange takes precedence if set.
952+
//
953+
// +optional
954+
UnhealthyLessThanOrEqualTo *intstr.IntOrString `json:"unhealthyLessThanOrEqualTo,omitempty"`
955+
956+
// unhealthyInRange specifies that remediations are only triggered if the number of
957+
// unhealthy Machines is in the configured range.
958+
// Takes precedence over unhealthyLessThanOrEqualTo.
959+
// Eg. "[3-5]" - This means that remediation will be allowed only when:
960+
// (a) there are at least 3 unhealthy Machines (and)
961+
// (b) there are at most 5 unhealthy Machines
962+
//
963+
// +optional
964+
// +kubebuilder:validation:Pattern=^\[[0-9]+-[0-9]+\]$
965+
// +kubebuilder:validation:MinLength=1
966+
// +kubebuilder:validation:MaxLength=32
967+
UnhealthyInRange string `json:"unhealthyInRange,omitempty"`
968+
}
969+
766970
// MachineDeploymentTopologyMachineDeletionSpec contains configuration options for Machine deletion.
767971
// +kubebuilder:validation:MinProperties=1
768972
type MachineDeploymentTopologyMachineDeletionSpec struct {
@@ -787,26 +991,6 @@ type MachineDeploymentTopologyMachineDeletionSpec struct {
787991
NodeDeletionTimeoutSeconds *int32 `json:"nodeDeletionTimeoutSeconds,omitempty"`
788992
}
789993

790-
// MachineHealthCheckTopology defines a MachineHealthCheck for a group of machines.
791-
// +kubebuilder:validation:MinProperties=1
792-
type MachineHealthCheckTopology struct {
793-
// enable controls if a MachineHealthCheck should be created for the target machines.
794-
//
795-
// If false: No MachineHealthCheck will be created.
796-
//
797-
// If not set(default): A MachineHealthCheck will be created if it is defined here or
798-
// in the associated ClusterClass. If no MachineHealthCheck is defined then none will be created.
799-
//
800-
// If true: A MachineHealthCheck is guaranteed to be created. Cluster validation will
801-
// block if `enable` is true and no MachineHealthCheck definition is available.
802-
// +optional
803-
Enable *bool `json:"enable,omitempty"`
804-
805-
// MachineHealthCheckClass defines a MachineHealthCheck for a group of machines.
806-
// If specified (any field is set), it entirely overrides the MachineHealthCheckClass defined in ClusterClass.
807-
MachineHealthCheckClass `json:",inline"`
808-
}
809-
810994
// MachinePoolTopology specifies the different parameters for a pool of worker nodes in the topology.
811995
// This pool of nodes is managed by a MachinePool object whose lifecycle is managed by the Cluster controller.
812996
type MachinePoolTopology struct {

0 commit comments

Comments
 (0)