Skip to content
This repository was archived by the owner on Jun 13, 2025. It is now read-only.

Commit 93faaba

Browse files
committed
Implement regional VPC and Public Gateway
1 parent 2f87fdf commit 93faaba

17 files changed

+589
-121
lines changed

api/v1beta1/scalewaycluster_types.go

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,51 @@ type ScalewayClusterSpec struct {
2828
}
2929

3030
type NetworkSpec struct {
31+
// PrivateNetwork allows attaching machines of the cluster to a Private
32+
// Network.
3133
// +optional
3234
PrivateNetwork *PrivateNetworkSpec `json:"privateNetwork,omitempty"`
35+
36+
// Use this field to create or use an existing Public Gateway and attach
37+
// it to the Private Network. Do not set this field if the Private Network
38+
// already has an attached Public Gateway.
39+
// +optional
40+
PublicGateway *PublicGatewaySpec `json:"publicGateway,omitempty"`
3341
}
3442

3543
type PrivateNetworkSpec struct {
44+
// Set to true to automatically attach machines to a Private Network.
45+
// The Private Network is automatically created if no existing Private
46+
// Network ID is provided.
3647
Enabled bool `json:"enabled"`
37-
// Set the ID to reuse an existing PrivateNetwork.
48+
// Set a Private Network ID to reuse an existing Private Network. This
49+
// Private Network must have DHCP enabled.
50+
// +optional
51+
ID *string `json:"id,omitempty"`
52+
// Optional subnet for the Private Network. Only used on newly created
53+
// Private Networks.
3854
// +optional
55+
Subnet *string `json:"subnet,omitempty"`
56+
}
57+
58+
type PublicGatewaySpec struct {
59+
// Set to true to attach a Public Gateway to the Private Network.
60+
// The Public Gateway is automatically created if no existing Public Gateway
61+
// ID is provided.
62+
Enabled bool `json:"enabled"`
63+
// ID of an existing Public Gateway that will be attached to the Private
64+
// Network. You should also specify the zone field.
3965
ID *string `json:"id,omitempty"`
66+
// Public Gateway commercial offer type.
67+
// +kubebuilder:default="VPC-GW-S"
68+
// +optional
69+
Type string `json:"type,omitempty"`
70+
// ID of an existing IP.
71+
IPID *string `json:"ipID,omitempty"`
72+
// Zone where to create the Public Gateway. Must be in the same region as the
73+
// cluster. Defaults to the first zone of the region.
74+
// +optional
75+
Zone *string `json:"zone,omitempty"`
4076
}
4177

4278
type LoadBalancerSpec struct {
@@ -55,6 +91,14 @@ type ScalewayClusterStatus struct {
5591
// +kubebuilder:default=false
5692
Ready bool `json:"ready"`
5793
FailureDomains clusterv1beta1.FailureDomains `json:"failureDomains,omitempty"`
94+
95+
// +optional
96+
Network *NetworkStatus `json:"network,omitempty"`
97+
}
98+
99+
type NetworkStatus struct {
100+
PrivateNetworkID *string `json:"privateNetworkID,omitempty"`
101+
PublicGatewayID *string `json:"publicGatewayID,omitempty"`
58102
}
59103

60104
//+kubebuilder:object:root=true

api/v1beta1/scalewaymachine_types.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ type ScalewayMachineSpec struct {
1818
RootVolumeSize *int64 `json:"rootVolumeSize,omitempty"`
1919
// +optional
2020
PublicIP *bool `json:"publicIP,omitempty"`
21+
// VolumeType ?
2122
}
2223

2324
// ScalewayMachineStatus defines the observed state of ScalewayMachine

api/v1beta1/zz_generated.deepcopy.go

Lines changed: 70 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config/crd/bases/infrastructure.cluster.x-k8s.io_scalewayclusters.yaml

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,52 @@ spec:
6868
network:
6969
properties:
7070
privateNetwork:
71+
description: PrivateNetwork allows attaching machines of the cluster
72+
to a Private Network.
7173
properties:
7274
enabled:
75+
description: Set to true to automatically attach machines
76+
to a Private Network. The Private Network is automatically
77+
created if no existing Private Network ID is provided.
7378
type: boolean
7479
id:
75-
description: Set the ID to reuse an existing PrivateNetwork.
80+
description: Set a Private Network ID to reuse an existing
81+
Private Network. This Private Network must have DHCP enabled.
82+
type: string
83+
subnet:
84+
description: Optional subnet for the Private Network. Only
85+
used on newly created Private Networks.
86+
type: string
87+
required:
88+
- enabled
89+
type: object
90+
publicGateway:
91+
description: Use this field to create or use an existing Public
92+
Gateway and attach it to the Private Network. Do not set this
93+
field if the Private Network already has an attached Public
94+
Gateway.
95+
properties:
96+
enabled:
97+
description: Set to true to attach a Public Gateway to the
98+
Private Network. The Public Gateway is automatically created
99+
if no existing Public Gateway ID is provided.
100+
type: boolean
101+
id:
102+
description: ID of an existing Public Gateway that will be
103+
attached to the Private Network. You should also specify
104+
the zone field.
105+
type: string
106+
ipID:
107+
description: ID of an existing IP.
108+
type: string
109+
type:
110+
default: VPC-GW-S
111+
description: Public Gateway commercial offer type.
112+
type: string
113+
zone:
114+
description: Zone where to create the Public Gateway. Must
115+
be in the same region as the cluster. Defaults to the first
116+
zone of the region.
76117
type: string
77118
required:
78119
- enabled
@@ -108,6 +149,13 @@ spec:
108149
type: object
109150
description: FailureDomains is a slice of FailureDomains.
110151
type: object
152+
network:
153+
properties:
154+
privateNetworkID:
155+
type: string
156+
publicGatewayID:
157+
type: string
158+
type: object
111159
ready:
112160
default: false
113161
type: boolean

config/crd/bases/infrastructure.cluster.x-k8s.io_scalewayclustertemplates.yaml

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,11 +82,53 @@ spec:
8282
network:
8383
properties:
8484
privateNetwork:
85+
description: PrivateNetwork allows attaching machines
86+
of the cluster to a Private Network.
8587
properties:
8688
enabled:
89+
description: Set to true to automatically attach machines
90+
to a Private Network. The Private Network is automatically
91+
created if no existing Private Network ID is provided.
8792
type: boolean
8893
id:
89-
description: Set the ID to reuse an existing PrivateNetwork.
94+
description: Set a Private Network ID to reuse an
95+
existing Private Network. This Private Network must
96+
have DHCP enabled.
97+
type: string
98+
subnet:
99+
description: Optional subnet for the Private Network.
100+
Only used on newly created Private Networks.
101+
type: string
102+
required:
103+
- enabled
104+
type: object
105+
publicGateway:
106+
description: Use this field to create or use an existing
107+
Public Gateway and attach it to the Private Network.
108+
Do not set this field if the Private Network already
109+
has an attached Public Gateway.
110+
properties:
111+
enabled:
112+
description: Set to true to attach a Public Gateway
113+
to the Private Network. The Public Gateway is automatically
114+
created if no existing Public Gateway ID is provided.
115+
type: boolean
116+
id:
117+
description: ID of an existing Public Gateway that
118+
will be attached to the Private Network. You should
119+
also specify the zone field.
120+
type: string
121+
ipID:
122+
description: ID of an existing IP.
123+
type: string
124+
type:
125+
default: VPC-GW-S
126+
description: Public Gateway commercial offer type.
127+
type: string
128+
zone:
129+
description: Zone where to create the Public Gateway.
130+
Must be in the same region as the cluster. Defaults
131+
to the first zone of the region.
90132
type: string
91133
required:
92134
- enabled

controllers/scalewaycluster_controller.go

Lines changed: 6 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,9 @@ import (
99
scwClient "github.com/Tomy2e/cluster-api-provider-scaleway/pkg/service/scaleway/client"
1010
"github.com/Tomy2e/cluster-api-provider-scaleway/pkg/service/scaleway/vpc"
1111
"github.com/Tomy2e/cluster-api-provider-scaleway/pkg/service/scaleway/vpcgw"
12-
"github.com/scaleway/scaleway-sdk-go/scw"
1312
apierrors "k8s.io/apimachinery/pkg/api/errors"
1413
"k8s.io/apimachinery/pkg/runtime"
1514
"k8s.io/klog/v2"
16-
"sigs.k8s.io/cluster-api/api/v1beta1"
1715
"sigs.k8s.io/cluster-api/util"
1816
"sigs.k8s.io/cluster-api/util/annotations"
1917
ctrl "sigs.k8s.io/controller-runtime"
@@ -108,45 +106,23 @@ func (r *ScalewayClusterReconciler) reconcileNormal(ctx context.Context, cluster
108106
}
109107
}
110108

111-
zones := clusterScope.Region().GetZones()
112-
113-
if len(zones) == 0 {
114-
zones = append(zones, scw.Zone(fmt.Sprintf("%s-1", clusterScope.Region())))
115-
}
116-
117-
failureDomains := make(v1beta1.FailureDomains, len(zones))
118-
for _, zone := range zones {
119-
if len(clusterScope.ScalewayCluster.Spec.FailureDomains) > 0 {
120-
for _, fd := range clusterScope.ScalewayCluster.Spec.FailureDomains {
121-
if fd == zone.String() {
122-
failureDomains[zone.String()] = v1beta1.FailureDomainSpec{
123-
ControlPlane: true,
124-
}
125-
}
126-
}
127-
} else {
128-
failureDomains[zone.String()] = v1beta1.FailureDomainSpec{
129-
ControlPlane: true,
130-
}
131-
}
132-
}
133-
134-
clusterScope.ScalewayCluster.Status.FailureDomains = failureDomains
109+
clusterScope.ScalewayCluster.Status.FailureDomains = clusterScope.FailureDomains()
135110

136111
if err := vpc.NewService(clusterScope).Reconcile(ctx); err != nil {
137-
return ctrl.Result{}, err
112+
return ctrl.Result{}, fmt.Errorf("failed to reconcile vpc: %w", err)
138113
}
139114

115+
// TODO: maybe wait for the gateway to be ready?
140116
if err := vpcgw.NewService(clusterScope).Reconcile(ctx); err != nil {
141-
return ctrl.Result{}, err
117+
return ctrl.Result{}, fmt.Errorf("failed to reconcile vpcgw: %w", err)
142118
}
143119

144120
if err := loadbalancer.NewService(clusterScope).Reconcile(ctx); err != nil {
145121
if errors.Is(err, loadbalancer.ErrLoadBalancerNotReady) {
146122
log.Info("loadbalancer is not ready yet, retrying")
147123
return ctrl.Result{RequeueAfter: 2 * time.Second}, nil
148124
}
149-
return ctrl.Result{}, err
125+
return ctrl.Result{}, fmt.Errorf("failed to reconcile loadbalancer: %w", err)
150126
}
151127

152128
clusterScope.ScalewayCluster.Status.Ready = true
@@ -157,7 +133,7 @@ func (r *ScalewayClusterReconciler) reconcileNormal(ctx context.Context, cluster
157133
func (r *ScalewayClusterReconciler) reconcileDelete(ctx context.Context, clusterScope *scope.Cluster) (ctrl.Result, error) {
158134
log := k8slog.FromContext(ctx)
159135

160-
log.Info("deleting ScalewayCluster")
136+
log.Info("Deleting cluster")
161137

162138
if err := loadbalancer.NewService(clusterScope).Delete(ctx); err != nil {
163139
return ctrl.Result{}, err

controllers/scalewaymachine_controller.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ func (r *ScalewayMachineReconciler) Reconcile(ctx context.Context, req ctrl.Requ
4545
}
4646

4747
log = log.WithValues("ScalewayMachine", klog.KObj(scalewayMachine))
48+
log.Info("Starting reconciling machine")
4849

4950
machine, err := util.GetOwnerMachine(ctx, r.Client, scalewayMachine.ObjectMeta)
5051
if err != nil {
@@ -147,6 +148,8 @@ func (r *ScalewayMachineReconciler) reconcileNormal(ctx context.Context, machine
147148

148149
machineScope.ScalewayMachine.Status.Ready = true
149150

151+
log.Info("Reconciled machine successfully")
152+
150153
return ctrl.Result{}, nil
151154
}
152155

0 commit comments

Comments
 (0)