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