@@ -20,11 +20,13 @@ import (
20
20
"cmp"
21
21
"fmt"
22
22
"net"
23
+ "reflect"
23
24
"strings"
24
25
25
26
apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
26
27
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
27
28
"k8s.io/apimachinery/pkg/types"
29
+ "k8s.io/apimachinery/pkg/util/intstr"
28
30
29
31
capierrors "sigs.k8s.io/cluster-api/errors"
30
32
)
@@ -609,10 +611,10 @@ type ControlPlaneTopology struct {
609
611
// +optional
610
612
Replicas * int32 `json:"replicas,omitempty"`
611
613
612
- // machineHealthCheck allows to enable, disable and override
614
+ // healthCheck allows to enable, disable and override
613
615
// the MachineHealthCheck configuration in the ClusterClass for this control plane.
614
616
// +optional
615
- MachineHealthCheck * MachineHealthCheckTopology `json:"machineHealthCheck ,omitempty"`
617
+ HealthCheck * ControlPlaneTopologyMachineHealthCheck `json:"healthCheck ,omitempty"`
616
618
617
619
// deletion contains configuration options for Machine deletion.
618
620
// +optional
@@ -639,6 +641,107 @@ type ControlPlaneTopology struct {
639
641
Variables ControlPlaneVariables `json:"variables,omitempty,omitzero"`
640
642
}
641
643
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
+
642
745
// ControlPlaneTopologyMachineDeletionSpec contains configuration options for Machine deletion.
643
746
// +kubebuilder:validation:MinProperties=1
644
747
type ControlPlaneTopologyMachineDeletionSpec struct {
@@ -722,10 +825,10 @@ type MachineDeploymentTopology struct {
722
825
// +optional
723
826
Replicas * int32 `json:"replicas,omitempty"`
724
827
725
- // machineHealthCheck allows to enable, disable and override
828
+ // healthCheck allows to enable, disable and override
726
829
// the MachineHealthCheck configuration in the ClusterClass for this MachineDeployment.
727
830
// +optional
728
- MachineHealthCheck * MachineHealthCheckTopology `json:"machineHealthCheck ,omitempty"`
831
+ HealthCheck * MachineDeploymentTopologyMachineHealthCheck `json:"healthCheck ,omitempty"`
729
832
730
833
// deletion contains configuration options for Machine deletion.
731
834
// +optional
@@ -763,6 +866,107 @@ type MachineDeploymentTopology struct {
763
866
Variables MachineDeploymentVariables `json:"variables,omitempty,omitzero"`
764
867
}
765
868
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
+
766
970
// MachineDeploymentTopologyMachineDeletionSpec contains configuration options for Machine deletion.
767
971
// +kubebuilder:validation:MinProperties=1
768
972
type MachineDeploymentTopologyMachineDeletionSpec struct {
@@ -787,26 +991,6 @@ type MachineDeploymentTopologyMachineDeletionSpec struct {
787
991
NodeDeletionTimeoutSeconds * int32 `json:"nodeDeletionTimeoutSeconds,omitempty"`
788
992
}
789
993
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
-
810
994
// MachinePoolTopology specifies the different parameters for a pool of worker nodes in the topology.
811
995
// This pool of nodes is managed by a MachinePool object whose lifecycle is managed by the Cluster controller.
812
996
type MachinePoolTopology struct {
0 commit comments