sigs.k8s.io/cluster-api@v1.7.1/exp/api/v1beta1/machinepool_types.go (about)

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