Skip to content

Commit b23f0ee

Browse files
committed
Add e2e test for custom LB port
Signed-off-by: Damien DASSIEU <[email protected]>
1 parent bbca74d commit b23f0ee

File tree

4 files changed

+115
-20
lines changed

4 files changed

+115
-20
lines changed

docs/scalewaycluster.md

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,28 @@ For more information about private DNS, please refer to the [Understanding Scale
151151
When creating a `ScalewayCluster`, a "main" Load Balancer is always created.
152152
It is also possible to specify "extra" Load Balancers to achieve regional redundancy.
153153

154+
#### Front API server port
155+
156+
The kube-apiserver Load Balancer's front port can be set at the cluster creation in the `Cluster` object.
157+
158+
Here is an example of the main Load Balancer port configuration:
159+
160+
```yaml
161+
apiVersion: cluster.x-k8s.io/v1beta1
162+
kind: Cluster
163+
metadata:
164+
name: my-cluster
165+
namespace: default
166+
spec:
167+
...
168+
clusterNetwork:
169+
apiServerPort: 443
170+
...
171+
```
172+
173+
- The `apiServerPort` field specifies the port of the Load Balancer frontend that exposes the kube-apiserver(s).
174+
This field should not be changed after the creation of the cluster.
175+
154176
#### Main Load Balancer
155177

156178
The main Load Balancer is always created by default, it is not possible to disable it.
@@ -189,26 +211,6 @@ spec:
189211
> When `private` is set to `true`, make sure your management cluster has network access
190212
> to the Private Network where the workload cluster will be created.
191213

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-
212214
#### Extra Load Balancers
213215

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

internal/service/scaleway/lb/lb_test.go

Lines changed: 74 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+
"k8s.io/utils/ptr"
2021
"sigs.k8s.io/cluster-api/api/v1beta1"
2122
)
2223

@@ -128,6 +129,79 @@ func TestService_Reconcile(t *testing.T) {
128129
g.Expect(c.ScalewayCluster.Status.Network.LoadBalancerIP).To(Equal(scw.StringPtr("42.42.42.42")))
129130
},
130131
},
132+
{
133+
name: "custom public LB, no extra LB, no Private Network, no ACL: create",
134+
fields: fields{
135+
Cluster: &scope.Cluster{
136+
ScalewayCluster: &v1alpha1.ScalewayCluster{
137+
ObjectMeta: v1.ObjectMeta{
138+
Name: "cluster",
139+
Namespace: "default",
140+
},
141+
},
142+
Cluster: &v1beta1.Cluster{
143+
ObjectMeta: v1.ObjectMeta{
144+
Name: "cluster",
145+
Namespace: "default",
146+
},
147+
Spec: v1beta1.ClusterSpec{
148+
ClusterNetwork: &v1beta1.ClusterNetwork{
149+
APIServerPort: ptr.To(int32(4242)),
150+
},
151+
},
152+
},
153+
},
154+
},
155+
args: args{
156+
ctx: context.TODO(),
157+
},
158+
expect: func(i *mock_client.MockInterfaceMockRecorder) {
159+
tags := []string{"caps-namespace=default", "caps-scalewaycluster=cluster"}
160+
161+
// Main LB
162+
i.GetZoneOrDefault(nil).Return(scw.ZoneFrPar1, nil)
163+
i.FindLB(gomock.Any(), scw.ZoneFrPar1, append(tags, CAPSMainLBTag)).Return(nil, client.ErrNoItemFound)
164+
i.CreateLB(gomock.Any(), scw.ZoneFrPar1, "cluster", "LB-S", nil, false, append(tags, CAPSMainLBTag)).Return(&lb.LB{
165+
ID: lbID,
166+
Name: "cluster",
167+
Status: lb.LBStatusReady,
168+
Zone: scw.ZoneFrPar1,
169+
IP: []*lb.IP{{IPAddress: "42.42.42.42"}},
170+
}, nil)
171+
172+
// Extra LBs
173+
i.FindLBs(gomock.Any(), append(tags, CAPSExtraLBTag)).Return([]*lb.LB{}, nil)
174+
175+
// Backend
176+
i.FindBackend(gomock.Any(), scw.ZoneFrPar1, lbID, BackendName).Return(nil, client.ErrNoItemFound)
177+
i.CreateBackend(gomock.Any(), scw.ZoneFrPar1, lbID, BackendName, nil, backendControlPlanePort).Return(&lb.Backend{
178+
ID: backendID,
179+
LB: &lb.LB{
180+
ID: lbID,
181+
Zone: scw.ZoneFrPar1,
182+
},
183+
}, nil)
184+
185+
// Frontend
186+
i.FindFrontend(gomock.Any(), scw.ZoneFrPar1, lbID, FrontendName).Return(nil, client.ErrNoItemFound)
187+
i.CreateFrontend(gomock.Any(), scw.ZoneFrPar1, lbID, FrontendName, backendID, int32(4242)).Return(&lb.Frontend{
188+
ID: frontendID,
189+
LB: &lb.LB{
190+
ID: lbID,
191+
Zone: scw.ZoneFrPar1,
192+
},
193+
}, nil)
194+
195+
// ACL
196+
i.FindLBACLByName(gomock.Any(), scw.ZoneFrPar1, frontendID, allowedRangesACLName).Return(nil, client.ErrNoItemFound)
197+
i.FindLBACLByName(gomock.Any(), scw.ZoneFrPar1, frontendID, publicGatewayACLName).Return(nil, client.ErrNoItemFound)
198+
i.FindLBACLByName(gomock.Any(), scw.ZoneFrPar1, frontendID, denyAllACLName).Return(nil, client.ErrNoItemFound)
199+
},
200+
asserts: func(g *WithT, c *scope.Cluster) {
201+
g.Expect(c.ScalewayCluster.Status.Network).ToNot(BeNil())
202+
g.Expect(c.ScalewayCluster.Status.Network.LoadBalancerIP).To(Equal(scw.StringPtr("42.42.42.42")))
203+
},
204+
},
131205
{
132206
name: "public LB, extra LBs, Private Network, ACL: up-to-date",
133207
fields: fields{

templates/cluster-template-private-network.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ metadata:
44
name: ${CLUSTER_NAME}
55
spec:
66
clusterNetwork:
7+
apiServerPort: ${API_SERVER_PORT:=null}
78
pods:
89
cidrBlocks:
910
- 10.244.0.0/16

test/e2e/scaleway_test.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,4 +54,22 @@ var _ = Describe("Workload cluster creation", func() {
5454
}
5555
})
5656
})
57+
58+
Context("Running the CAPSClusterDeploymentSpec with front api custom port", func() {
59+
CAPSClusterDeploymentSpec(func() CAPSClusterDeploymentSpecInput {
60+
return CAPSClusterDeploymentSpecInput{
61+
E2EConfig: e2eConfig,
62+
ClusterctlConfigPath: clusterctlConfigPath,
63+
BootstrapClusterProxy: bootstrapClusterProxy,
64+
ArtifactFolder: artifactFolder,
65+
SkipCleanup: skipCleanup,
66+
ControlPlaneMachineCount: 3,
67+
WorkerMachineCount: 2,
68+
Flavor: "",
69+
ClusterctlVariables: map[string]string{
70+
"API_SERVER_PORT": "443",
71+
},
72+
}
73+
})
74+
})
5775
})

0 commit comments

Comments
 (0)