cluster_api_rs/api/
capi_machinehealthcheck.rs

1// WARNING: generated by kopium - manual changes will be overwritten
2// kopium command: kopium --smart-derive-elision -D Default -D PartialEq -A -d -f -
3// kopium version: 0.22.5
4
5#[allow(unused_imports)]
6mod prelude {
7    pub use k8s_openapi::apimachinery::pkg::apis::meta::v1::Condition;
8    pub use k8s_openapi::apimachinery::pkg::util::intstr::IntOrString;
9    pub use kube::CustomResource;
10    pub use schemars::JsonSchema;
11    pub use serde::{Deserialize, Serialize};
12    pub use std::collections::BTreeMap;
13}
14
15use self::prelude::*;
16
17/// spec is the specification of machine health check policy
18#[derive(CustomResource, Serialize, Deserialize, Clone, Debug, Default, PartialEq, JsonSchema)]
19#[kube(
20    group = "cluster.x-k8s.io",
21    version = "v1beta2",
22    kind = "MachineHealthCheck",
23    plural = "machinehealthchecks"
24)]
25#[kube(namespaced)]
26#[kube(status = "MachineHealthCheckStatus")]
27#[kube(derive = "Default")]
28#[kube(derive = "PartialEq")]
29pub struct MachineHealthCheckSpec {
30    /// checks are the checks that are used to evaluate if a Machine is healthy.
31    ///
32    /// Independent of this configuration the MachineHealthCheck controller will always
33    /// flag Machines with `cluster.x-k8s.io/remediate-machine` annotation and
34    /// Machines with deleted Nodes as unhealthy.
35    ///
36    /// Furthermore, if checks.nodeStartupTimeoutSeconds is not set it
37    /// is defaulted to 10 minutes and evaluated accordingly.
38    #[serde(default, skip_serializing_if = "Option::is_none")]
39    pub checks: Option<MachineHealthCheckChecks>,
40    /// clusterName is the name of the Cluster this object belongs to.
41    #[serde(rename = "clusterName")]
42    pub cluster_name: String,
43    /// remediation configures if and how remediations are triggered if a Machine is unhealthy.
44    ///
45    /// If remediation or remediation.triggerIf is not set,
46    /// remediation will always be triggered for unhealthy Machines.
47    ///
48    /// If remediation or remediation.templateRef is not set,
49    /// the OwnerRemediated condition will be set on unhealthy Machines to trigger remediation via
50    /// the owner of the Machines, for example a MachineSet or a KubeadmControlPlane.
51    #[serde(default, skip_serializing_if = "Option::is_none")]
52    pub remediation: Option<MachineHealthCheckRemediation>,
53    /// selector is a label selector to match machines whose health will be exercised
54    pub selector: MachineHealthCheckSelector,
55}
56
57/// checks are the checks that are used to evaluate if a Machine is healthy.
58///
59/// Independent of this configuration the MachineHealthCheck controller will always
60/// flag Machines with `cluster.x-k8s.io/remediate-machine` annotation and
61/// Machines with deleted Nodes as unhealthy.
62///
63/// Furthermore, if checks.nodeStartupTimeoutSeconds is not set it
64/// is defaulted to 10 minutes and evaluated accordingly.
65#[derive(Serialize, Deserialize, Clone, Debug, Default, PartialEq, JsonSchema)]
66pub struct MachineHealthCheckChecks {
67    /// nodeStartupTimeoutSeconds allows to set the maximum time for MachineHealthCheck
68    /// to consider a Machine unhealthy if a corresponding Node isn't associated
69    /// through a `Spec.ProviderID` field.
70    ///
71    /// The duration set in this field is compared to the greatest of:
72    /// - Cluster's infrastructure ready condition timestamp (if and when available)
73    /// - Control Plane's initialized condition timestamp (if and when available)
74    /// - Machine's infrastructure ready condition timestamp (if and when available)
75    /// - Machine's metadata creation timestamp
76    ///
77    /// Defaults to 10 minutes.
78    /// If you wish to disable this feature, set the value explicitly to 0.
79    #[serde(
80        default,
81        skip_serializing_if = "Option::is_none",
82        rename = "nodeStartupTimeoutSeconds"
83    )]
84    pub node_startup_timeout_seconds: Option<i32>,
85    /// unhealthyMachineConditions contains a list of the machine conditions that determine
86    /// whether a machine is considered unhealthy.  The conditions are combined in a
87    /// logical OR, i.e. if any of the conditions is met, the machine is unhealthy.
88    #[serde(
89        default,
90        skip_serializing_if = "Option::is_none",
91        rename = "unhealthyMachineConditions"
92    )]
93    pub unhealthy_machine_conditions:
94        Option<Vec<MachineHealthCheckChecksUnhealthyMachineConditions>>,
95    /// unhealthyNodeConditions contains a list of conditions that determine
96    /// whether a node is considered unhealthy. The conditions are combined in a
97    /// logical OR, i.e. if any of the conditions is met, the node is unhealthy.
98    #[serde(
99        default,
100        skip_serializing_if = "Option::is_none",
101        rename = "unhealthyNodeConditions"
102    )]
103    pub unhealthy_node_conditions: Option<Vec<MachineHealthCheckChecksUnhealthyNodeConditions>>,
104}
105
106/// UnhealthyMachineCondition represents a Machine condition type and value with a timeout
107/// specified as a duration.  When the named condition has been in the given
108/// status for at least the timeout value, a machine is considered unhealthy.
109#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
110pub struct MachineHealthCheckChecksUnhealthyMachineConditions {
111    /// status of the condition, one of True, False, Unknown.
112    pub status: MachineHealthCheckChecksUnhealthyMachineConditionsStatus,
113    /// timeoutSeconds is the duration that a machine must be in a given status for,
114    /// after which the machine is considered unhealthy.
115    /// For example, with a value of "3600", the machine must match the status
116    /// for at least 1 hour before being considered unhealthy.
117    #[serde(rename = "timeoutSeconds")]
118    pub timeout_seconds: i32,
119    /// type of Machine condition
120    #[serde(rename = "type")]
121    pub r#type: String,
122}
123
124/// UnhealthyMachineCondition represents a Machine condition type and value with a timeout
125/// specified as a duration.  When the named condition has been in the given
126/// status for at least the timeout value, a machine is considered unhealthy.
127#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
128pub enum MachineHealthCheckChecksUnhealthyMachineConditionsStatus {
129    True,
130    False,
131    Unknown,
132}
133
134/// UnhealthyNodeCondition represents a Node condition type and value with a timeout
135/// specified as a duration.  When the named condition has been in the given
136/// status for at least the timeout value, a node is considered unhealthy.
137#[derive(Serialize, Deserialize, Clone, Debug, Default, PartialEq, JsonSchema)]
138pub struct MachineHealthCheckChecksUnhealthyNodeConditions {
139    /// status of the condition, one of True, False, Unknown.
140    pub status: String,
141    /// timeoutSeconds is the duration that a node must be in a given status for,
142    /// after which the node is considered unhealthy.
143    /// For example, with a value of "3600", the node must match the status
144    /// for at least 1 hour before being considered unhealthy.
145    #[serde(rename = "timeoutSeconds")]
146    pub timeout_seconds: i32,
147    /// type of Node condition
148    #[serde(rename = "type")]
149    pub r#type: String,
150}
151
152/// remediation configures if and how remediations are triggered if a Machine is unhealthy.
153///
154/// If remediation or remediation.triggerIf is not set,
155/// remediation will always be triggered for unhealthy Machines.
156///
157/// If remediation or remediation.templateRef is not set,
158/// the OwnerRemediated condition will be set on unhealthy Machines to trigger remediation via
159/// the owner of the Machines, for example a MachineSet or a KubeadmControlPlane.
160#[derive(Serialize, Deserialize, Clone, Debug, Default, PartialEq, JsonSchema)]
161pub struct MachineHealthCheckRemediation {
162    /// templateRef is a reference to a remediation template
163    /// provided by an infrastructure provider.
164    ///
165    /// This field is completely optional, when filled, the MachineHealthCheck controller
166    /// creates a new object from the template referenced and hands off remediation of the machine to
167    /// a controller that lives outside of Cluster API.
168    #[serde(
169        default,
170        skip_serializing_if = "Option::is_none",
171        rename = "templateRef"
172    )]
173    pub template_ref: Option<MachineHealthCheckRemediationTemplateRef>,
174    /// triggerIf configures if remediations are triggered.
175    /// If this field is not set, remediations are always triggered.
176    #[serde(default, skip_serializing_if = "Option::is_none", rename = "triggerIf")]
177    pub trigger_if: Option<MachineHealthCheckRemediationTriggerIf>,
178}
179
180/// templateRef is a reference to a remediation template
181/// provided by an infrastructure provider.
182///
183/// This field is completely optional, when filled, the MachineHealthCheck controller
184/// creates a new object from the template referenced and hands off remediation of the machine to
185/// a controller that lives outside of Cluster API.
186#[derive(Serialize, Deserialize, Clone, Debug, Default, PartialEq, JsonSchema)]
187pub struct MachineHealthCheckRemediationTemplateRef {
188    /// apiVersion of the remediation template.
189    /// apiVersion must be fully qualified domain name followed by / and a version.
190    /// NOTE: This field must be kept in sync with the APIVersion of the remediation template.
191    #[serde(rename = "apiVersion")]
192    pub api_version: String,
193    /// kind of the remediation template.
194    /// kind must consist of alphanumeric characters or '-', start with an alphabetic character, and end with an alphanumeric character.
195    pub kind: String,
196    /// name of the remediation template.
197    /// name must consist of lower case alphanumeric characters, '-' or '.', and must start and end with an alphanumeric character.
198    pub name: String,
199}
200
201/// triggerIf configures if remediations are triggered.
202/// If this field is not set, remediations are always triggered.
203#[derive(Serialize, Deserialize, Clone, Debug, Default, PartialEq, JsonSchema)]
204pub struct MachineHealthCheckRemediationTriggerIf {
205    /// unhealthyInRange specifies that remediations are only triggered if the number of
206    /// unhealthy Machines is in the configured range.
207    /// Takes precedence over unhealthyLessThanOrEqualTo.
208    /// Eg. "[3-5]" - This means that remediation will be allowed only when:
209    /// (a) there are at least 3 unhealthy Machines (and)
210    /// (b) there are at most 5 unhealthy Machines
211    #[serde(
212        default,
213        skip_serializing_if = "Option::is_none",
214        rename = "unhealthyInRange"
215    )]
216    pub unhealthy_in_range: Option<String>,
217    /// unhealthyLessThanOrEqualTo specifies that remediations are only triggered if the number of
218    /// unhealthy Machines is less than or equal to the configured value.
219    /// unhealthyInRange takes precedence if set.
220    #[serde(
221        default,
222        skip_serializing_if = "Option::is_none",
223        rename = "unhealthyLessThanOrEqualTo"
224    )]
225    pub unhealthy_less_than_or_equal_to: Option<IntOrString>,
226}
227
228/// selector is a label selector to match machines whose health will be exercised
229#[derive(Serialize, Deserialize, Clone, Debug, Default, PartialEq, JsonSchema)]
230pub struct MachineHealthCheckSelector {
231    /// matchExpressions is a list of label selector requirements. The requirements are ANDed.
232    #[serde(
233        default,
234        skip_serializing_if = "Option::is_none",
235        rename = "matchExpressions"
236    )]
237    pub match_expressions: Option<Vec<MachineHealthCheckSelectorMatchExpressions>>,
238    /// matchLabels is a map of {key,value} pairs. A single {key,value} in the matchLabels
239    /// map is equivalent to an element of matchExpressions, whose key field is "key", the
240    /// operator is "In", and the values array contains only "value". The requirements are ANDed.
241    #[serde(
242        default,
243        skip_serializing_if = "Option::is_none",
244        rename = "matchLabels"
245    )]
246    pub match_labels: Option<BTreeMap<String, String>>,
247}
248
249/// A label selector requirement is a selector that contains values, a key, and an operator that
250/// relates the key and values.
251#[derive(Serialize, Deserialize, Clone, Debug, Default, PartialEq, JsonSchema)]
252pub struct MachineHealthCheckSelectorMatchExpressions {
253    /// key is the label key that the selector applies to.
254    pub key: String,
255    /// operator represents a key's relationship to a set of values.
256    /// Valid operators are In, NotIn, Exists and DoesNotExist.
257    pub operator: String,
258    /// values is an array of string values. If the operator is In or NotIn,
259    /// the values array must be non-empty. If the operator is Exists or DoesNotExist,
260    /// the values array must be empty. This array is replaced during a strategic
261    /// merge patch.
262    #[serde(default, skip_serializing_if = "Option::is_none")]
263    pub values: Option<Vec<String>>,
264}
265
266/// status is the most recently observed status of MachineHealthCheck resource
267#[derive(Serialize, Deserialize, Clone, Debug, Default, PartialEq, JsonSchema)]
268pub struct MachineHealthCheckStatus {
269    /// conditions represents the observations of a MachineHealthCheck's current state.
270    /// Known condition types are RemediationAllowed, Paused.
271    #[serde(default, skip_serializing_if = "Option::is_none")]
272    pub conditions: Option<Vec<Condition>>,
273    /// currentHealthy is the total number of healthy machines counted by this machine health check
274    #[serde(
275        default,
276        skip_serializing_if = "Option::is_none",
277        rename = "currentHealthy"
278    )]
279    pub current_healthy: Option<i32>,
280    /// deprecated groups all the status fields that are deprecated and will be removed when all the nested field are removed.
281    #[serde(default, skip_serializing_if = "Option::is_none")]
282    pub deprecated: Option<MachineHealthCheckStatusDeprecated>,
283    /// expectedMachines is the total number of machines counted by this machine health check
284    #[serde(
285        default,
286        skip_serializing_if = "Option::is_none",
287        rename = "expectedMachines"
288    )]
289    pub expected_machines: Option<i32>,
290    /// observedGeneration is the latest generation observed by the controller.
291    #[serde(
292        default,
293        skip_serializing_if = "Option::is_none",
294        rename = "observedGeneration"
295    )]
296    pub observed_generation: Option<i64>,
297    /// remediationsAllowed is the number of further remediations allowed by this machine health check before
298    /// maxUnhealthy short circuiting will be applied
299    #[serde(
300        default,
301        skip_serializing_if = "Option::is_none",
302        rename = "remediationsAllowed"
303    )]
304    pub remediations_allowed: Option<i32>,
305    /// targets shows the current list of machines the machine health check is watching
306    #[serde(default, skip_serializing_if = "Option::is_none")]
307    pub targets: Option<Vec<String>>,
308}
309
310/// deprecated groups all the status fields that are deprecated and will be removed when all the nested field are removed.
311#[derive(Serialize, Deserialize, Clone, Debug, Default, PartialEq, JsonSchema)]
312pub struct MachineHealthCheckStatusDeprecated {
313    /// v1beta1 groups all the status fields that are deprecated and will be removed when support for v1beta1 will be dropped.
314    #[serde(default, skip_serializing_if = "Option::is_none")]
315    pub v1beta1: Option<MachineHealthCheckStatusDeprecatedV1beta1>,
316}
317
318/// v1beta1 groups all the status fields that are deprecated and will be removed when support for v1beta1 will be dropped.
319#[derive(Serialize, Deserialize, Clone, Debug, Default, PartialEq, JsonSchema)]
320pub struct MachineHealthCheckStatusDeprecatedV1beta1 {
321    /// conditions defines current service state of the MachineHealthCheck.
322    ///
323    /// Deprecated: This field is deprecated and is going to be removed when support for v1beta1 will be dropped. Please see <https://github.com/kubernetes-sigs/cluster-api/blob/main/docs/proposals/20240916-improve-status-in-CAPI-resources.md> for more details.
324    #[serde(default, skip_serializing_if = "Option::is_none")]
325    pub conditions: Option<Vec<Condition>>,
326}