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