1 package v1beta1 2 3 import ( 4 corev1 "k8s.io/api/core/v1" 5 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 6 "k8s.io/apimachinery/pkg/util/intstr" 7 ) 8 9 // RemediationStrategyType contains remediation strategy type 10 type RemediationStrategyType string 11 12 // +genclient 13 // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object 14 15 // MachineHealthCheck is the Schema for the machinehealthchecks API 16 // +kubebuilder:subresource:status 17 // +kubebuilder:resource:shortName=mhc;mhcs 18 // +k8s:openapi-gen=true 19 // +kubebuilder:printcolumn:name="MaxUnhealthy",type="string",JSONPath=".spec.maxUnhealthy",description="Maximum number of unhealthy machines allowed" 20 // +kubebuilder:printcolumn:name="ExpectedMachines",type="integer",JSONPath=".status.expectedMachines",description="Number of machines currently monitored" 21 // +kubebuilder:printcolumn:name="CurrentHealthy",type="integer",JSONPath=".status.currentHealthy",description="Current observed healthy machines" 22 // Compatibility level 2: Stable within a major release for a minimum of 9 months or 3 minor releases (whichever is longer). 23 // +openshift:compatibility-gen:level=2 24 type MachineHealthCheck struct { 25 metav1.TypeMeta `json:",inline"` 26 27 // metadata is the standard object's metadata. 28 // More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata 29 metav1.ObjectMeta `json:"metadata,omitempty"` 30 31 // Specification of machine health check policy 32 // +optional 33 Spec MachineHealthCheckSpec `json:"spec,omitempty"` 34 35 // Most recently observed status of MachineHealthCheck resource 36 // +optional 37 Status MachineHealthCheckStatus `json:"status,omitempty"` 38 } 39 40 // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object 41 42 // MachineHealthCheckList contains a list of MachineHealthCheck 43 // Compatibility level 2: Stable within a major release for a minimum of 9 months or 3 minor releases (whichever is longer). 44 // +openshift:compatibility-gen:level=2 45 type MachineHealthCheckList struct { 46 metav1.TypeMeta `json:",inline"` 47 48 // metadata is the standard list's metadata. 49 // More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata 50 metav1.ListMeta `json:"metadata,omitempty"` 51 52 Items []MachineHealthCheck `json:"items"` 53 } 54 55 // MachineHealthCheckSpec defines the desired state of MachineHealthCheck 56 type MachineHealthCheckSpec struct { 57 // Label selector to match machines whose health will be exercised. 58 // Note: An empty selector will match all machines. 59 Selector metav1.LabelSelector `json:"selector"` 60 61 // UnhealthyConditions contains a list of the conditions that determine 62 // whether a node is considered unhealthy. The conditions are combined in a 63 // logical OR, i.e. if any of the conditions is met, the node is unhealthy. 64 // 65 // +kubebuilder:validation:MinItems=1 66 UnhealthyConditions []UnhealthyCondition `json:"unhealthyConditions"` 67 68 // Any farther remediation is only allowed if at most "MaxUnhealthy" machines selected by 69 // "selector" are not healthy. 70 // Expects either a postive integer value or a percentage value. 71 // Percentage values must be positive whole numbers and are capped at 100%. 72 // Both 0 and 0% are valid and will block all remediation. 73 // +kubebuilder:default:="100%" 74 // +kubebuilder:validation:XIntOrString 75 // +kubebuilder:validation:Pattern="^((100|[0-9]{1,2})%|[0-9]+)$" 76 // +optional 77 MaxUnhealthy *intstr.IntOrString `json:"maxUnhealthy,omitempty"` 78 79 // Machines older than this duration without a node will be considered to have 80 // failed and will be remediated. 81 // To prevent Machines without Nodes from being removed, disable startup checks 82 // by setting this value explicitly to "0". 83 // Expects an unsigned duration string of decimal numbers each with optional 84 // fraction and a unit suffix, eg "300ms", "1.5h" or "2h45m". 85 // Valid time units are "ns", "us" (or "µs"), "ms", "s", "m", "h". 86 // +optional 87 // +kubebuilder:default:="10m" 88 // +kubebuilder:validation:Pattern="^0|([0-9]+(\\.[0-9]+)?(ns|us|µs|ms|s|m|h))+$" 89 // +kubebuilder:validation:Type:=string 90 // +optional 91 NodeStartupTimeout *metav1.Duration `json:"nodeStartupTimeout,omitempty"` 92 93 // RemediationTemplate is a reference to a remediation template 94 // provided by an infrastructure provider. 95 // 96 // This field is completely optional, when filled, the MachineHealthCheck controller 97 // creates a new object from the template referenced and hands off remediation of the machine to 98 // a controller that lives outside of Machine API Operator. 99 // +optional 100 RemediationTemplate *corev1.ObjectReference `json:"remediationTemplate,omitempty"` 101 } 102 103 // UnhealthyCondition represents a Node condition type and value with a timeout 104 // specified as a duration. When the named condition has been in the given 105 // status for at least the timeout value, a node is considered unhealthy. 106 type UnhealthyCondition struct { 107 // +kubebuilder:validation:Type=string 108 // +kubebuilder:validation:MinLength=1 109 Type corev1.NodeConditionType `json:"type"` 110 111 // +kubebuilder:validation:Type=string 112 // +kubebuilder:validation:MinLength=1 113 Status corev1.ConditionStatus `json:"status"` 114 115 // Expects an unsigned duration string of decimal numbers each with optional 116 // fraction and a unit suffix, eg "300ms", "1.5h" or "2h45m". 117 // Valid time units are "ns", "us" (or "µs"), "ms", "s", "m", "h". 118 // +kubebuilder:validation:Pattern="^([0-9]+(\\.[0-9]+)?(ns|us|µs|ms|s|m|h))+$" 119 // +kubebuilder:validation:Type:=string 120 Timeout metav1.Duration `json:"timeout"` 121 } 122 123 // MachineHealthCheckStatus defines the observed state of MachineHealthCheck 124 type MachineHealthCheckStatus struct { 125 // total number of machines counted by this machine health check 126 // +kubebuilder:validation:Minimum=0 127 ExpectedMachines *int `json:"expectedMachines"` 128 129 // total number of machines counted by this machine health check 130 // +kubebuilder:validation:Minimum=0 131 CurrentHealthy *int `json:"currentHealthy"` 132 133 // RemediationsAllowed is the number of further remediations allowed by this machine health check before 134 // maxUnhealthy short circuiting will be applied 135 // +kubebuilder:validation:Minimum=0 136 // +optional 137 RemediationsAllowed int32 `json:"remediationsAllowed"` 138 139 // Conditions defines the current state of the MachineHealthCheck 140 // +optional 141 Conditions Conditions `json:"conditions,omitempty"` 142 } 143