Skip to content

Commit 5effb78

Browse files
committed
test(fw): rely on capms firewall instead of manual one
1 parent e958cfd commit 5effb78

File tree

5 files changed

+8
-119
lines changed

5 files changed

+8
-119
lines changed

DEVELOPMENT.md

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ Next install our CAPMS provider into the cluster.
1818
make push-to-capi-lab
1919
```
2020

21-
Before creating a cluster some manual steps are required beforehand: you need to allocate a node network and a firewall.
21+
Before creating a cluster some manual steps are required beforehand: you need to allocate a node network.
2222

2323
```bash
24-
make -C capi-lab node-network firewall control-plane-ip
24+
make -C capi-lab node-network control-plane-ip
2525
```
2626

2727
A basic cluster configuration that relies on `config/clusterctl-templates/cluster-template.yaml` and uses the aforementioned node network can be generated and applied to the management cluster using a make target.
@@ -181,16 +181,14 @@ export WORKER_MACHINE_COUNT=1
181181
export repo_path=$HOME/path/to/cluster-api-provider-metal-stack
182182
export project_name=
183183
export tenant_name=
184-
export firewall_id=
185184
```
186185

187-
Create firewall if needed:
186+
Create project, node network and control plane ip if needed:
188187

189188
```bash
190189
metalctl project create --name $project_name --tenant $tenant_name --description "Cluster API test project"
191190
metalctl network allocate --description "Node network for $CLUSTER_NAME" --name $CLUSTER_NAME --project $METAL_PROJECT_ID --partition $METAL_PARTITION
192191
metalctl network ip create --network internet --project $METAL_PROJECT_ID --name "$CLUSTER_NAME-vip" --type static -o template --template "{{ .ipaddress }}"
193-
metalctl firewall create --description "Firewall for $CLUSTER_NAME cluster" --name firewall-$CLUSTER_NAME --hostname firewall-$CLUSTER_NAME --project $METAL_PROJECT_ID --partition $METAL_PARTITION --image $FIREWALL_MACHINE_IMAGE --size $FIREWALL_MACHINE_SIZE --firewall-rules-file $repo_path/config/target-cluster/firewall-rules.yaml --networks internet,$METAL_NODE_NETWORK_ID
194192
```
195193

196194
```bash
@@ -201,12 +199,6 @@ clusterctl init --infrastructure metal-stack --kubeconfig kind-bootstrap.kubecon
201199
clusterctl generate cluster $CLUSTER_NAME --infrastructure metal-stack > cluster-$CLUSTER_NAME.yaml
202200
kubectl apply -n $NAMESPACE -f cluster-$CLUSTER_NAME.yaml
203201

204-
# once the control plane node is in phoned home
205-
metalctl machine consolepassword $firewall_id
206-
metalctl machine console --ipmi $firewall_id
207-
# sudo systemctl restart frr
208-
# ~.
209-
210202
kubectl --kubeconfig kind-bootstrap.kubeconfig -n $NAMESPACE get metalstackmachines.infrastructure.cluster.x-k8s.io
211203
export control_plane_machine_id=
212204
metalctl machine console --ipmi $control_plane_machine_id

README.md

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ Currently, we provide the following custom resources:
1515
We plan to cover more resources in the future:
1616

1717
- Node Networks
18-
- Firewall Deployments
18+
- Complete Firewall Deployments using the [Firewall Controller Manager](https://github.com/metal-stack/firewall-controller-manager)
1919
- Improved configuration suggestion of CNIs
2020

2121
> [!note]
@@ -76,15 +76,6 @@ Allocate a VIP for the control plane.
7676
export CONTROL_PLANE_IP=$(metalctl network ip create --network internet --project $METAL_PROJECT_ID --name "$CLUSTER_NAME-vip" --type static -o template --template "{{ .ipaddress }}")
7777
```
7878

79-
A firewall needs to be created with appropriate firewall rules. An example can be found at [firewall-rules.yaml](config/target-cluster/firewall-rules.yaml).
80-
```bash
81-
# export environment variable for the firewall image and size
82-
export FIREWALL_MACHINE_IMAGE=<firewall-image>
83-
export FIREWALL_MACHINE_SIZE=<machine-size>
84-
85-
metalctl firewall create --description "Firewall for $CLUSTER_NAME" --name "$CLUSTER_NAME-fw" --hostname "$CLUSTER_NAME-fw" --project $METAL_PROJECT_ID --partition $METAL_PARTITION --image $FIREWALL_MACHINE_IMAGE --size $FIREWALL_MACHINE_SIZE --firewall-rules-file=<rules.yaml> --networks internet,$METAL_NODE_NETWORK_ID
86-
```
87-
8879
For your first cluster, it is advised to start with our generated template. Ensure that the namespaced cluster name is unique within the metal stack project.
8980

9081
```bash
@@ -96,6 +87,8 @@ export CONTROL_PLANE_MACHINE_IMAGE=<machine-image>
9687
export CONTROL_PLANE_MACHINE_SIZE=<machine-size>
9788
export WORKER_MACHINE_IMAGE=<machine-image>
9889
export WORKER_MACHINE_SIZE=<machine-size>
90+
export FIREWALL_MACHINE_IMAGE=<machine-image>
91+
export FIREWALL_MACHINE_SIZE=<machine-size>
9992

10093
# generate manifest
10194
clusterctl generate cluster $CLUSTER_NAME --kubernetes-version v1.32.9 --infrastructure metal-stack

capi-lab/Makefile

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,6 @@ controller:
5959
kubectl --kubeconfig=$(KUBECONFIG) patch deployments.apps -n cap-metal-stack metal-stack-controller-manager --patch='{"spec":{"template":{"spec":{"containers":[{"name": "manager","imagePullPolicy":"IfNotPresent","image":"$(IMG)"}]}}}}'
6060
kubectl --kubeconfig=$(KUBECONFIG) delete pod -n cap-metal-stack -l control-plane=metal-stack-controller-manager
6161

62-
.PHONY: firewall
63-
firewall:
64-
metalctl firewall create --description fw --name fw --hostname fw --project 00000000-0000-0000-0000-000000000001 --partition mini-lab --image firewall-ubuntu-3.0 --size v1-small-x86 --firewall-rules-file=firewall-rules.yaml --networks internet-mini-lab,$(shell metalctl network list --name $(CLUSTER_NAME) -o template --template '{{ .id }}')
65-
6662
.PHONY: node-network
6763
node-network:
6864
metalctl network allocate --description "node network for $(CLUSTER_NAME) cluster" --name $(CLUSTER_NAME) --project 00000000-0000-0000-0000-000000000001 --partition mini-lab

test/e2e/frmwrk/cluster_upgrade_kubernetes_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,8 +200,8 @@ func capi_e2e_ClusterUpgradeConformanceSpec(ctx context.Context, inputGetter fun
200200
Namespace: namespace.Name,
201201
ClusterName: clusterName,
202202
KubernetesVersion: input.E2EConfig.MustGetVariable(capi_e2e.KubernetesVersionUpgradeFrom),
203-
ControlPlaneMachineCount: ptr.To[int64](controlPlaneMachineCount),
204-
WorkerMachineCount: ptr.To[int64](workerMachineCount),
203+
ControlPlaneMachineCount: ptr.To(controlPlaneMachineCount),
204+
WorkerMachineCount: ptr.To(workerMachineCount),
205205
},
206206
ControlPlaneWaiters: input.ControlPlaneWaiters,
207207
WaitForClusterIntervals: input.E2EConfig.GetIntervals(specName, "wait-cluster"), WaitForControlPlaneIntervals: input.E2EConfig.GetIntervals(specName, "wait-control-plane"),

test/e2e/frmwrk/shared_cluster.go

Lines changed: 0 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,7 @@ import (
1212
. "github.com/onsi/ginkgo/v2" //nolint:staticcheck
1313
. "github.com/onsi/gomega" //nolint:staticcheck
1414

15-
metalfw "github.com/metal-stack/metal-go/api/client/firewall"
1615
metalip "github.com/metal-stack/metal-go/api/client/ip"
17-
metalmachine "github.com/metal-stack/metal-go/api/client/machine"
1816
metalnetwork "github.com/metal-stack/metal-go/api/client/network"
1917
metalmodels "github.com/metal-stack/metal-go/api/models"
2018

@@ -130,15 +128,13 @@ func (e2e *E2ECluster) teardownNamespace(ctx context.Context) {
130128
func (e2e *E2ECluster) SetupMetalStackPreconditions(ctx context.Context) {
131129
By("Setup Preconditions")
132130
e2e.setupNodeNetwork(ctx)
133-
e2e.setupFirewall(ctx)
134131
e2e.setupControlPlaneIP(ctx)
135132
}
136133

137134
func (e2e *E2ECluster) Teardown(ctx context.Context) {
138135
e2e.teardownAddons(ctx)
139136
e2e.teardownCluster(ctx)
140137
e2e.teardownControlPlaneIP(ctx)
141-
e2e.teardownFirewall(ctx)
142138
e2e.teardownNodeNetwork(ctx)
143139
e2e.teardownNamespace(ctx)
144140
}
@@ -173,94 +169,6 @@ func (e2e *E2ECluster) teardownNodeNetwork(ctx context.Context) {
173169
e2e.Refs.NodeNetwork = nil
174170
}
175171

176-
func (e2e *E2ECluster) setupFirewall(ctx context.Context) {
177-
By("Setup Firewall")
178-
179-
fcr := &metalmodels.V1FirewallCreateRequest{
180-
Name: e2e.ClusterName + "-fw",
181-
Hostname: e2e.ClusterName + "-fw",
182-
Description: "Firewall for " + e2e.ClusterName,
183-
Partitionid: &e2e.E2EContext.Environment.partition,
184-
Projectid: &e2e.E2EContext.Environment.projectID,
185-
Sizeid: &e2e.FirewallSize,
186-
Imageid: &e2e.FirewallImage,
187-
Tags: []string{
188-
fmt.Sprintf("%s=%s.%s", capmsv1alpha1.TagInfraClusterResource, e2e.NamespaceName, e2e.ClusterName),
189-
fmt.Sprintf("%s=%s", "e2e-test", e2e.SpecName),
190-
},
191-
Networks: []*metalmodels.V1MachineAllocationNetwork{
192-
{
193-
Networkid: ptr.To(e2e.E2EContext.Environment.publicNetwork),
194-
},
195-
{
196-
Networkid: e2e.Refs.NodeNetwork.ID,
197-
},
198-
},
199-
// At the moment we just go with vastly broad firewall rules.
200-
// In production this should be limited down.
201-
FirewallRules: &metalmodels.V1FirewallRules{
202-
Egress: []*metalmodels.V1FirewallEgressRule{
203-
{
204-
Comment: "allow outgoing HTTP and HTTPS traffic",
205-
Protocol: "TCP",
206-
Ports: []int32{80, 443},
207-
To: []string{"0.0.0.0/0"},
208-
},
209-
{
210-
Comment: "allow outgoing DNS traffic via TCP",
211-
Protocol: "TCP",
212-
Ports: []int32{53},
213-
To: []string{"0.0.0.0/0"},
214-
},
215-
{
216-
Comment: "allow outgoing traffic to control plane for ccm",
217-
Protocol: "TCP",
218-
Ports: []int32{8080},
219-
To: []string{"0.0.0.0/0"},
220-
},
221-
{
222-
Comment: "allow outgoing DNS and NTP traffic via UDP",
223-
Protocol: "UDP",
224-
Ports: []int32{53, 123},
225-
To: []string{"0.0.0.0/0"},
226-
},
227-
},
228-
Ingress: []*metalmodels.V1FirewallIngressRule{
229-
{
230-
Comment: "allow incoming HTTPS and HTTPS traffic",
231-
Protocol: "TCP",
232-
From: []string{"0.0.0.0/0"},
233-
To: []string{"0.0.0.0/0"},
234-
Ports: []int32{80, 443},
235-
},
236-
},
237-
},
238-
}
239-
240-
Eventually(func() error {
241-
fw, err := e2e.E2EContext.Environment.Metal.Firewall().AllocateFirewall(metalfw.NewAllocateFirewallParamsWithContext(ctx).WithBody(fcr), nil)
242-
if err != nil {
243-
return err
244-
}
245-
246-
e2e.Refs.Firewall = fw.Payload
247-
return nil
248-
}, e2e.E2EContext.E2EConfig.GetIntervals("metal-stack", "wait-firewall-allocate")...).ShouldNot(HaveOccurred(), "firewall not available")
249-
250-
GinkgoWriter.Printf("Firewall allocated with ID: %s\n", *e2e.Refs.Firewall.ID)
251-
}
252-
253-
func (e2e *E2ECluster) teardownFirewall(ctx context.Context) {
254-
if e2e.Refs.Firewall == nil || e2e.Refs.Firewall.ID == nil {
255-
return
256-
}
257-
258-
_, err := e2e.E2EContext.Environment.Metal.Machine().FreeMachine(metalmachine.NewFreeMachineParamsWithContext(ctx).WithID(*e2e.Refs.Firewall.ID), nil)
259-
Expect(err).ToNot(HaveOccurred(), "failed to free firewall machine")
260-
261-
e2e.Refs.Firewall = nil
262-
}
263-
264172
func (e2e *E2ECluster) setupControlPlaneIP(ctx context.Context) {
265173
if e2e.ControlPlaneIP != "" {
266174
return

0 commit comments

Comments
 (0)