|
| 1 | +package v1alpha1 |
| 2 | + |
| 3 | +import ( |
| 4 | + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" |
| 5 | + clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1" |
| 6 | +) |
| 7 | + |
| 8 | +const ManagedClusterFinalizer = "scalewaycluster.infrastructure.cluster.x-k8s.io/smc-protection" |
| 9 | + |
| 10 | +// ScalewayManagedClusterSpec defines the desired state of ScalewayManagedCluster |
| 11 | +// |
| 12 | +// +kubebuilder:validation:XValidation:rule="!has(oldSelf.controlPlaneEndpoint) || has(self.controlPlaneEndpoint)", message="controlPlaneEndpoint is required once set" |
| 13 | +// +kubebuilder:validation:XValidation:rule="(has(self.network) && has(self.network.privateNetwork)) == (has(oldSelf.network) && has(oldSelf.network.privateNetwork))",message="privateNetwork cannot be added or removed" |
| 14 | +type ScalewayManagedClusterSpec struct { |
| 15 | + // Region where the managed cluster will be created. |
| 16 | + // +kubebuilder:validation:XValidation:rule="self == oldSelf",message="Value is immutable" |
| 17 | + // +kubebuilder:validation:MinLength:=2 |
| 18 | + Region string `json:"region"` |
| 19 | + |
| 20 | + // ProjectID in which the managed cluster will be created. |
| 21 | + // +kubebuilder:validation:XValidation:rule="self == oldSelf",message="Value is immutable" |
| 22 | + // +kubebuilder:validation:MinLength:=2 |
| 23 | + ProjectID string `json:"projectID"` |
| 24 | + |
| 25 | + // ScalewaySecretName is the name of the secret that contains the Scaleway client parameters. |
| 26 | + // The following keys are required: SCW_ACCESS_KEY, SCW_SECRET_KEY, SCW_DEFAULT_PROJECT_ID. |
| 27 | + // The following key is optional: SCW_API_URL. |
| 28 | + // +kubebuilder:validation:MinLength:=1 |
| 29 | + ScalewaySecretName string `json:"scalewaySecretName"` |
| 30 | + |
| 31 | + // Network defines the network configuration of the managed cluster. |
| 32 | + // +optional |
| 33 | + Network *ManagedNetworkSpec `json:"network,omitempty"` |
| 34 | + |
| 35 | + // ControlPlaneEndpoint represents the endpoint used to communicate with the control plane. |
| 36 | + // +kubebuilder:validation:XValidation:rule="self == oldSelf",message="Value is immutable" |
| 37 | + // +optional |
| 38 | + ControlPlaneEndpoint clusterv1.APIEndpoint `json:"controlPlaneEndpoint,omitempty,omitzero"` |
| 39 | +} |
| 40 | + |
| 41 | +// ManagedNetworkSpec defines the network configuration of a managed cluster. |
| 42 | +type ManagedNetworkSpec struct { |
| 43 | + // PrivateNetwork allows attaching machines of the cluster to a Private Network. |
| 44 | + // +kubebuilder:validation:XValidation:rule="has(self.vpcID) == has(oldSelf.vpcID)",message="vpcID cannot be added or removed" |
| 45 | + // +kubebuilder:validation:XValidation:rule="has(self.id) == has(oldSelf.id)",message="id cannot be added or removed" |
| 46 | + // +kubebuilder:validation:XValidation:rule="has(self.subnet) == has(oldSelf.subnet)",message="subnet cannot be added or removed" |
| 47 | + // +kubebuilder:validation:XValidation:rule="has(self.id) && !has(self.subnet) || !has(self.id)",message="subnet cannot be set when id is set" |
| 48 | + // +kubebuilder:validation:XValidation:rule="has(self.id) && !has(self.vpcID) || !has(self.id)",message="vpcID cannot be set when id is set" |
| 49 | + // +optional |
| 50 | + PrivateNetwork *PrivateNetworkParams `json:"privateNetwork,omitempty"` |
| 51 | + |
| 52 | + // PublicGateways allows to create Public Gateways that will be attached to the |
| 53 | + // Private Network of the cluster. |
| 54 | + // +kubebuilder:validation:MaxItems=6 |
| 55 | + // +optional |
| 56 | + PublicGateways []PublicGatewaySpec `json:"publicGateways,omitempty"` |
| 57 | +} |
| 58 | + |
| 59 | +// ScalewayManagedClusterStatus defines the observed state of ScalewayManagedCluster. |
| 60 | +type ScalewayManagedClusterStatus struct { |
| 61 | + // Ready denotes that the Scaleway managed cluster infrastructure is fully provisioned. |
| 62 | + // NOTE: this field is part of the Cluster API contract and it is used to orchestrate provisioning. |
| 63 | + // The value of this field is never updated after provisioning is completed. |
| 64 | + // +optional |
| 65 | + Ready bool `json:"ready"` |
| 66 | + |
| 67 | + // Network contains information about currently provisioned network resources. |
| 68 | + // +optional |
| 69 | + Network *ManagedNetworkStatus `json:"network,omitempty"` |
| 70 | +} |
| 71 | + |
| 72 | +// ManagedNetworkStatus contains information about currently provisioned network resources. |
| 73 | +type ManagedNetworkStatus struct { |
| 74 | + // PrivateNetworkID is the ID of the Private Network that is attached to the cluster. |
| 75 | + // +optional |
| 76 | + PrivateNetworkID *string `json:"privateNetworkID,omitempty"` |
| 77 | +} |
| 78 | + |
| 79 | +// +kubebuilder:object:root=true |
| 80 | +// +kubebuilder:resource:path=scalewaymanagedclusters,scope=Namespaced,categories=cluster-api,shortName=smc |
| 81 | +// +kubebuilder:subresource:status |
| 82 | +// +kubebuilder:storageversion |
| 83 | +// +kubebuilder:printcolumn:name="Cluster",type="string",JSONPath=".metadata.labels.cluster\\.x-k8s\\.io/cluster-name",description="Cluster to which this ScalewayManagedCluster belongs" |
| 84 | +// +kubebuilder:printcolumn:name="Ready",type="boolean",JSONPath=".status.ready",description="Ready is true when the managed cluster is fully provisioned" |
| 85 | +// +kubebuilder:printcolumn:name="Region",type="string",JSONPath=".spec.region",description="Region of the managed cluster" |
| 86 | +// +kubebuilder:printcolumn:name="Host",type="string",JSONPath=".spec.controlPlaneEndpoint.host",description="Host of the control plane" |
| 87 | +// +kubebuilder:printcolumn:name="Port",type="integer",JSONPath=".spec.controlPlaneEndpoint.port",description="Port of the control plane" |
| 88 | + |
| 89 | +// ScalewayManagedCluster is the Schema for the scalewaymanagedclusters API |
| 90 | +// +kubebuilder:validation:XValidation:rule="self.metadata.name.size() <= 63",message="name must be between 1 and 63 characters" |
| 91 | +// +kubebuilder:validation:XValidation:rule="self.metadata.name.matches('^[a-z0-9]([-a-z0-9]*[a-z0-9])?$')",message="name must be a valid DNS label" |
| 92 | +type ScalewayManagedCluster struct { |
| 93 | + metav1.TypeMeta `json:",inline"` |
| 94 | + |
| 95 | + // metadata is a standard object metadata |
| 96 | + // +optional |
| 97 | + metav1.ObjectMeta `json:"metadata,omitempty,omitzero"` |
| 98 | + |
| 99 | + // spec defines the desired state of ScalewayManagedCluster |
| 100 | + // +required |
| 101 | + Spec ScalewayManagedClusterSpec `json:"spec"` |
| 102 | + |
| 103 | + // status defines the observed state of ScalewayManagedCluster |
| 104 | + // +optional |
| 105 | + Status ScalewayManagedClusterStatus `json:"status,omitempty,omitzero"` |
| 106 | +} |
| 107 | + |
| 108 | +// +kubebuilder:object:root=true |
| 109 | + |
| 110 | +// ScalewayManagedClusterList contains a list of ScalewayManagedCluster |
| 111 | +type ScalewayManagedClusterList struct { |
| 112 | + metav1.TypeMeta `json:",inline"` |
| 113 | + metav1.ListMeta `json:"metadata,omitempty"` |
| 114 | + Items []ScalewayManagedCluster `json:"items"` |
| 115 | +} |
| 116 | + |
| 117 | +func init() { |
| 118 | + SchemeBuilder.Register(&ScalewayManagedCluster{}, &ScalewayManagedClusterList{}) |
| 119 | +} |
0 commit comments