1 package v1beta1 2 3 import ( 4 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 5 ) 6 7 // +genclient 8 // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object 9 10 // MachineSet ensures that a specified number of machines replicas are running at any given time. 11 // +k8s:openapi-gen=true 12 // +kubebuilder:subresource:status 13 // +kubebuilder:subresource:scale:specpath=.spec.replicas,statuspath=.status.replicas,selectorpath=.status.labelSelector 14 // +kubebuilder:printcolumn:name="Desired",type="integer",JSONPath=".spec.replicas",description="Desired Replicas" 15 // +kubebuilder:printcolumn:name="Current",type="integer",JSONPath=".status.replicas",description="Current Replicas" 16 // +kubebuilder:printcolumn:name="Ready",type="integer",JSONPath=".status.readyReplicas",description="Ready Replicas" 17 // +kubebuilder:printcolumn:name="Available",type="string",JSONPath=".status.availableReplicas",description="Observed number of available replicas" 18 // +kubebuilder:printcolumn:name="Age",type="date",JSONPath=".metadata.creationTimestamp",description="Machineset age" 19 // Compatibility level 2: Stable within a major release for a minimum of 9 months or 3 minor releases (whichever is longer). 20 // +openshift:compatibility-gen:level=2 21 type MachineSet struct { 22 metav1.TypeMeta `json:",inline"` 23 24 // metadata is the standard object's metadata. 25 // More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata 26 metav1.ObjectMeta `json:"metadata,omitempty"` 27 28 Spec MachineSetSpec `json:"spec,omitempty"` 29 Status MachineSetStatus `json:"status,omitempty"` 30 } 31 32 // MachineSetSpec defines the desired state of MachineSet 33 type MachineSetSpec struct { 34 // Replicas is the number of desired replicas. 35 // This is a pointer to distinguish between explicit zero and unspecified. 36 // Defaults to 1. 37 // +kubebuilder:default=1 38 Replicas *int32 `json:"replicas,omitempty"` 39 // MinReadySeconds is the minimum number of seconds for which a newly created machine should be ready. 40 // Defaults to 0 (machine will be considered available as soon as it is ready) 41 // +optional 42 MinReadySeconds int32 `json:"minReadySeconds,omitempty"` 43 // DeletePolicy defines the policy used to identify nodes to delete when downscaling. 44 // Defaults to "Random". Valid values are "Random, "Newest", "Oldest" 45 // +kubebuilder:validation:Enum=Random;Newest;Oldest 46 DeletePolicy string `json:"deletePolicy,omitempty"` 47 // Selector is a label query over machines that should match the replica count. 48 // Label keys and values that must match in order to be controlled by this MachineSet. 49 // It must match the machine template's labels. 50 // More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/labels/#label-selectors 51 Selector metav1.LabelSelector `json:"selector"` 52 // Template is the object that describes the machine that will be created if 53 // insufficient replicas are detected. 54 // +optional 55 Template MachineTemplateSpec `json:"template,omitempty"` 56 } 57 58 // MachineSetDeletePolicy defines how priority is assigned to nodes to delete when 59 // downscaling a MachineSet. Defaults to "Random". 60 type MachineSetDeletePolicy string 61 62 const ( 63 // RandomMachineSetDeletePolicy prioritizes both Machines that have the annotation 64 // "cluster.k8s.io/delete-machine=yes" and Machines that are unhealthy 65 // (Status.ErrorReason or Status.ErrorMessage are set to a non-empty value). 66 // Finally, it picks Machines at random to delete. 67 RandomMachineSetDeletePolicy MachineSetDeletePolicy = "Random" 68 // NewestMachineSetDeletePolicy prioritizes both Machines that have the annotation 69 // "cluster.k8s.io/delete-machine=yes" and Machines that are unhealthy 70 // (Status.ErrorReason or Status.ErrorMessage are set to a non-empty value). 71 // It then prioritizes the newest Machines for deletion based on the Machine's CreationTimestamp. 72 NewestMachineSetDeletePolicy MachineSetDeletePolicy = "Newest" 73 // OldestMachineSetDeletePolicy prioritizes both Machines that have the annotation 74 // "cluster.k8s.io/delete-machine=yes" and Machines that are unhealthy 75 // (Status.ErrorReason or Status.ErrorMessage are set to a non-empty value). 76 // It then prioritizes the oldest Machines for deletion based on the Machine's CreationTimestamp. 77 OldestMachineSetDeletePolicy MachineSetDeletePolicy = "Oldest" 78 ) 79 80 // MachineTemplateSpec describes the data needed to create a Machine from a template 81 type MachineTemplateSpec struct { 82 // Standard object's metadata. 83 // More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata 84 // +optional 85 ObjectMeta `json:"metadata,omitempty"` 86 // Specification of the desired behavior of the machine. 87 // More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#spec-and-status 88 // +optional 89 Spec MachineSpec `json:"spec,omitempty"` 90 } 91 92 // MachineSetStatus defines the observed state of MachineSet 93 type MachineSetStatus struct { 94 // Replicas is the most recently observed number of replicas. 95 Replicas int32 `json:"replicas"` 96 // The number of replicas that have labels matching the labels of the machine template of the MachineSet. 97 // +optional 98 FullyLabeledReplicas int32 `json:"fullyLabeledReplicas,omitempty"` 99 // The number of ready replicas for this MachineSet. A machine is considered ready when the node has been created and is "Ready". 100 // +optional 101 ReadyReplicas int32 `json:"readyReplicas,omitempty"` 102 // The number of available replicas (ready for at least minReadySeconds) for this MachineSet. 103 // +optional 104 AvailableReplicas int32 `json:"availableReplicas,omitempty"` 105 // ObservedGeneration reflects the generation of the most recently observed MachineSet. 106 // +optional 107 ObservedGeneration int64 `json:"observedGeneration,omitempty"` 108 // In the event that there is a terminal problem reconciling the 109 // replicas, both ErrorReason and ErrorMessage will be set. ErrorReason 110 // will be populated with a succinct value suitable for machine 111 // interpretation, while ErrorMessage will contain a more verbose 112 // string suitable for logging and human consumption. 113 // 114 // These fields should not be set for transitive errors that a 115 // controller faces that are expected to be fixed automatically over 116 // time (like service outages), but instead indicate that something is 117 // fundamentally wrong with the MachineTemplate's spec or the configuration of 118 // the machine controller, and that manual intervention is required. Examples 119 // of terminal errors would be invalid combinations of settings in the 120 // spec, values that are unsupported by the machine controller, or the 121 // responsible machine controller itself being critically misconfigured. 122 // 123 // Any transient errors that occur during the reconciliation of Machines 124 // can be added as events to the MachineSet object and/or logged in the 125 // controller's output. 126 // +optional 127 ErrorReason *MachineSetStatusError `json:"errorReason,omitempty"` 128 // +optional 129 ErrorMessage *string `json:"errorMessage,omitempty"` 130 } 131 132 // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object 133 134 // MachineSetList contains a list of MachineSet 135 // Compatibility level 2: Stable within a major release for a minimum of 9 months or 3 minor releases (whichever is longer). 136 // +openshift:compatibility-gen:level=2 137 type MachineSetList struct { 138 metav1.TypeMeta `json:",inline"` 139 140 // metadata is the standard list's metadata. 141 // More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata 142 metav1.ListMeta `json:"metadata,omitempty"` 143 144 Items []MachineSet `json:"items"` 145 } 146