Skip to content

Commit bbca74d

Browse files
committed
Move lb port definition from ScalewayCluster to Cluster
Signed-off-by: Damien DASSIEU <[email protected]>
1 parent 1caa5a2 commit bbca74d

File tree

8 files changed

+44
-56
lines changed

8 files changed

+44
-56
lines changed

api/v1alpha1/scalewaycluster_types.go

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ const ClusterFinalizer = "scalewaycluster.infrastructure.cluster.x-k8s.io/sc-pro
1515
// +kubebuilder:validation:XValidation:rule="(has(self.network) && has(self.network.controlPlanePrivateDNS)) == (has(oldSelf.network) && has(oldSelf.network.controlPlanePrivateDNS))",message="controlPlanePrivateDNS cannot be added or removed"
1616
// +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"
1717
//
18-
// +kubebuilder:validation:XValidation:rule="(has(self.network) && has(self.network.controlPlaneLoadBalancer) && has(self.network.controlPlaneLoadBalancer.port)) == (has(oldSelf.network) && has(oldSelf.network.controlPlaneLoadBalancer) && has(oldSelf.network.controlPlaneLoadBalancer.port))",message="port cannot be added or removed"
1918
// +kubebuilder:validation:XValidation:rule="(has(self.network) && has(self.network.controlPlaneLoadBalancer) && has(self.network.controlPlaneLoadBalancer.private)) == (has(oldSelf.network) && has(oldSelf.network.controlPlaneLoadBalancer) && has(oldSelf.network.controlPlaneLoadBalancer.private))",message="private cannot be added or removed"
2019
// +kubebuilder:validation:XValidation:rule="(has(self.network) && has(self.network.controlPlaneLoadBalancer) && has(self.network.controlPlaneLoadBalancer.ip)) == (has(oldSelf.network) && has(oldSelf.network.controlPlaneLoadBalancer) && has(oldSelf.network.controlPlaneLoadBalancer.ip))",message="ip cannot be added or removed"
2120
// +kubebuilder:validation:XValidation:rule="(has(self.network) && has(self.network.controlPlaneLoadBalancer) && has(self.network.controlPlaneLoadBalancer.zone)) == (has(oldSelf.network) && has(oldSelf.network.controlPlaneLoadBalancer) && has(oldSelf.network.controlPlaneLoadBalancer.zone))",message="zone cannot be added or removed"
@@ -127,12 +126,6 @@ type ControlPlaneLoadBalancerSpec struct {
127126
// +kubebuilder:validation:XValidation:rule="!has(oldSelf.privateIP) || self.privateIP == oldSelf.privateIP",message="privateIP is immutable"
128127
LoadBalancerSpec `json:",inline"`
129128

130-
// Port configured on the Load Balancer. It must be valid port range (1-65535).
131-
// +kubebuilder:validation:XValidation:rule="self == oldSelf",message="Value is immutable"
132-
// +kubebuilder:validation:Minimum=1
133-
// +kubebuilder:validation:Maximum=65535
134-
Port *int32 `json:"port,omitempty"`
135-
136129
// AllowedRanges allows to set a list of allowed IP ranges that can access
137130
// the cluster through the loadbalancer. When unset, all IP ranges are allowed.
138131
// To allow the cluster to work properly, public IPs of nodes and Public

api/v1alpha1/zz_generated.deepcopy.go

Lines changed: 0 additions & 5 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: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -170,16 +170,6 @@ spec:
170170
description: IP to use when creating a loadbalancer.
171171
format: ipv4
172172
type: string
173-
port:
174-
description: Port configured on the Load Balancer. It must
175-
be valid port range (1-65535).
176-
format: int32
177-
maximum: 65535
178-
minimum: 1
179-
type: integer
180-
x-kubernetes-validations:
181-
- message: Value is immutable
182-
rule: self == oldSelf
183173
private:
184174
description: Private disables the creation of a public IP
185175
on the LoadBalancers when it's set to true.
@@ -360,10 +350,6 @@ spec:
360350
- message: privateNetwork cannot be added or removed
361351
rule: (has(self.network) && has(self.network.privateNetwork)) == (has(oldSelf.network)
362352
&& has(oldSelf.network.privateNetwork))
363-
- message: port cannot be added or removed
364-
rule: (has(self.network) && has(self.network.controlPlaneLoadBalancer)
365-
&& has(self.network.controlPlaneLoadBalancer.port)) == (has(oldSelf.network)
366-
&& has(oldSelf.network.controlPlaneLoadBalancer) && has(oldSelf.network.controlPlaneLoadBalancer.port))
367353
- message: private cannot be added or removed
368354
rule: (has(self.network) && has(self.network.controlPlaneLoadBalancer)
369355
&& has(self.network.controlPlaneLoadBalancer.private)) == (has(oldSelf.network)

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

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -170,16 +170,6 @@ spec:
170170
description: IP to use when creating a loadbalancer.
171171
format: ipv4
172172
type: string
173-
port:
174-
description: Port configured on the Load Balancer.
175-
It must be valid port range (1-65535).
176-
format: int32
177-
maximum: 65535
178-
minimum: 1
179-
type: integer
180-
x-kubernetes-validations:
181-
- message: Value is immutable
182-
rule: self == oldSelf
183173
private:
184174
description: Private disables the creation of a public
185175
IP on the LoadBalancers when it's set to true.
@@ -362,10 +352,6 @@ spec:
362352
- message: privateNetwork cannot be added or removed
363353
rule: (has(self.network) && has(self.network.privateNetwork))
364354
== (has(oldSelf.network) && has(oldSelf.network.privateNetwork))
365-
- message: port cannot be added or removed
366-
rule: (has(self.network) && has(self.network.controlPlaneLoadBalancer)
367-
&& has(self.network.controlPlaneLoadBalancer.port)) == (has(oldSelf.network)
368-
&& has(oldSelf.network.controlPlaneLoadBalancer) && has(oldSelf.network.controlPlaneLoadBalancer.port))
369355
- message: private cannot be added or removed
370356
rule: (has(self.network) && has(self.network.controlPlaneLoadBalancer)
371357
&& has(self.network.controlPlaneLoadBalancer.private)) ==

docs/scalewaycluster.md

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,6 @@ spec:
168168
network:
169169
controlPlaneLoadBalancer:
170170
type: LB-S
171-
port: 443
172171
zone: fr-par-1
173172
ip: 42.42.42.42 # optional
174173
# private: true
@@ -177,8 +176,6 @@ spec:
177176
```
178177

179178
- The `type` field can be updated to migrate the Load Balancer to another type.
180-
- The `port` field specifies the port of the Load Balancer frontend that exposes the kube-apiserver(s).
181-
This field is immutable.
182179
- The `zone` field specifies where the Load Balancer will be created. Must be in the same region
183180
as the `ScalewayCluster` region. This defaults to the first availability zone of the region.
184181
This field is immutable.
@@ -192,6 +189,26 @@ spec:
192189
> When `private` is set to `true`, make sure your management cluster has network access
193190
> to the Private Network where the workload cluster will be created.
194191

192+
The main Load Balancer's port can be set at the cluster creation in the `Cluster` object.
193+
194+
Here is an example of the main Load Balancer port configuration:
195+
196+
```yaml
197+
apiVersion: cluster.x-k8s.io/v1beta1
198+
kind: Cluster
199+
metadata:
200+
name: my-cluster
201+
namespace: default
202+
spec:
203+
...
204+
clusterNetwork:
205+
apiServerPort: 443
206+
...
207+
```
208+
209+
- The `apiServerPort` field specifies the port of the Load Balancer frontend that exposes the kube-apiserver(s).
210+
This field is immutable.
211+
195212
#### Extra Load Balancers
196213

197214
To specify extra Load Balancers, it is required to also set the `network.controlPlaneDNS`

internal/scope/cluster.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -129,10 +129,9 @@ func (c *Cluster) PrivateNetworkID() (string, error) {
129129
func (c *Cluster) ControlPlaneLoadBalancerPort() int32 {
130130
var port int32 = defaultFrontendControlPlanePort
131131

132-
if c.ScalewayCluster.Spec.Network != nil &&
133-
c.ScalewayCluster.Spec.Network.ControlPlaneLoadBalancer != nil &&
134-
c.ScalewayCluster.Spec.Network.ControlPlaneLoadBalancer.Port != nil {
135-
port = *c.ScalewayCluster.Spec.Network.ControlPlaneLoadBalancer.Port
132+
if c.Cluster.Spec.ClusterNetwork != nil &&
133+
c.Cluster.Spec.ClusterNetwork.APIServerPort != nil {
134+
port = *c.Cluster.Spec.ClusterNetwork.APIServerPort
136135
}
137136

138137
return port

internal/scope/cluster_test.go

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
scwClient "github.com/scaleway/cluster-api-provider-scaleway/internal/service/scaleway/client"
1010
"github.com/scaleway/scaleway-sdk-go/scw"
1111
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
12+
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
1213
"sigs.k8s.io/cluster-api/util/patch"
1314
)
1415

@@ -311,7 +312,7 @@ func TestCluster_PrivateNetworkID(t *testing.T) {
311312
func TestCluster_ControlPlaneLoadBalancerPort(t *testing.T) {
312313
t.Parallel()
313314
type fields struct {
314-
ScalewayCluster *infrav1.ScalewayCluster
315+
Cluster *clusterv1.Cluster
315316
}
316317
tests := []struct {
317318
name string
@@ -321,19 +322,17 @@ func TestCluster_ControlPlaneLoadBalancerPort(t *testing.T) {
321322
{
322323
name: "empty spec",
323324
fields: fields{
324-
ScalewayCluster: &infrav1.ScalewayCluster{},
325+
Cluster: &clusterv1.Cluster{},
325326
},
326327
want: defaultFrontendControlPlanePort,
327328
},
328329
{
329330
name: "override with 443",
330331
fields: fields{
331-
ScalewayCluster: &infrav1.ScalewayCluster{
332-
Spec: infrav1.ScalewayClusterSpec{
333-
Network: &infrav1.NetworkSpec{
334-
ControlPlaneLoadBalancer: &infrav1.ControlPlaneLoadBalancerSpec{
335-
Port: scw.Int32Ptr(443),
336-
},
332+
Cluster: &clusterv1.Cluster{
333+
Spec: clusterv1.ClusterSpec{
334+
ClusterNetwork: &clusterv1.ClusterNetwork{
335+
APIServerPort: scw.Int32Ptr(443),
337336
},
338337
},
339338
},
@@ -345,7 +344,7 @@ func TestCluster_ControlPlaneLoadBalancerPort(t *testing.T) {
345344
t.Run(tt.name, func(t *testing.T) {
346345
t.Parallel()
347346
c := &Cluster{
348-
ScalewayCluster: tt.fields.ScalewayCluster,
347+
Cluster: tt.fields.Cluster,
349348
}
350349
if got := c.ControlPlaneLoadBalancerPort(); got != tt.want {
351350
t.Errorf("Cluster.ControlPlaneLoadBalancerPort() = %v, want %v", got, tt.want)

internal/service/scaleway/lb/lb_test.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import (
1717
"github.com/scaleway/scaleway-sdk-go/scw"
1818
"go.uber.org/mock/gomock"
1919
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
20+
"sigs.k8s.io/cluster-api/api/v1beta1"
2021
)
2122

2223
const (
@@ -69,6 +70,12 @@ func TestService_Reconcile(t *testing.T) {
6970
Namespace: "default",
7071
},
7172
},
73+
Cluster: &v1beta1.Cluster{
74+
ObjectMeta: v1.ObjectMeta{
75+
Name: "cluster",
76+
Namespace: "default",
77+
},
78+
},
7279
},
7380
},
7481
args: args{
@@ -151,6 +158,12 @@ func TestService_Reconcile(t *testing.T) {
151158
},
152159
},
153160
},
161+
Cluster: &v1beta1.Cluster{
162+
ObjectMeta: v1.ObjectMeta{
163+
Name: "cluster",
164+
Namespace: "default",
165+
},
166+
},
154167
},
155168
},
156169
args: args{

0 commit comments

Comments
 (0)