k8s_cluster_api/v1beta1/machine.rs
1use super::*;
2
3pub use deployment::MachineDeploymentSpec;
4pub use machineset::MachineTemplateSpec;
5
6pub mod deployment;
7pub mod machineset;
8
9mod impls;
10
11// MachineSpec defines the desired state of Machine.
12#[skip_serializing_none]
13#[derive(Clone, Debug, Default, Serialize, Deserialize)]
14#[serde(rename_all = "camelCase")]
15pub struct MachineSpec {
16 /// ClusterName is the name of the Cluster this object belongs to.
17 // +kubebuilder:validation:MinLength=1
18 pub cluster_name: String, // `json:"clusterName"`
19
20 /// Bootstrap is a reference to a local struct which encapsulates
21 // fields to configure the Machine’s bootstrapping mechanism.
22 pub bootstrap: Bootstrap, // `json:"bootstrap"`
23
24 // InfrastructureRef is a required reference to a custom resource
25 // offered by an infrastructure provider.
26 pub infrastructure_ref: corev1::ObjectReference, // `json:"infrastructureRef"`
27
28 // Version defines the desired Kubernetes version.
29 // This field is meant to be optionally used by bootstrap providers.
30 // +optional
31 pub version: Option<String>, // `json:"version,omitempty"`
32
33 // ProviderID is the identification ID of the machine provided by the provider.
34 // This field must match the provider ID as seen on the node object corresponding to this machine.
35 // This field is required by higher level consumers of cluster-api. Example use case is cluster autoscaler
36 // with cluster-api as provider. Clean-up logic in the autoscaler compares machines to nodes to find out
37 // machines at provider which could not get registered as Kubernetes nodes. With cluster-api as a
38 // generic out-of-tree provider for autoscaler, this field is required by autoscaler to be
39 // able to have a provider view of the list of machines. Another list of nodes is queried from the k8s apiserver
40 // and then a comparison is done to find out unregistered machines and are marked for delete.
41 // This field will be set by the actuators and consumed by higher level entities like autoscaler that will
42 // be interfacing with cluster-api as generic provider.
43 // +optional
44 #[serde(rename = "providerID")]
45 pub provider_id: Option<String>, // `json:"providerID,omitempty"`
46
47 // FailureDomain is the failure domain the machine will be created in.
48 // Must match a key in the FailureDomains map stored on the cluster object.
49 // +optional
50 pub failure_domain: Option<String>, // `json:"failureDomain,omitempty"`
51
52 // NodeDrainTimeout is the total amount of time that the controller will spend on draining a node.
53 // The default value is 0, meaning that the node can be drained without any time limitations.
54 // NOTE: NodeDrainTimeout is different from `kubectl drain --timeout`
55 // +optional
56 // pub node_drain_timeout: *metav1.Duration `json:"nodeDrainTimeout,omitempty"`
57 pub node_drain_timeout: Option<i64>, // `json:"nodeDrainTimeout,omitempty"`
58}
59
60// Bootstrap encapsulates fields to configure the Machine’s bootstrapping mechanism.
61#[skip_serializing_none]
62#[derive(Clone, Debug, Default, Serialize, Deserialize)]
63#[serde(rename_all = "camelCase")]
64pub struct Bootstrap {
65 // ConfigRef is a reference to a bootstrap provider-specific resource
66 // that holds configuration details. The reference is optional to
67 // allow users/operators to specify Bootstrap.DataSecretName without
68 // the need of a controller.
69 // +optional
70 pub config_ref: Option<corev1::ObjectReference>, // `json:"configRef,omitempty"`
71
72 // DataSecretName is the name of the secret that stores the bootstrap data script.
73 // If nil, the Machine should remain in the Pending state.
74 // +optional
75 pub data_secret_name: Option<String>, // `json:"dataSecretName,omitempty"`
76}
77
78/*
79
80package v1beta1
81
82import (
83 corev1 "k8s.io/api/core/v1"
84 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
85
86 capierrors "sigs.k8s.io/cluster-api/errors"
87)
88
89const (
90 // MachineFinalizer is set on PrepareForCreate callback.
91 MachineFinalizer = "machine.cluster.x-k8s.io"
92
93 // MachineControlPlaneLabelName is the label set on machines or related objects that are part of a control plane.
94 MachineControlPlaneLabelName = "cluster.x-k8s.io/control-plane"
95
96 // ExcludeNodeDrainingAnnotation annotation explicitly skips node draining if set.
97 ExcludeNodeDrainingAnnotation = "machine.cluster.x-k8s.io/exclude-node-draining"
98
99 // MachineSetLabelName is the label set on machines if they're controlled by MachineSet.
100 MachineSetLabelName = "cluster.x-k8s.io/set-name"
101
102 // MachineDeploymentLabelName is the label set on machines if they're controlled by MachineDeployment.
103 MachineDeploymentLabelName = "cluster.x-k8s.io/deployment-name"
104
105 // PreDrainDeleteHookAnnotationPrefix annotation specifies the prefix we
106 // search each annotation for during the pre-drain.delete lifecycle hook
107 // to pause reconciliation of deletion. These hooks will prevent removal of
108 // draining the associated node until all are removed.
109 PreDrainDeleteHookAnnotationPrefix = "pre-drain.delete.hook.machine.cluster.x-k8s.io"
110
111 // PreTerminateDeleteHookAnnotationPrefix annotation specifies the prefix we
112 // search each annotation for during the pre-terminate.delete lifecycle hook
113 // to pause reconciliation of deletion. These hooks will prevent removal of
114 // an instance from an infrastructure provider until all are removed.
115 PreTerminateDeleteHookAnnotationPrefix = "pre-terminate.delete.hook.machine.cluster.x-k8s.io"
116)
117
118// ANCHOR: MachineSpec
119
120
121// ANCHOR_END: MachineSpec
122
123// ANCHOR: MachineStatus
124
125// MachineStatus defines the observed state of Machine.
126type MachineStatus struct {
127 // NodeRef will point to the corresponding Node if it exists.
128 // +optional
129 NodeRef *corev1.ObjectReference `json:"nodeRef,omitempty"`
130
131 // NodeInfo is a set of ids/uuids to uniquely identify the node.
132 // More info: https://kubernetes.io/docs/concepts/nodes/node/#info
133 // +optional
134 NodeInfo *corev1.NodeSystemInfo `json:"nodeInfo,omitempty"`
135
136 // LastUpdated identifies when the phase of the Machine last transitioned.
137 // +optional
138 LastUpdated *metav1.Time `json:"lastUpdated,omitempty"`
139
140 // FailureReason will be set in the event that there is a terminal problem
141 // reconciling the Machine and will contain a succinct value suitable
142 // for machine interpretation.
143 //
144 // This field should not be set for transitive errors that a controller
145 // faces that are expected to be fixed automatically over
146 // time (like service outages), but instead indicate that something is
147 // fundamentally wrong with the Machine's spec or the configuration of
148 // the controller, and that manual intervention is required. Examples
149 // of terminal errors would be invalid combinations of settings in the
150 // spec, values that are unsupported by the controller, or the
151 // responsible controller itself being critically misconfigured.
152 //
153 // Any transient errors that occur during the reconciliation of Machines
154 // can be added as events to the Machine object and/or logged in the
155 // controller's output.
156 // +optional
157 FailureReason *capierrors.MachineStatusError `json:"failureReason,omitempty"`
158
159 // FailureMessage will be set in the event that there is a terminal problem
160 // reconciling the Machine and will contain a more verbose string suitable
161 // for logging and human consumption.
162 //
163 // This field should not be set for transitive errors that a controller
164 // faces that are expected to be fixed automatically over
165 // time (like service outages), but instead indicate that something is
166 // fundamentally wrong with the Machine's spec or the configuration of
167 // the controller, and that manual intervention is required. Examples
168 // of terminal errors would be invalid combinations of settings in the
169 // spec, values that are unsupported by the controller, or the
170 // responsible controller itself being critically misconfigured.
171 //
172 // Any transient errors that occur during the reconciliation of Machines
173 // can be added as events to the Machine object and/or logged in the
174 // controller's output.
175 // +optional
176 FailureMessage *string `json:"failureMessage,omitempty"`
177
178 // Addresses is a list of addresses assigned to the machine.
179 // This field is copied from the infrastructure provider reference.
180 // +optional
181 Addresses MachineAddresses `json:"addresses,omitempty"`
182
183 // Phase represents the current phase of machine actuation.
184 // E.g. Pending, Running, Terminating, Failed etc.
185 // +optional
186 Phase string `json:"phase,omitempty"`
187
188 // BootstrapReady is the state of the bootstrap provider.
189 // +optional
190 BootstrapReady bool `json:"bootstrapReady"`
191
192 // InfrastructureReady is the state of the infrastructure provider.
193 // +optional
194 InfrastructureReady bool `json:"infrastructureReady"`
195
196 // ObservedGeneration is the latest generation observed by the controller.
197 // +optional
198 ObservedGeneration int64 `json:"observedGeneration,omitempty"`
199
200 // Conditions defines current service state of the Machine.
201 // +optional
202 Conditions Conditions `json:"conditions,omitempty"`
203}
204
205// ANCHOR_END: MachineStatus
206
207// SetTypedPhase sets the Phase field to the string representation of MachinePhase.
208func (m *MachineStatus) SetTypedPhase(p MachinePhase) {
209 m.Phase = string(p)
210}
211
212// GetTypedPhase attempts to parse the Phase field and return
213// the typed MachinePhase representation as described in `machine_phase_types.go`.
214func (m *MachineStatus) GetTypedPhase() MachinePhase {
215 switch phase := MachinePhase(m.Phase); phase {
216 case
217 MachinePhasePending,
218 MachinePhaseProvisioning,
219 MachinePhaseProvisioned,
220 MachinePhaseRunning,
221 MachinePhaseDeleting,
222 MachinePhaseDeleted,
223 MachinePhaseFailed:
224 return phase
225 default:
226 return MachinePhaseUnknown
227 }
228}
229
230// ANCHOR: Bootstrap
231
232// ANCHOR_END: Bootstrap
233
234// +kubebuilder:object:root=true
235// +kubebuilder:resource:path=machines,shortName=ma,scope=Namespaced,categories=cluster-api
236// +kubebuilder:subresource:status
237// +kubebuilder:storageversion
238// +kubebuilder:printcolumn:name="Cluster",type="string",JSONPath=".spec.clusterName",description="Cluster"
239// +kubebuilder:printcolumn:name="NodeName",type="string",JSONPath=".status.nodeRef.name",description="Node name associated with this machine"
240// +kubebuilder:printcolumn:name="ProviderID",type="string",JSONPath=".spec.providerID",description="Provider ID"
241// +kubebuilder:printcolumn:name="Phase",type="string",JSONPath=".status.phase",description="Machine status such as Terminating/Pending/Running/Failed etc"
242// +kubebuilder:printcolumn:name="Age",type="date",JSONPath=".metadata.creationTimestamp",description="Time duration since creation of Machine"
243// +kubebuilder:printcolumn:name="Version",type="string",JSONPath=".spec.version",description="Kubernetes version associated with this Machine"
244
245// Machine is the Schema for the machines API.
246type Machine struct {
247 metav1.TypeMeta `json:",inline"`
248 metav1.ObjectMeta `json:"metadata,omitempty"`
249
250 Spec MachineSpec `json:"spec,omitempty"`
251 Status MachineStatus `json:"status,omitempty"`
252}
253
254// GetConditions returns the set of conditions for this object.
255func (m *Machine) GetConditions() Conditions {
256 return m.Status.Conditions
257}
258
259// SetConditions sets the conditions on this object.
260func (m *Machine) SetConditions(conditions Conditions) {
261 m.Status.Conditions = conditions
262}
263
264// +kubebuilder:object:root=true
265
266// MachineList contains a list of Machine.
267type MachineList struct {
268 metav1.TypeMeta `json:",inline"`
269 metav1.ListMeta `json:"metadata,omitempty"`
270 Items []Machine `json:"items"`
271}
272
273func init() {
274 SchemeBuilder.Register(&Machine{}, &MachineList{})
275}
276
277*/