sigs.k8s.io/cluster-api@v1.6.3/exp/api/v1alpha4/machinepool_types.go (about) 1 /* 2 Copyright 2019 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 clusterv1alpha4 "sigs.k8s.io/cluster-api/api/v1alpha4" 24 capierrors "sigs.k8s.io/cluster-api/errors" 25 ) 26 27 const ( 28 // MachinePoolFinalizer is used to ensure deletion of dependencies (nodes, infra). 29 MachinePoolFinalizer = "machinepool.cluster.x-k8s.io" 30 ) 31 32 // ANCHOR: MachinePoolSpec 33 34 // MachinePoolSpec defines the desired state of MachinePool. 35 type MachinePoolSpec struct { 36 // ClusterName is the name of the Cluster this object belongs to. 37 // +kubebuilder:validation:MinLength=1 38 ClusterName string `json:"clusterName"` 39 40 // Number of desired machines. Defaults to 1. 41 // This is a pointer to distinguish between explicit zero and not specified. 42 Replicas *int32 `json:"replicas,omitempty"` 43 44 // Template describes the machines that will be created. 45 Template clusterv1alpha4.MachineTemplateSpec `json:"template"` 46 47 // Minimum number of seconds for which a newly created machine instances should 48 // be ready. 49 // Defaults to 0 (machine instance will be considered available as soon as it 50 // is ready) 51 // +optional 52 MinReadySeconds *int32 `json:"minReadySeconds,omitempty"` 53 54 // ProviderIDList are the identification IDs of machine instances provided by the provider. 55 // This field must match the provider IDs as seen on the node objects corresponding to a machine pool's machine instances. 56 // +optional 57 ProviderIDList []string `json:"providerIDList,omitempty"` 58 59 // FailureDomains is the list of failure domains this MachinePool should be attached to. 60 FailureDomains []string `json:"failureDomains,omitempty"` 61 } 62 63 // ANCHOR_END: MachinePoolSpec 64 65 // ANCHOR: MachinePoolStatus 66 67 // MachinePoolStatus defines the observed state of MachinePool. 68 type MachinePoolStatus struct { 69 // NodeRefs will point to the corresponding Nodes if it they exist. 70 // +optional 71 NodeRefs []corev1.ObjectReference `json:"nodeRefs,omitempty"` 72 73 // Replicas is the most recently observed number of replicas. 74 // +optional 75 Replicas int32 `json:"replicas"` 76 77 // The number of ready replicas for this MachinePool. A machine is considered ready when the node has been created and is "Ready". 78 // +optional 79 ReadyReplicas int32 `json:"readyReplicas,omitempty"` 80 81 // The number of available replicas (ready for at least minReadySeconds) for this MachinePool. 82 // +optional 83 AvailableReplicas int32 `json:"availableReplicas,omitempty"` 84 85 // Total number of unavailable machine instances targeted by this machine pool. 86 // This is the total number of machine instances that are still required for 87 // the machine pool to have 100% available capacity. They may either 88 // be machine instances that are running but not yet available or machine instances 89 // that still have not been created. 90 // +optional 91 UnavailableReplicas int32 `json:"unavailableReplicas,omitempty"` 92 93 // FailureReason indicates that there is a problem reconciling the state, and 94 // will be set to a token value suitable for programmatic interpretation. 95 // +optional 96 FailureReason *capierrors.MachinePoolStatusFailure `json:"failureReason,omitempty"` 97 98 // FailureMessage indicates that there is a problem reconciling the state, 99 // and will be set to a descriptive error message. 100 // +optional 101 FailureMessage *string `json:"failureMessage,omitempty"` 102 103 // Phase represents the current phase of cluster actuation. 104 // E.g. Pending, Running, Terminating, Failed etc. 105 // +optional 106 Phase string `json:"phase,omitempty"` 107 108 // BootstrapReady is the state of the bootstrap provider. 109 // +optional 110 BootstrapReady bool `json:"bootstrapReady"` 111 112 // InfrastructureReady is the state of the infrastructure provider. 113 // +optional 114 InfrastructureReady bool `json:"infrastructureReady"` 115 116 // ObservedGeneration is the latest generation observed by the controller. 117 // +optional 118 ObservedGeneration int64 `json:"observedGeneration,omitempty"` 119 120 // Conditions define the current service state of the MachinePool. 121 // +optional 122 Conditions clusterv1alpha4.Conditions `json:"conditions,omitempty"` 123 } 124 125 // ANCHOR_END: MachinePoolStatus 126 127 // MachinePoolPhase is a string representation of a MachinePool Phase. 128 // 129 // This type is a high-level indicator of the status of the MachinePool as it is provisioned, 130 // from the API user’s perspective. 131 // 132 // The value should not be interpreted by any software components as a reliable indication 133 // of the actual state of the MachinePool, and controllers should not use the MachinePool Phase field 134 // value when making decisions about what action to take. 135 // 136 // Controllers should always look at the actual state of the MachinePool’s fields to make those decisions. 137 type MachinePoolPhase string 138 139 const ( 140 // MachinePoolPhasePending is the first state a MachinePool is assigned by 141 // Cluster API MachinePool controller after being created. 142 MachinePoolPhasePending = MachinePoolPhase("Pending") 143 144 // MachinePoolPhaseProvisioning is the state when the 145 // MachinePool infrastructure is being created or updated. 146 MachinePoolPhaseProvisioning = MachinePoolPhase("Provisioning") 147 148 // MachinePoolPhaseProvisioned is the state when its 149 // infrastructure has been created and configured. 150 MachinePoolPhaseProvisioned = MachinePoolPhase("Provisioned") 151 152 // MachinePoolPhaseRunning is the MachinePool state when its instances 153 // have become Kubernetes Nodes in the Ready state. 154 MachinePoolPhaseRunning = MachinePoolPhase("Running") 155 156 // MachinePoolPhaseScalingUp is the MachinePool state when the 157 // MachinePool infrastructure is scaling up. 158 MachinePoolPhaseScalingUp = MachinePoolPhase("ScalingUp") 159 160 // MachinePoolPhaseScalingDown is the MachinePool state when the 161 // MachinePool infrastructure is scaling down. 162 MachinePoolPhaseScalingDown = MachinePoolPhase("ScalingDown") 163 164 // MachinePoolPhaseDeleting is the MachinePool state when a delete 165 // request has been sent to the API Server, 166 // but its infrastructure has not yet been fully deleted. 167 MachinePoolPhaseDeleting = MachinePoolPhase("Deleting") 168 169 // MachinePoolPhaseFailed is the MachinePool state when the system 170 // might require user intervention. 171 MachinePoolPhaseFailed = MachinePoolPhase("Failed") 172 173 // MachinePoolPhaseUnknown is returned if the MachinePool state cannot be determined. 174 MachinePoolPhaseUnknown = MachinePoolPhase("Unknown") 175 ) 176 177 // SetTypedPhase sets the Phase field to the string representation of MachinePoolPhase. 178 func (m *MachinePoolStatus) SetTypedPhase(p MachinePoolPhase) { 179 m.Phase = string(p) 180 } 181 182 // GetTypedPhase attempts to parse the Phase field and return 183 // the typed MachinePoolPhase representation as described in `machinepool_phase_types.go`. 184 func (m *MachinePoolStatus) GetTypedPhase() MachinePoolPhase { 185 switch phase := MachinePoolPhase(m.Phase); phase { 186 case 187 MachinePoolPhasePending, 188 MachinePoolPhaseProvisioning, 189 MachinePoolPhaseProvisioned, 190 MachinePoolPhaseRunning, 191 MachinePoolPhaseScalingUp, 192 MachinePoolPhaseScalingDown, 193 MachinePoolPhaseDeleting, 194 MachinePoolPhaseFailed: 195 return phase 196 default: 197 return MachinePoolPhaseUnknown 198 } 199 } 200 201 // +kubebuilder:object:root=true 202 // +kubebuilder:unservedversion 203 // +kubebuilder:deprecatedversion 204 // +kubebuilder:resource:path=machinepools,shortName=mp,scope=Namespaced,categories=cluster-api 205 // +kubebuilder:subresource:status 206 // +kubebuilder:subresource:scale:specpath=.spec.replicas,statuspath=.status.replicas 207 // +kubebuilder:printcolumn:name="Age",type="date",JSONPath=".metadata.creationTimestamp",description="Time duration since creation of MachinePool" 208 // +kubebuilder:printcolumn:name="Replicas",type="string",JSONPath=".status.replicas",description="MachinePool replicas count" 209 // +kubebuilder:printcolumn:name="Phase",type="string",JSONPath=".status.phase",description="MachinePool status such as Terminating/Pending/Provisioning/Running/Failed etc" 210 // +kubebuilder:printcolumn:name="Version",type="string",JSONPath=".spec.template.spec.version",description="Kubernetes version associated with this MachinePool" 211 // +k8s:conversion-gen=false 212 213 // MachinePool is the Schema for the machinepools API. 214 // 215 // Deprecated: This type will be removed in one of the next releases. 216 type MachinePool struct { 217 metav1.TypeMeta `json:",inline"` 218 metav1.ObjectMeta `json:"metadata,omitempty"` 219 220 Spec MachinePoolSpec `json:"spec,omitempty"` 221 Status MachinePoolStatus `json:"status,omitempty"` 222 } 223 224 // GetConditions returns the set of conditions for this object. 225 func (m *MachinePool) GetConditions() clusterv1alpha4.Conditions { 226 return m.Status.Conditions 227 } 228 229 // SetConditions sets the conditions on this object. 230 func (m *MachinePool) SetConditions(conditions clusterv1alpha4.Conditions) { 231 m.Status.Conditions = conditions 232 } 233 234 // +kubebuilder:object:root=true 235 236 // MachinePoolList contains a list of MachinePool. 237 // 238 // Deprecated: This type will be removed in one of the next releases. 239 type MachinePoolList struct { 240 metav1.TypeMeta `json:",inline"` 241 metav1.ListMeta `json:"metadata,omitempty"` 242 Items []MachinePool `json:"items"` 243 } 244 245 func init() { 246 objectTypes = append(objectTypes, &MachinePool{}, &MachinePoolList{}) 247 }