|
| 1 | +/* |
| 2 | +Copyright 2022 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 v1beta2 |
| 18 | + |
| 19 | +import ( |
| 20 | + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" |
| 21 | + |
| 22 | + clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1" |
| 23 | +) |
| 24 | + |
| 25 | +// RosaMachinePoolSpec defines the desired state of RosaMachinePool. |
| 26 | +type RosaMachinePoolSpec struct { |
| 27 | + // NodePoolName specifies the name of the nodepool in Rosa |
| 28 | + // must be a valid DNS-1035 label, so it must consist of lower case alphanumeric and have a max length of 15 characters. |
| 29 | + // |
| 30 | + // +immutable |
| 31 | + // +kubebuilder:validation:XValidation:rule="self == oldSelf", message="nodepoolName is immutable" |
| 32 | + // +kubebuilder:validation:MaxLength:=15 |
| 33 | + // +kubebuilder:validation:Pattern:=`^[a-z]([-a-z0-9]*[a-z0-9])?$` |
| 34 | + NodePoolName string `json:"nodePoolName"` |
| 35 | + |
| 36 | + // AvailabilityZone is an optinal field specifying the availability zone where instances of this machine pool should run |
| 37 | + // For Multi-AZ clusters, you can create a machine pool in a Single-AZ of your choice. |
| 38 | + // +optional |
| 39 | + AvailabilityZone string `json:"availabilityZone,omitempty"` |
| 40 | + |
| 41 | + // +optional |
| 42 | + Subnet string `json:"subnet,omitempty"` |
| 43 | + |
| 44 | + // Labels specifies labels for the Kubernetes node objects |
| 45 | + // +optional |
| 46 | + Labels map[string]string `json:"labels,omitempty"` |
| 47 | + |
| 48 | + // AutoRepair specifies whether health checks should be enabled for machines |
| 49 | + // in the NodePool. The default is false. |
| 50 | + // +optional |
| 51 | + // +kubebuilder:default=false |
| 52 | + AutoRepair bool `json:"autoRepair,omitempty"` |
| 53 | + |
| 54 | + // InstanceType specifies the AWS instance type |
| 55 | + InstanceType string `json:"instanceType,omitempty"` |
| 56 | + |
| 57 | + // Autoscaling specifies auto scaling behaviour for this MachinePool. |
| 58 | + // required if Replicas is not configured |
| 59 | + // +optional |
| 60 | + Autoscaling *RosaMachinePoolAutoScaling `json:"autoscaling,omitempty"` |
| 61 | + |
| 62 | + // TODO(alberto): Enable and propagate this API input. |
| 63 | + // Taints []*Taint `json:"taints,omitempty"` |
| 64 | + // TuningConfigs []string `json:"tuningConfigs,omitempty"` |
| 65 | + // Version *Version `json:"version,omitempty"` |
| 66 | + |
| 67 | + // ProviderIDList contain a ProviderID for each machine instance that's currently managed by this machine pool. |
| 68 | + // +optional |
| 69 | + ProviderIDList []string `json:"providerIDList,omitempty"` |
| 70 | +} |
| 71 | + |
| 72 | +// RosaMachinePoolAutoScaling specifies scaling options. |
| 73 | +type RosaMachinePoolAutoScaling struct { |
| 74 | + // +kubebuilder:validation:Minimum=1 |
| 75 | + MinReplicas int `json:"minReplicas,omitempty"` |
| 76 | + // +kubebuilder:validation:Minimum=1 |
| 77 | + MaxReplicas int `json:"maxReplicas,omitempty"` |
| 78 | +} |
| 79 | + |
| 80 | +// RosaMachinePoolStatus defines the observed state of RosaMachinePool. |
| 81 | +type RosaMachinePoolStatus struct { |
| 82 | + // Ready denotes that the RosaMachinePool nodepool has joined |
| 83 | + // the cluster |
| 84 | + // +kubebuilder:default=false |
| 85 | + Ready bool `json:"ready"` |
| 86 | + |
| 87 | + // Replicas is the most recently observed number of replicas. |
| 88 | + // +optional |
| 89 | + Replicas int32 `json:"replicas"` |
| 90 | + |
| 91 | + // Conditions defines current service state of the managed machine pool |
| 92 | + // +optional |
| 93 | + Conditions clusterv1.Conditions `json:"conditions,omitempty"` |
| 94 | + |
| 95 | + // ID is the ID given by ROSA. |
| 96 | + ID string `json:"id,omitempty"` |
| 97 | +} |
| 98 | + |
| 99 | +// +kubebuilder:object:root=true |
| 100 | +// +kubebuilder:resource:path=rosamachinepools,scope=Namespaced,categories=cluster-api,shortName=rosamp |
| 101 | +// +kubebuilder:storageversion |
| 102 | +// +kubebuilder:subresource:status |
| 103 | +// +kubebuilder:printcolumn:name="Ready",type="string",JSONPath=".status.ready",description="MachinePool ready status" |
| 104 | +// +kubebuilder:printcolumn:name="Replicas",type="integer",JSONPath=".status.replicas",description="Number of replicas" |
| 105 | + |
| 106 | +// ROSAMachinePool is the Schema for the rosamachinepools API. |
| 107 | +type ROSAMachinePool struct { |
| 108 | + metav1.TypeMeta `json:",inline"` |
| 109 | + metav1.ObjectMeta `json:"metadata,omitempty"` |
| 110 | + |
| 111 | + Spec RosaMachinePoolSpec `json:"spec,omitempty"` |
| 112 | + Status RosaMachinePoolStatus `json:"status,omitempty"` |
| 113 | +} |
| 114 | + |
| 115 | +// +kubebuilder:object:root=true |
| 116 | + |
| 117 | +// ROSAMachinePoolList contains a list of RosaMachinePools. |
| 118 | +type ROSAMachinePoolList struct { |
| 119 | + metav1.TypeMeta `json:",inline"` |
| 120 | + metav1.ListMeta `json:"metadata,omitempty"` |
| 121 | + Items []ROSAMachinePool `json:"items"` |
| 122 | +} |
| 123 | + |
| 124 | +// GetConditions returns the observations of the operational state of the RosaMachinePool resource. |
| 125 | +func (r *ROSAMachinePool) GetConditions() clusterv1.Conditions { |
| 126 | + return r.Status.Conditions |
| 127 | +} |
| 128 | + |
| 129 | +// SetConditions sets the underlying service state of the RosaMachinePool to the predescribed clusterv1.Conditions. |
| 130 | +func (r *ROSAMachinePool) SetConditions(conditions clusterv1.Conditions) { |
| 131 | + r.Status.Conditions = conditions |
| 132 | +} |
| 133 | + |
| 134 | +func init() { |
| 135 | + SchemeBuilder.Register(&ROSAMachinePool{}, &ROSAMachinePoolList{}) |
| 136 | +} |
0 commit comments