k8s_cluster_api/v1beta1/machine/
deployment.rs

1use super::*;
2
3pub mod impls;
4
5// +kubebuilder:resource:path=machinedeployments,shortName=md,scope=Namespaced,categories=cluster-api
6
7/// MachineDeploymentSpec defines the desired state of MachineDeployment.
8#[skip_serializing_none]
9#[derive(Clone, Debug, Default, Serialize, Deserialize, CustomResource)]
10#[serde(rename_all = "camelCase")]
11#[kube(
12    group = "cluster.x-k8s.io",
13    version = "v1beta1",
14    kind = "MachineDeployment",
15    plural = "machinedeployments",
16    shortname = "md",
17    status = "MachineDeploymentStatus"
18)]
19#[kube(namespaced)]
20#[kube(schema = "disabled")]
21pub struct MachineDeploymentSpec {
22    /// ClusterName is the name of the Cluster this object belongs to.
23    // +kubebuilder:validation:MinLength=1
24    pub cluster_name: String, // `json:"clusterName"`
25
26    /// Number of desired machines. Defaults to 1.
27    /// This is a pointer to distinguish between explicit zero and not specified.
28    // +optional
29    // +kubebuilder:default=1
30    pub replicas: Option<i32>, // `json:"replicas,omitempty"`
31
32    /// Label selector for machines. Existing MachineSets whose machines are
33    /// selected by this will be the ones affected by this deployment.
34    /// It must match the machine template's labels.
35    pub selector: metav1::LabelSelector, // `json:"selector"`
36
37    /// Template describes the machines that will be created.
38    pub template: MachineTemplateSpec, // `json:"template"`
39
40    /// The deployment strategy to use to replace existing machines with
41    /// new ones.
42    // +optional
43    pub strategy: Option<MachineDeploymentStrategy>, // `json:"strategy,omitempty"`
44
45    /// Minimum number of seconds for which a newly created machine should
46    /// be ready.
47    /// Defaults to 0 (machine will be considered available as soon as it
48    // /is ready)
49    // +optional
50    pub min_ready_seconds: Option<i32>, // `json:"minReadySeconds,omitempty"`
51
52    /// The number of old MachineSets to retain to allow rollback.
53    /// This is a pointer to distinguish between explicit zero and not specified.
54    /// Defaults to 1.
55    // +optional
56    pub revision_history_limit: Option<i32>, // `json:"revisionHistoryLimit,omitempty"`
57
58    // Indicates that the deployment is paused.
59    // +optional
60    pub paused: Option<bool>, // `json:"paused,omitempty"`
61
62    // The maximum time in seconds for a deployment to make progress before it
63    // is considered to be failed. The deployment controller will continue to
64    // process failed deployments and a condition with a ProgressDeadlineExceeded
65    // reason will be surfaced in the deployment status. Note that progress will
66    // not be estimated during the time a deployment is paused. Defaults to 600s.
67    // +optional
68    pub progress_deadline_seconds: Option<i32>, // `json:"progressDeadlineSeconds,omitempty"`
69}
70
71#[skip_serializing_none]
72#[derive(Clone, Debug, Default, Serialize, Deserialize)]
73#[serde(rename_all = "camelCase")]
74pub struct MachineDeploymentStatus {
75    /// The generation observed by the deployment controller.
76    // +optional
77    observed_generation: Option<i64>, // `json:"observedGeneration,omitempty"`
78
79    /// Selector is the same as the label selector but in the string format to avoid introspection
80    /// by clients. The string will be in the same format as the query-param syntax.
81    /// More info about label selectors: http://kubernetes.io/docs/user-guide/labels#label-selectors
82    // +optional
83    selector: Option<String>, // `json:"selector,omitempty"`
84
85    /// Total number of non-terminated machines targeted by this deployment
86    /// (their labels match the selector).
87    // +optional
88    replicas: Option<i32>, //`json:"replicas"`
89
90    /// Total number of non-terminated machines targeted by this deployment
91    /// that have the desired template spec.
92    // +optional
93    updated_replicas: Option<i32>, // `json:"updatedReplicas"`
94
95    /// Total number of ready machines targeted by this deployment.
96    // +optional
97    ready_replicas: Option<i32>, // `json:"readyReplicas"`
98
99    /// Total number of available machines (ready for at least minReadySeconds)
100    /// targeted by this deployment.
101    // +optional
102    available_replicas: Option<i32>, // `json:"availableReplicas"`
103
104    /// Total number of unavailable machines targeted by this deployment.
105    /// This is the total number of machines that are still required for
106    /// the deployment to have 100% available capacity. They may either
107    /// be machines that are running but not yet available or machines
108    /// that still have not been created.
109    // +optional
110    unavailable_replicas: Option<i32>, // `json:"unavailableReplicas"`
111
112    /// Phase represents the current phase of a MachineDeployment (ScalingUp, ScalingDown, Running, Failed, or Unknown).
113    // +optional
114    phase: Option<String>, // `json:"phase,omitempty"`
115
116    /// Conditions defines current service state of the MachineDeployment.
117    // +optional
118    conditions: Option<Conditions>, // `json:"conditions,omitempty"`
119}
120
121/// MachineDeploymentStrategyType defines the type of MachineDeployment rollout strategies.
122#[derive(Clone, Copy, Debug, Serialize, Deserialize)]
123pub enum MachineDeploymentStrategyType {
124    /// RollingUpdateMachineDeploymentStrategyType replaces the old MachineSet by new one using rolling update
125    /// i.e. gradually scale down the old MachineSet and scale up the new one.
126    RollingUpdate,
127
128    /// OnDeleteMachineDeploymentStrategyType replaces old MachineSets when the deletion of the associated machines are completed.
129    OnDelete,
130}
131
132/// MachineDeploymentStrategy describes how to replace existing machines
133/// with new ones.
134#[skip_serializing_none]
135#[derive(Clone, Debug, Default, Serialize, Deserialize)]
136#[serde(rename_all = "camelCase")]
137pub struct MachineDeploymentStrategy {
138    /// Type of deployment.
139    /// Default is RollingUpdate.
140    // +kubebuilder:validation:Enum=RollingUpdate;OnDelete
141    // +optional
142    pub r#type: Option<MachineDeploymentStrategyType>, // `json:"type,omitempty"`
143
144    /// Rolling update config params. Present only if
145    /// MachineDeploymentStrategyType = RollingUpdate.
146    // +optional
147    pub rolling_update: Option<MachineRollingUpdateDeployment>, // `json:"rollingUpdate,omitempty"`
148}
149
150// MachineRollingUpdateDeployment is used to control the desired behavior of rolling update.
151#[skip_serializing_none]
152#[derive(Clone, Debug, Default, Serialize, Deserialize)]
153#[serde(rename_all = "camelCase")]
154pub struct MachineRollingUpdateDeployment {
155    // The maximum number of machines that can be unavailable during the update.
156    // Value can be an absolute number (ex: 5) or a percentage of desired
157    // machines (ex: 10%).
158    // Absolute number is calculated from percentage by rounding down.
159    // This can not be 0 if MaxSurge is 0.
160    // Defaults to 0.
161    // Example: when this is set to 30%, the old MachineSet can be scaled
162    // down to 70% of desired machines immediately when the rolling update
163    // starts. Once new machines are ready, old MachineSet can be scaled
164    // down further, followed by scaling up the new MachineSet, ensuring
165    // that the total number of machines available at all times
166    // during the update is at least 70% of desired machines.
167    // +optional
168    pub max_unavailable: Option<intstr::IntOrString>, // `json:"maxUnavailable,omitempty"`
169
170    // The maximum number of machines that can be scheduled above the
171    // desired number of machines.
172    // Value can be an absolute number (ex: 5) or a percentage of
173    // desired machines (ex: 10%).
174    // This can not be 0 if MaxUnavailable is 0.
175    // Absolute number is calculated from percentage by rounding up.
176    // Defaults to 1.
177    // Example: when this is set to 30%, the new MachineSet can be scaled
178    // up immediately when the rolling update starts, such that the total
179    // number of old and new machines do not exceed 130% of desired
180    // machines. Once old machines have been killed, new MachineSet can
181    // be scaled up further, ensuring that total number of machines running
182    // at any time during the update is at most 130% of desired machines.
183    // +optional
184    pub max_surge: Option<intstr::IntOrString>, // `json:"maxSurge,omitempty"`
185
186    // DeletePolicy defines the policy used by the MachineDeployment to identify nodes to delete when downscaling.
187    // Valid values are "Random, "Newest", "Oldest"
188    // When no value is supplied, the default DeletePolicy of MachineSet is used
189    // +kubebuilder:validation:Enum=Random;Newest;Oldest
190    // +optional
191    pub delete_policy: Option<String>, // `json:"deletePolicy,omitempty"`
192}
193
194/*
195
196package v1beta1
197
198import (
199    metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
200    "k8s.io/apimachinery/pkg/util/intstr"
201)
202
203const (
204    // MachineDeploymentTopologyFinalizer is the finalizer used by the topology MachineDeployment controller to
205    // clean up referenced template resources if necessary when a MachineDeployment is being deleted.
206    MachineDeploymentTopologyFinalizer = "machinedeployment.topology.cluster.x-k8s.io"
207)
208
209const (
210    // RevisionAnnotation is the revision annotation of a machine deployment's machine sets which records its rollout sequence.
211    RevisionAnnotation = "machinedeployment.clusters.x-k8s.io/revision"
212
213    // RevisionHistoryAnnotation maintains the history of all old revisions that a machine set has served for a machine deployment.
214    RevisionHistoryAnnotation = "machinedeployment.clusters.x-k8s.io/revision-history"
215
216    // DesiredReplicasAnnotation is the desired replicas for a machine deployment recorded as an annotation
217    // in its machine sets. Helps in separating scaling events from the rollout process and for
218    // determining if the new machine set for a deployment is really saturated.
219    DesiredReplicasAnnotation = "machinedeployment.clusters.x-k8s.io/desired-replicas"
220
221    // MaxReplicasAnnotation is the maximum replicas a deployment can have at a given point, which
222    // is machinedeployment.spec.replicas + maxSurge. Used by the underlying machine sets to estimate their
223    // proportions in case the deployment has surge replicas.
224    MaxReplicasAnnotation = "machinedeployment.clusters.x-k8s.io/max-replicas"
225
226    // MachineDeploymentUniqueLabel is the label applied to Machines
227    // in a MachineDeployment containing the hash of the template.
228    MachineDeploymentUniqueLabel = "machine-template-hash"
229)
230
231// ANCHOR: MachineDeploymentSpec
232
233
234// ANCHOR_END: MachineDeploymentSpec
235
236// ANCHOR: MachineDeploymentStrategy
237
238// ANCHOR_END: MachineDeploymentStrategy
239
240// ANCHOR: MachineRollingUpdateDeployment
241
242// ANCHOR_END: MachineRollingUpdateDeployment
243
244// ANCHOR: MachineDeploymentStatus
245
246// MachineDeploymentStatus defines the observed state of MachineDeployment.
247type MachineDeploymentStatus struct {
248    // The generation observed by the deployment controller.
249    // +optional
250    ObservedGeneration int64 `json:"observedGeneration,omitempty"`
251
252    // Selector is the same as the label selector but in the string format to avoid introspection
253    // by clients. The string will be in the same format as the query-param syntax.
254    // More info about label selectors: http://kubernetes.io/docs/user-guide/labels#label-selectors
255    // +optional
256    Selector string `json:"selector,omitempty"`
257
258    // Total number of non-terminated machines targeted by this deployment
259    // (their labels match the selector).
260    // +optional
261    Replicas int32 `json:"replicas"`
262
263    // Total number of non-terminated machines targeted by this deployment
264    // that have the desired template spec.
265    // +optional
266    UpdatedReplicas int32 `json:"updatedReplicas"`
267
268    // Total number of ready machines targeted by this deployment.
269    // +optional
270    ReadyReplicas int32 `json:"readyReplicas"`
271
272    // Total number of available machines (ready for at least minReadySeconds)
273    // targeted by this deployment.
274    // +optional
275    AvailableReplicas int32 `json:"availableReplicas"`
276
277    // Total number of unavailable machines targeted by this deployment.
278    // This is the total number of machines that are still required for
279    // the deployment to have 100% available capacity. They may either
280    // be machines that are running but not yet available or machines
281    // that still have not been created.
282    // +optional
283    UnavailableReplicas int32 `json:"unavailableReplicas"`
284
285    // Phase represents the current phase of a MachineDeployment (ScalingUp, ScalingDown, Running, Failed, or Unknown).
286    // +optional
287    Phase string `json:"phase,omitempty"`
288
289    // Conditions defines current service state of the MachineDeployment.
290    // +optional
291    Conditions Conditions `json:"conditions,omitempty"`
292}
293
294// ANCHOR_END: MachineDeploymentStatus
295
296// MachineDeploymentPhase indicates the progress of the machine deployment.
297type MachineDeploymentPhase string
298
299const (
300    // MachineDeploymentPhaseScalingUp indicates the MachineDeployment is scaling up.
301    MachineDeploymentPhaseScalingUp = MachineDeploymentPhase("ScalingUp")
302
303    // MachineDeploymentPhaseScalingDown indicates the MachineDeployment is scaling down.
304    MachineDeploymentPhaseScalingDown = MachineDeploymentPhase("ScalingDown")
305
306    // MachineDeploymentPhaseRunning indicates scaling has completed and all Machines are running.
307    MachineDeploymentPhaseRunning = MachineDeploymentPhase("Running")
308
309    // MachineDeploymentPhaseFailed indicates there was a problem scaling and user intervention might be required.
310    MachineDeploymentPhaseFailed = MachineDeploymentPhase("Failed")
311
312    // MachineDeploymentPhaseUnknown indicates the state of the MachineDeployment cannot be determined.
313    MachineDeploymentPhaseUnknown = MachineDeploymentPhase("Unknown")
314)
315
316// SetTypedPhase sets the Phase field to the string representation of MachineDeploymentPhase.
317func (md *MachineDeploymentStatus) SetTypedPhase(p MachineDeploymentPhase) {
318    md.Phase = string(p)
319}
320
321// GetTypedPhase attempts to parse the Phase field and return
322// the typed MachineDeploymentPhase representation.
323func (md *MachineDeploymentStatus) GetTypedPhase() MachineDeploymentPhase {
324    switch phase := MachineDeploymentPhase(md.Phase); phase {
325    case
326        MachineDeploymentPhaseScalingDown,
327        MachineDeploymentPhaseScalingUp,
328        MachineDeploymentPhaseRunning,
329        MachineDeploymentPhaseFailed:
330        return phase
331    default:
332        return MachineDeploymentPhaseUnknown
333    }
334}
335
336// +kubebuilder:object:root=true
337// +kubebuilder:resource:path=machinedeployments,shortName=md,scope=Namespaced,categories=cluster-api
338// +kubebuilder:storageversion
339// +kubebuilder:subresource:status
340// +kubebuilder:subresource:scale:specpath=.spec.replicas,statuspath=.status.replicas,selectorpath=.status.selector
341// +kubebuilder:printcolumn:name="Cluster",type="string",JSONPath=".spec.clusterName",description="Cluster"
342// +kubebuilder:printcolumn:name="Replicas",type="integer",JSONPath=".status.replicas",description="Total number of non-terminated machines targeted by this MachineDeployment"
343// +kubebuilder:printcolumn:name="Ready",type="integer",JSONPath=".status.readyReplicas",description="Total number of ready machines targeted by this MachineDeployment"
344// +kubebuilder:printcolumn:name="Updated",type=integer,JSONPath=".status.updatedReplicas",description="Total number of non-terminated machines targeted by this deployment that have the desired template spec"
345// +kubebuilder:printcolumn:name="Unavailable",type=integer,JSONPath=".status.unavailableReplicas",description="Total number of unavailable machines targeted by this MachineDeployment"
346// +kubebuilder:printcolumn:name="Phase",type="string",JSONPath=".status.phase",description="MachineDeployment status such as ScalingUp/ScalingDown/Running/Failed/Unknown"
347// +kubebuilder:printcolumn:name="Age",type="date",JSONPath=".metadata.creationTimestamp",description="Time duration since creation of MachineDeployment"
348// +kubebuilder:printcolumn:name="Version",type="string",JSONPath=".spec.template.spec.version",description="Kubernetes version associated with this MachineDeployment"
349
350// MachineDeployment is the Schema for the machinedeployments API.
351type MachineDeployment struct {
352    metav1.TypeMeta   `json:",inline"`
353    metav1.ObjectMeta `json:"metadata,omitempty"`
354
355    Spec   MachineDeploymentSpec   `json:"spec,omitempty"`
356    Status MachineDeploymentStatus `json:"status,omitempty"`
357}
358
359// +kubebuilder:object:root=true
360
361// MachineDeploymentList contains a list of MachineDeployment.
362type MachineDeploymentList struct {
363    metav1.TypeMeta `json:",inline"`
364    metav1.ListMeta `json:"metadata,omitempty"`
365    Items           []MachineDeployment `json:"items"`
366}
367
368func init() {
369    SchemeBuilder.Register(&MachineDeployment{}, &MachineDeploymentList{})
370}
371
372// GetConditions returns the set of conditions for the machinedeployment.
373func (m *MachineDeployment) GetConditions() Conditions {
374    return m.Status.Conditions
375}
376
377// SetConditions updates the set of conditions on the machinedeployment.
378func (m *MachineDeployment) SetConditions(conditions Conditions) {
379    m.Status.Conditions = conditions
380}
381
382*/
383
384#[cfg(test)]
385mod tests;