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