Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ E2E_ARTIFACTS ?= $(ROOT_DIR)/_artifacts
E2E_CONF_FILE ?= $(ROOT_DIR)/test/e2e/config/scaleway.yaml
E2E_CONF_FILE_ENVSUBST := $(ROOT_DIR)/test/e2e/config/scaleway-envsubst.yaml
E2E_V1BETA1_TEMPLATES := $(ROOT_DIR)/test/e2e/data/infrastructure-scaleway/v1beta1
E2E_FOCUS ?= ""

.PHONY: setup-test-e2e
setup-test-e2e: ## Set up a Kind cluster for e2e tests if it does not exist
Expand All @@ -84,11 +85,12 @@ setup-test-e2e: ## Set up a Kind cluster for e2e tests if it does not exist
generate-e2e: kustomize ## Generate templates for e2e
$(KUSTOMIZE) build $(E2E_V1BETA1_TEMPLATES)/cluster-template --load-restrictor LoadRestrictionsNone > $(E2E_V1BETA1_TEMPLATES)/cluster-template.yaml
$(KUSTOMIZE) build $(E2E_V1BETA1_TEMPLATES)/cluster-template-private-network --load-restrictor LoadRestrictionsNone > $(E2E_V1BETA1_TEMPLATES)/cluster-template-private-network.yaml
$(KUSTOMIZE) build $(E2E_V1BETA1_TEMPLATES)/cluster-template-managed --load-restrictor LoadRestrictionsNone > $(E2E_V1BETA1_TEMPLATES)/cluster-template-managed.yaml

.PHONY: test-e2e
test-e2e: setup-test-e2e generate-e2e docker-build envsubst ginkgo build-installer fmt vet ## Run the e2e tests. Expected an isolated environment using Kind.
MANAGER_IMAGE=$(IMG) $(ENVSUBST) < $(E2E_CONF_FILE) > $(E2E_CONF_FILE_ENVSUBST)
KIND_CLUSTER=$(KIND_CLUSTER) KUBECONFIG=$(KIND_KUBECONFIG) $(GINKGO) run -v --nodes 2 ./test/e2e/ -- \
KIND_CLUSTER=$(KIND_CLUSTER) KUBECONFIG=$(KIND_KUBECONFIG) $(GINKGO) run -v --nodes=2 --focus=$(E2E_FOCUS) ./test/e2e/ -- \
-e2e.config $(E2E_CONF_FILE_ENVSUBST) \
-e2e.use-existing-cluster \
-e2e.artifacts-folder=$(E2E_ARTIFACTS)
Expand Down
27 changes: 27 additions & 0 deletions PROJECT
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,31 @@ resources:
kind: ScalewayMachineTemplate
path: github.com/scaleway/cluster-api-provider-scaleway/api/v1alpha1
version: v1alpha1
- api:
crdVersion: v1
namespaced: true
controller: true
domain: cluster.x-k8s.io
group: infrastructure
kind: ScalewayManagedCluster
path: github.com/scaleway/cluster-api-provider-scaleway/api/v1alpha1
version: v1alpha1
- api:
crdVersion: v1
namespaced: true
controller: true
domain: cluster.x-k8s.io
group: infrastructure
kind: ScalewayManagedControlPlane
path: github.com/scaleway/cluster-api-provider-scaleway/api/v1alpha1
version: v1alpha1
- api:
crdVersion: v1
namespaced: true
controller: true
domain: cluster.x-k8s.io
group: infrastructure
kind: ScalewayManagedMachinePool
path: github.com/scaleway/cluster-api-provider-scaleway/api/v1alpha1
version: v1alpha1
version: "3"
43 changes: 3 additions & 40 deletions api/v1alpha1/scalewaycluster_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ type ScalewayClusterSpec struct {
Network *NetworkSpec `json:"network,omitempty"`

// ScalewaySecretName is the name of the secret that contains the Scaleway client parameters.
// The following keys are required: SCW_ACCESS_KEY, SCW_SECRET_KEY, SCW_DEFAULT_PROJECT_ID.
// The following keys are required: SCW_ACCESS_KEY, SCW_SECRET_KEY.
// The following key is optional: SCW_API_URL.
ScalewaySecretName string `json:"scalewaySecretName"`

Expand Down Expand Up @@ -142,12 +142,6 @@ type ControlPlaneLoadBalancerSpec struct {
Private *bool `json:"private,omitempty"`
}

// CIDR is an IP address range in CIDR notation (for example, "10.0.0.0/8" or "fd00::/8").
// +kubebuilder:validation:XValidation:rule="isCIDR(self)",message="value must be a valid CIDR network address"
// +kubebuilder:validation:MaxLength:=43
// +kubebuilder:validation:MinLength:=1
type CIDR string

type ControlPlaneDNSSpec struct {
// Domain is the DNS Zone that this record should live in. It must be pre-existing in your Scaleway account.
// The format must be a string that conforms to the definition of a subdomain in DNS (RFC 1123).
Expand All @@ -173,44 +167,13 @@ type ControlPlanePrivateDNSSpec struct {
// +kubebuilder:validation:XValidation:rule="has(self.id) && !has(self.subnet) || !has(self.id)",message="subnet cannot be set when id is set"
// +kubebuilder:validation:XValidation:rule="has(self.id) && !has(self.vpcID) || !has(self.id)",message="vpcID cannot be set when id is set"
type PrivateNetworkSpec struct {
PrivateNetworkParams `json:",inline"`

// Set to true to automatically attach machines to a Private Network.
// The Private Network is automatically created if no existing Private
// Network ID is provided.
// +kubebuilder:validation:XValidation:rule="self == oldSelf",message="Value is immutable"
Enabled bool `json:"enabled"`

// Set a Private Network ID to reuse an existing Private Network.
// +kubebuilder:validation:XValidation:rule="self == oldSelf",message="Value is immutable"
// +optional
ID *string `json:"id,omitempty"`

// Set the VPC ID where the new Private Network will be created.
// +kubebuilder:validation:XValidation:rule="self == oldSelf",message="Value is immutable"
// +optional
VPCID *string `json:"vpcID,omitempty"`

// Optional subnet for the Private Network. Only used on newly created Private Networks.
// +kubebuilder:validation:XValidation:rule="self == oldSelf",message="Value is immutable"
// +optional
Subnet *string `json:"subnet,omitempty"`
}

// PublicGatewaySpec defines Public Gateway settings for the cluster.
type PublicGatewaySpec struct {
// Public Gateway commercial offer type.
// +kubebuilder:default="VPC-GW-S"
// +optional
Type *string `json:"type,omitempty"`

// IP to use when creating a Public Gateway.
// +kubebuilder:validation:Format=ipv4
// +optional
IP *string `json:"ip,omitempty"`

// Zone where to create the Public Gateway. Must be in the same region as the
// cluster. Defaults to the first zone of the region.
// +optional
Zone *string `json:"zone,omitempty"`
}

// ScalewayClusterStatus defines the observed state of ScalewayCluster.
Expand Down
119 changes: 119 additions & 0 deletions api/v1alpha1/scalewaymanagedcluster_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
package v1alpha1

import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
)

const ManagedClusterFinalizer = "scalewaycluster.infrastructure.cluster.x-k8s.io/smc-protection"

// ScalewayManagedClusterSpec defines the desired state of ScalewayManagedCluster
//
// +kubebuilder:validation:XValidation:rule="!has(oldSelf.controlPlaneEndpoint) || has(self.controlPlaneEndpoint)", message="controlPlaneEndpoint is required once set"
// +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"
type ScalewayManagedClusterSpec struct {
// Region where the managed cluster will be created.
// +kubebuilder:validation:XValidation:rule="self == oldSelf",message="Value is immutable"
// +kubebuilder:validation:MinLength:=2
Region string `json:"region"`

// ProjectID in which the managed cluster will be created.
// +kubebuilder:validation:XValidation:rule="self == oldSelf",message="Value is immutable"
// +kubebuilder:validation:MinLength:=2
ProjectID string `json:"projectID"`

// ScalewaySecretName is the name of the secret that contains the Scaleway client parameters.
// The following keys are required: SCW_ACCESS_KEY, SCW_SECRET_KEY.
// The following key is optional: SCW_API_URL.
// +kubebuilder:validation:MinLength:=1
ScalewaySecretName string `json:"scalewaySecretName"`

// Network defines the network configuration of the managed cluster.
// +optional
Network *ManagedNetworkSpec `json:"network,omitempty"`

// ControlPlaneEndpoint represents the endpoint used to communicate with the control plane.
// +kubebuilder:validation:XValidation:rule="self == oldSelf",message="Value is immutable"
// +optional
ControlPlaneEndpoint clusterv1.APIEndpoint `json:"controlPlaneEndpoint,omitempty,omitzero"`
}

// ManagedNetworkSpec defines the network configuration of a managed cluster.
type ManagedNetworkSpec struct {
// PrivateNetwork allows attaching machines of the cluster to a Private Network.
// +kubebuilder:validation:XValidation:rule="has(self.vpcID) == has(oldSelf.vpcID)",message="vpcID cannot be added or removed"
// +kubebuilder:validation:XValidation:rule="has(self.id) == has(oldSelf.id)",message="id cannot be added or removed"
// +kubebuilder:validation:XValidation:rule="has(self.subnet) == has(oldSelf.subnet)",message="subnet cannot be added or removed"
// +kubebuilder:validation:XValidation:rule="has(self.id) && !has(self.subnet) || !has(self.id)",message="subnet cannot be set when id is set"
// +kubebuilder:validation:XValidation:rule="has(self.id) && !has(self.vpcID) || !has(self.id)",message="vpcID cannot be set when id is set"
// +optional
PrivateNetwork *PrivateNetworkParams `json:"privateNetwork,omitempty"`

// PublicGateways allows to create Public Gateways that will be attached to the
// Private Network of the cluster.
// +kubebuilder:validation:MaxItems=6
// +optional
PublicGateways []PublicGatewaySpec `json:"publicGateways,omitempty"`
}

// ScalewayManagedClusterStatus defines the observed state of ScalewayManagedCluster.
type ScalewayManagedClusterStatus struct {
// Ready denotes that the Scaleway managed cluster infrastructure is fully provisioned.
// NOTE: this field is part of the Cluster API contract and it is used to orchestrate provisioning.
// The value of this field is never updated after provisioning is completed.
// +optional
Ready bool `json:"ready"`

// Network contains information about currently provisioned network resources.
// +optional
Network *ManagedNetworkStatus `json:"network,omitempty"`
}

// ManagedNetworkStatus contains information about currently provisioned network resources.
type ManagedNetworkStatus struct {
// PrivateNetworkID is the ID of the Private Network that is attached to the cluster.
// +optional
PrivateNetworkID *string `json:"privateNetworkID,omitempty"`
}

// +kubebuilder:object:root=true
// +kubebuilder:resource:path=scalewaymanagedclusters,scope=Namespaced,categories=cluster-api,shortName=smc
// +kubebuilder:subresource:status
// +kubebuilder:storageversion
// +kubebuilder:printcolumn:name="Cluster",type="string",JSONPath=".metadata.labels.cluster\\.x-k8s\\.io/cluster-name",description="Cluster to which this ScalewayManagedCluster belongs"
// +kubebuilder:printcolumn:name="Ready",type="boolean",JSONPath=".status.ready",description="Ready is true when the managed cluster is fully provisioned"
// +kubebuilder:printcolumn:name="Region",type="string",JSONPath=".spec.region",description="Region of the managed cluster"
// +kubebuilder:printcolumn:name="Host",type="string",JSONPath=".spec.controlPlaneEndpoint.host",description="Host of the control plane"
// +kubebuilder:printcolumn:name="Port",type="integer",JSONPath=".spec.controlPlaneEndpoint.port",description="Port of the control plane"

// ScalewayManagedCluster is the Schema for the scalewaymanagedclusters API
// +kubebuilder:validation:XValidation:rule="self.metadata.name.size() <= 63",message="name must be between 1 and 63 characters"
// +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"
type ScalewayManagedCluster struct {
metav1.TypeMeta `json:",inline"`

// metadata is a standard object metadata
// +optional
metav1.ObjectMeta `json:"metadata,omitempty,omitzero"`

// spec defines the desired state of ScalewayManagedCluster
// +required
Spec ScalewayManagedClusterSpec `json:"spec"`

// status defines the observed state of ScalewayManagedCluster
// +optional
Status ScalewayManagedClusterStatus `json:"status,omitempty,omitzero"`
}

// +kubebuilder:object:root=true

// ScalewayManagedClusterList contains a list of ScalewayManagedCluster
type ScalewayManagedClusterList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []ScalewayManagedCluster `json:"items"`
}

func init() {
SchemeBuilder.Register(&ScalewayManagedCluster{}, &ScalewayManagedClusterList{})
}
Loading