Skip to content

Commit f0a1815

Browse files
committed
feat(cluster): optional node network
1 parent 637a407 commit f0a1815

19 files changed

+140
-108
lines changed

DEVELOPMENT.md

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@ 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.
21+
Before creating a cluster the control plane IP needs to be created first:
2222

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

27-
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.
27+
A basic cluster configuration that relies on `config/clusterctl-templates/cluster-template-calico.yaml` and uses the aforementioned IP can be generated and applied to the management cluster using a make target.
2828

2929
```bash
3030
make -C capi-lab apply-sample-cluster
@@ -159,7 +159,6 @@ export METAL_API_URL=
159159

160160
export METAL_PARTITION=
161161
export METAL_PROJECT_ID=
162-
export METAL_NODE_NETWORK_ID=
163162
export CONTROL_PLANE_IP=
164163

165164
export FIREWALL_MACHINE_IMAGE=
@@ -183,11 +182,10 @@ export project_name=
183182
export tenant_name=
184183
```
185184

186-
Create project, node network and control plane ip if needed:
185+
Create project and control plane ip if needed:
187186

188187
```bash
189188
metalctl project create --name $project_name --tenant $tenant_name --description "Cluster API test project"
190-
metalctl network allocate --description "Node network for $CLUSTER_NAME" --name $CLUSTER_NAME --project $METAL_PROJECT_ID --partition $METAL_PARTITION
191189
metalctl network ip create --network internet --project $METAL_PROJECT_ID --name "$CLUSTER_NAME-vip" --type static -o template --template "{{ .ipaddress }}"
192190
```
193191

README.md

Lines changed: 5 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ Currently, we provide the following custom resources:
1717

1818
We plan to cover more resources in the future:
1919

20-
- Node Networks
2120
- Complete Firewall Deployments using the [Firewall Controller Manager](https://github.com/metal-stack/firewall-controller-manager)
2221
- Improved configuration suggestion of CNIs
2322

@@ -62,28 +61,21 @@ clusterctl init --infrastructure metal-stack
6261
> **Manual steps needed:**
6362
> Due to the early development stage, manual actions are needed for the cluster to operate. Some metal-stack resources need to be created manually.
6463
65-
A node network needs to be created.
64+
Allocate a VIP for the control plane.
65+
6666
```bash
6767
export CLUSTER_NAME=<cluster-name>
6868
export METAL_PARTITION=<partition>
6969
export METAL_PROJECT_ID=<project-id>
70-
metalctl network allocate --description "Node network for $CLUSTER_NAME" --name $CLUSTER_NAME --project $METAL_PROJECT_ID --partition $METAL_PARTITION
7170

72-
# export environment variable for use in the next steps
73-
export METAL_NODE_NETWORK_ID=$(metalctl network list --name $CLUSTER_NAME -o template --template '{{ .id }}')
74-
```
75-
76-
Allocate a VIP for the control plane.
77-
78-
```bash
7971
export CONTROL_PLANE_IP=$(metalctl network ip create --network internet --project $METAL_PROJECT_ID --name "$CLUSTER_NAME-vip" --type static -o template --template "{{ .ipaddress }}")
8072
```
8173

8274
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.
8375

8476
```bash
8577
# display required environment variables
86-
clusterctl generate cluster $CLUSTER_NAME --infrastructure metal-stack --list-variables
78+
clusterctl generate cluster $CLUSTER_NAME --infrastructure metal-stack --list-variables --flavor calico
8779

8880
# set additional environment variables
8981
export CONTROL_PLANE_MACHINE_IMAGE=<machine-image>
@@ -94,7 +86,7 @@ export FIREWALL_MACHINE_IMAGE=<machine-image>
9486
export FIREWALL_MACHINE_SIZE=<machine-size>
9587

9688
# generate manifest
97-
clusterctl generate cluster $CLUSTER_NAME --kubernetes-version v1.32.9 --infrastructure metal-stack
89+
clusterctl generate cluster $CLUSTER_NAME --kubernetes-version v1.32.9 --infrastructure metal-stack --flavor calico
9890
```
9991

10092
Apply the generated manifest from the `clusterctl` output.
@@ -103,51 +95,7 @@ Apply the generated manifest from the `clusterctl` output.
10395
kubectl apply -f <manifest>
10496
```
10597

106-
Once your control plane and worker machines have been provisioned, you need to install your CNI of choice into your created cluster. This is required due to CAPI. An example is provided below:
107-
108-
```bash
109-
# get the kubeconfig
110-
clusterctl get kubeconfig metal-test > capms-cluster.kubeconfig
111-
112-
# install the calico operator
113-
kubectl --kubeconfig=capms-cluster.kubeconfig create -f https://raw.githubusercontent.com/projectcalico/calico/v3.28.2/manifests/tigera-operator.yaml
114-
115-
# install the calico CNI
116-
cat <<EOF | kubectl --kubeconfig=capms-cluster.kubeconfig create -f -
117-
apiVersion: operator.tigera.io/v1
118-
kind: Installation
119-
metadata:
120-
name: default
121-
spec:
122-
# Configures Calico networking.
123-
calicoNetwork:
124-
bgp: Disabled
125-
ipPools:
126-
- name: default-ipv4-ippool
127-
blockSize: 26
128-
cidr: 10.240.0.0/12
129-
encapsulation: None
130-
mtu: 1440
131-
cni:
132-
ipam:
133-
type: HostLocal
134-
type: Calico
135-
EOF
136-
```
137-
138-
Meanwhile, the `metal-ccm` has to be deployed for the machines to reach `Running` phase. For this use the [`config/target-cluster/metal-ccm.yaml` template](config/target-cluster/metal-ccm.yaml) and fill in the required variables.
139-
140-
```bash
141-
export NAMESPACE=<namespace>
142-
export CLUSTER_NAME=<cluster name>
143-
cat config/target-cluster/metal-ccm.yaml | envsubst | kubectl --kubeconfig capms-cluster.kubeconfig apply -f -
144-
```
145-
146-
If you want to provide service's of type `LoadBalancer` through MetalLB by the `metal-ccm`, you need to deploy MetalLB:
147-
148-
```bash
149-
kubectl --kubeconfig capms-cluster.kubeconfig apply --kustomize capi-lab/metallb
150-
```
98+
That's it!
15199

152100
## Frequently Asked Questions
153101

api/v1alpha1/metalstackcluster_types.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ const (
3737
ClusterControlPlaneEndpointDefaultPort = 443
3838

3939
ClusterPaused clusterv1.ConditionType = clusterv1.PausedV1Beta2Condition
40+
ClusterNodeNetworkEnsured clusterv1.ConditionType = "ClusterNodeNetworkEnsured"
4041
ClusterControlPlaneIPEnsured clusterv1.ConditionType = "ClusterControlPlaneIPEnsured"
4142
)
4243

@@ -57,7 +58,9 @@ type MetalStackClusterSpec struct {
5758
ProjectID string `json:"projectID"`
5859

5960
// NodeNetworkID is the network ID in metal-stack in which the worker nodes and the firewall of the cluster are placed.
60-
NodeNetworkID string `json:"nodeNetworkID"`
61+
// If not provided this will automatically be acquired during reconcile.
62+
// +optional
63+
NodeNetworkID *string `json:"nodeNetworkID,omitempty"`
6164

6265
// ControlPlaneIP is the ip address in metal-stack on which the control plane will be exposed.
6366
// If this ip and the control plane endpoint are not provided, an ephemeral ip will automatically be acquired during reconcile.
@@ -153,6 +156,6 @@ func (c *MetalStackCluster) SetConditions(conditions clusterv1.Conditions) {
153156
c.Status.Conditions = conditions
154157
}
155158

156-
func (c *MetalStackCluster) GetClusterID() string {
159+
func (c *MetalStackCluster) GetClusterName() string {
157160
return fmt.Sprintf("%s.%s", c.GetNamespace(), c.GetName())
158161
}

api/v1alpha1/metalstackcluster_types_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ var _ = Describe("MetalStackCluster", func() {
1717
},
1818
}
1919

20-
clusterID := cluster.GetClusterID()
20+
clusterID := cluster.GetClusterName()
2121
Expect(utilvalidation.IsValidLabelValue(clusterID)).To(BeEmpty())
2222
})
2323

@@ -29,7 +29,7 @@ var _ = Describe("MetalStackCluster", func() {
2929
},
3030
}
3131

32-
clusterID := cluster.GetClusterID()
32+
clusterID := cluster.GetClusterName()
3333
Expect(clusterID).To(Equal("some-namespace.my-cluster"))
3434
})
3535
})

api/v1alpha1/zz_generated.deepcopy.go

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

capi-lab/Makefile

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,17 +59,12 @@ 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: node-network
63-
node-network:
64-
metalctl network allocate --description "node network for $(CLUSTER_NAME) cluster" --name $(CLUSTER_NAME) --project 00000000-0000-0000-0000-000000000001 --partition mini-lab
65-
6662
.PHONY: control-plane-ip
6763
control-plane-ip:
6864
metalctl network ip create --network internet-mini-lab --project $(METAL_PROJECT_ID) --name "$(CLUSTER_NAME)-vip" --type static -o template --template "{{ .ipaddress }}"
6965

7066
.PHONY: apply-sample-cluster
7167
apply-sample-cluster:
72-
$(eval METAL_NODE_NETWORK_ID = $(shell metalctl network list --name $(CLUSTER_NAME) -o template --template '{{ .id }}'))
7368
$(eval CONTROL_PLANE_IP = $(shell metalctl network ip list --name "$(CLUSTER_NAME)-vip" -o template --template '{{ .ipaddress }}'))
7469
echo $(CLUSTER_NAME)
7570
clusterctl generate cluster $(CLUSTER_NAME) \
@@ -82,7 +77,6 @@ apply-sample-cluster:
8277

8378
.PHONY: delete-sample-cluster
8479
delete-sample-cluster:
85-
$(eval METAL_NODE_NETWORK_ID = $(shell metalctl network list --name $(CLUSTER_NAME) -o template --template '{{ .id }}'))
8680
$(eval CONTROL_PLANE_IP = $(shell metalctl network ip list --name "$(CLUSTER_NAME)-vip" -o template --template '{{ .ipaddress }}'))
8781
clusterctl generate cluster $(CLUSTER_NAME) \
8882
--kubeconfig=$(KUBECONFIG) \

config/clusterctl-templates/cluster-template-calico-lab.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ metadata:
3131
spec:
3232
projectID: ${METAL_PROJECT_ID}
3333
partition: ${METAL_PARTITION}
34-
nodeNetworkID: ${METAL_NODE_NETWORK_ID}
34+
nodeNetworkID: ${METAL_NODE_NETWORK_ID:=null}
3535
controlPlaneIP: ${CONTROL_PLANE_IP}
3636
firewallDeploymentRef:
3737
name: ${CLUSTER_NAME}

config/clusterctl-templates/cluster-template-calico.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ metadata:
3131
spec:
3232
projectID: ${METAL_PROJECT_ID}
3333
partition: ${METAL_PARTITION}
34-
nodeNetworkID: ${METAL_NODE_NETWORK_ID}
34+
nodeNetworkID: ${METAL_NODE_NETWORK_ID:=null}
3535
controlPlaneIP: ${CONTROL_PLANE_IP}
3636
firewallDeploymentRef:
3737
name: ${CLUSTER_NAME}

config/clusterctl-templates/cluster-template-pre-v1.33.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ metadata:
2727
spec:
2828
projectID: ${METAL_PROJECT_ID}
2929
partition: ${METAL_PARTITION}
30-
nodeNetworkID: ${METAL_NODE_NETWORK_ID}
30+
nodeNetworkID: ${METAL_NODE_NETWORK_ID:=null}
3131
controlPlaneIP: ${CONTROL_PLANE_IP}
3232
firewallDeploymentRef:
3333
name: ${CLUSTER_NAME}

config/clusterctl-templates/cluster-template.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ metadata:
2727
spec:
2828
projectID: ${METAL_PROJECT_ID}
2929
partition: ${METAL_PARTITION}
30-
nodeNetworkID: ${METAL_NODE_NETWORK_ID}
30+
nodeNetworkID: ${METAL_NODE_NETWORK_ID:=null}
3131
controlPlaneIP: ${CONTROL_PLANE_IP}
3232
firewallDeploymentRef:
3333
name: ${CLUSTER_NAME}

0 commit comments

Comments
 (0)