Skip to content

Commit 4ad70c1

Browse files
Merge branch 'main' into cyclonedx-sbom
2 parents e012f97 + 9a296a4 commit 4ad70c1

File tree

12 files changed

+79
-86
lines changed

12 files changed

+79
-86
lines changed

DEVELOPMENT.md

Lines changed: 1 addition & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -85,32 +85,6 @@ If you want to provide service's of type load balancer through MetalLB by the me
8585
kubectl --kubeconfig capi-lab/.capms-cluster-kubeconfig.yaml apply --kustomize capi-lab/metallb
8686
```
8787

88-
For each node in your Kubernetes cluster, you need to create a BGP peer configuration. Replace the placeholders ({{
89-
NODE_ASN }}, {{ NODE_HOSTNAME }}, and {{ NODE_ROUTER_ID }}) with the appropriate values for each node.
90-
91-
```bash
92-
cat <<EOF | kubectl --kubeconfig=capi-lab/.capms-cluster-kubeconfig.yaml create -f -
93-
apiVersion: metallb.io/v1beta2
94-
kind: BGPPeer
95-
metadata:
96-
name: ${NODE_HOSTNAME}
97-
namespace: metallb-system
98-
spec:
99-
holdTime: 1m30s
100-
keepaliveTime: 0s
101-
myASN: ${NODE_ASN}
102-
nodeSelectors:
103-
- matchExpressions:
104-
- key: kubernetes.io/hostname
105-
operator: In
106-
values:
107-
- ${NODE_HOSTNAME}
108-
passwordSecret: {}
109-
peerASN: ${NODE_ASN}
110-
peerAddress: ${NODE_ROUTER_ID}
111-
EOF
112-
```
113-
11488
That's it!
11589

11690
### To Deploy on the cluster
@@ -230,7 +204,7 @@ export WORKER_MACHINE_SIZE=
230204

231205
export CLUSTER_NAME=
232206
export NAMESPACE=default
233-
export KUBERNETES_VERSION=v1.30.6
207+
export KUBERNETES_VERSION=v1.31.6
234208

235209
export CONTROL_PLANE_MACHINE_COUNT=1
236210
export WORKER_MACHINE_COUNT=1

README.md

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -146,42 +146,6 @@ If you want to provide service's of type `LoadBalancer` through MetalLB by the `
146146
kubectl --kubeconfig capms-cluster.kubeconfig apply --kustomize capi-lab/metallb
147147
```
148148

149-
For each worker node in your Kubernetes cluster, you need to create a BGP peer configuration. Replace the placeholders (`{{
150-
NODE_ASN }}`, `{{ NODE_HOSTNAME }}`, and `{{ NODE_ROUTER_ID }}`) with the appropriate values for each node.
151-
152-
```bash
153-
# in metal-stack, list all machines of your cluster
154-
metalctl machine ls --project $METAL_PROJECT_ID
155-
156-
# for each worker machine collect the information as follows
157-
export NODE_ID=<worker-machine-id>
158-
export NODE_HOSTNAME=$(metalctl machine describe $NODE_ID -o template --template '{{ .allocation.hostname }}')
159-
export NODE_ASN=$(metalctl machine describe $NODE_ID -o template --template '{{ printf "%.0f" (index .allocation.networks 0).asn }}')
160-
export NODE_ROUTER_ID=$(metalctl machine describe $NODE_ID -o template --template '{{ (index (index .allocation.networks 0).ips 0) }}')
161-
162-
# for each worker machine generate and apply the BGPPeer resource
163-
cat <<EOF | kubectl --kubeconfig=capms-cluster.kubeconfig create -f -
164-
apiVersion: metallb.io/v1beta2
165-
kind: BGPPeer
166-
metadata:
167-
name: ${NODE_HOSTNAME}
168-
namespace: metallb-system
169-
spec:
170-
holdTime: 1m30s
171-
keepaliveTime: 0s
172-
myASN: ${NODE_ASN}
173-
nodeSelectors:
174-
- matchExpressions:
175-
- key: kubernetes.io/hostname
176-
operator: In
177-
values:
178-
- ${NODE_HOSTNAME}
179-
passwordSecret: {}
180-
peerASN: ${NODE_ASN}
181-
peerAddress: ${NODE_ROUTER_ID}
182-
EOF
183-
```
184-
185149
## Frequently Asked Questions
186150

187151
### I need to know the Control Plane IP address in advance. Can I provide a static IP address in advance?

api/v1alpha1/metalstackcluster_types.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,5 +142,5 @@ func (c *MetalStackCluster) SetConditions(conditions clusterv1.Conditions) {
142142
}
143143

144144
func (c *MetalStackCluster) GetClusterID() string {
145-
return fmt.Sprintf("%s/%s", c.GetNamespace(), c.GetName())
145+
return fmt.Sprintf("%s.%s", c.GetNamespace(), c.GetName())
146146
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package v1alpha1_test
2+
3+
import (
4+
"github.com/metal-stack/cluster-api-provider-metal-stack/api/v1alpha1"
5+
. "github.com/onsi/ginkgo/v2"
6+
. "github.com/onsi/gomega"
7+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
8+
utilvalidation "k8s.io/apimachinery/pkg/util/validation"
9+
)
10+
11+
var _ = Describe("MetalStackCluster", func() {
12+
It("GetClusterID is a valid label value", func() {
13+
cluster := &v1alpha1.MetalStackCluster{
14+
ObjectMeta: metav1.ObjectMeta{
15+
Name: "my-cluster",
16+
Namespace: "some-namespace",
17+
},
18+
}
19+
20+
clusterID := cluster.GetClusterID()
21+
Expect(utilvalidation.IsValidLabelValue(clusterID)).To(BeEmpty())
22+
})
23+
24+
It("GetClusterID is constant", func() {
25+
cluster := &v1alpha1.MetalStackCluster{
26+
ObjectMeta: metav1.ObjectMeta{
27+
Name: "my-cluster",
28+
Namespace: "some-namespace",
29+
},
30+
}
31+
32+
clusterID := cluster.GetClusterID()
33+
Expect(clusterID).To(Equal("some-namespace.my-cluster"))
34+
})
35+
})

api/v1alpha1/suite_test.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package v1alpha1_test
2+
3+
import (
4+
"testing"
5+
6+
. "github.com/onsi/ginkgo/v2"
7+
. "github.com/onsi/gomega"
8+
)
9+
10+
func TestTypes(t *testing.T) {
11+
RegisterFailHandler(Fail)
12+
RunSpecs(t, "v1alpha1.Types Suite")
13+
}

capi-lab/Makefile

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ KIND_EXPERIMENTAL_DOCKER_NETWORK=mini_lab_ext
66
KUBECONFIG := $(shell pwd)/mini-lab/.kubeconfig
77
MINI_LAB_FLAVOR=capms
88

9+
CLUSTER_NAME ?= metal-test
10+
KUBERNETES_VERSION ?= 1.31.6
11+
912
METAL_API_URL=http://metal.203.0.113.1.nip.io:8080
1013
METAL_API_HMAC=metal-edit
1114
METAL_API_HMAC_AUTH_TYPE=Metal-Edit
@@ -16,9 +19,9 @@ METALCTL_HMAC_AUTH_TYPE=Metal-Edit
1619
METAL_PARTITION ?= mini-lab
1720
METAL_PROJECT_ID ?= 00000000-0000-0000-0000-000000000001
1821

19-
CONTROL_PLANE_MACHINE_IMAGE ?= ubuntu-24.0-k8s-1.31.6
22+
CONTROL_PLANE_MACHINE_IMAGE ?= ubuntu-24.0-k8s-$(KUBERNETES_VERSION)
2023
CONTROL_PLANE_MACHINE_SIZE ?= v1-small-x86
21-
WORKER_MACHINE_IMAGE ?= ubuntu-24.0-k8s-1.31.6
24+
WORKER_MACHINE_IMAGE ?= ubuntu-24.0-k8s-$(KUBERNETES_VERSION)
2225
WORKER_MACHINE_SIZE ?= v1-small-x86
2326

2427
IMG ?= ghcr.io/metal-stack/cluster-api-metal-stack-controller:latest
@@ -54,37 +57,38 @@ controller:
5457

5558
.PHONY: firewall
5659
firewall:
57-
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 metal-test -o template --template '{{ .id }}')
60+
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 }}')
5861

5962
.PHONY: node-network
6063
node-network:
61-
metalctl network allocate --description "node network for metal-test cluster" --name metal-test --project 00000000-0000-0000-0000-000000000001 --partition mini-lab
64+
metalctl network allocate --description "node network for $(CLUSTER_NAME) cluster" --name $(CLUSTER_NAME) --project 00000000-0000-0000-0000-000000000001 --partition mini-lab
6265

6366
.PHONY: control-plane-ip
6467
control-plane-ip:
6568
metalctl network ip create --network internet-mini-lab --project $(METAL_PROJECT_ID) --name "$(CLUSTER_NAME)-vip" --type static -o template --template "{{ .ipaddress }}"
6669

6770
.PHONY: apply-sample-cluster
6871
apply-sample-cluster:
69-
$(eval METAL_NODE_NETWORK_ID = $(shell metalctl network list --name metal-test -o template --template '{{ .id }}'))
70-
$(eval CONTROL_PLANE_IP = $(shell metalctl network ip list --name "$(CLUSTER_NAME)-vip" -o template --template '{{ .id }}'))
71-
clusterctl generate cluster metal-test \
72+
$(eval METAL_NODE_NETWORK_ID = $(shell metalctl network list --name $(CLUSTER_NAME) -o template --template '{{ .id }}'))
73+
$(eval CONTROL_PLANE_IP = $(shell metalctl network ip list --name "$(CLUSTER_NAME)-vip" -o template --template '{{ .ipaddress }}'))
74+
echo $(CLUSTER_NAME)
75+
clusterctl generate cluster $(CLUSTER_NAME) \
7276
--kubeconfig=$(KUBECONFIG) \
7377
--worker-machine-count 1 \
7478
--control-plane-machine-count 1 \
75-
--kubernetes-version 1.30.6 \
79+
--kubernetes-version $(KUBERNETES_VERSION) \
7680
--from ../config/clusterctl-templates/cluster-template.yaml \
7781
| kubectl --kubeconfig=$(KUBECONFIG) apply -f -
7882

7983
.PHONY: delete-sample-cluster
8084
delete-sample-cluster:
81-
$(eval METAL_NODE_NETWORK_ID = $(shell metalctl network list --name metal-test -o template --template '{{ .id }}'))
82-
$(eval CONTROL_PLANE_IP = $(shell metalctl network ip list --name "$(CLUSTER_NAME)-vip" -o template --template '{{ .id }}'))
83-
clusterctl generate cluster metal-test \
85+
$(eval METAL_NODE_NETWORK_ID = $(shell metalctl network list --name $(CLUSTER_NAME) -o template --template '{{ .id }}'))
86+
$(eval CONTROL_PLANE_IP = $(shell metalctl network ip list --name "$(CLUSTER_NAME)-vip" -o template --template '{{ .ipaddress }}'))
87+
clusterctl generate cluster $(CLUSTER_NAME) \
8488
--kubeconfig=$(KUBECONFIG) \
8589
--worker-machine-count 1 \
8690
--control-plane-machine-count 1 \
87-
--kubernetes-version 1.30.6 \
91+
--kubernetes-version $(KUBERNETES_VERSION) \
8892
--from ../config/clusterctl-templates/cluster-template.yaml \
8993
| kubectl --kubeconfig=$(KUBECONFIG) delete -f -
9094

@@ -95,7 +99,7 @@ mtu-fix:
9599

96100
.PHONY: deploy-metal-ccm
97101
deploy-metal-ccm:
98-
$(eval METAL_CLUSTER_ID = $(shell kubectl get metalstackclusters.infrastructure.cluster.x-k8s.io metal-test -ojsonpath='{.metadata.uid}'))
99-
$(eval METAL_NODE_NETWORK_ID = $(shell metalctl network list --name metal-test -o template --template '{{ .id }}'))
102+
$(eval NAMESPACE = $(shell kubectl get metalstackclusters.infrastructure.cluster.x-k8s.io $(CLUSTER_NAME) -ojsonpath='{.metadata.namespace}'))
103+
$(eval METAL_NODE_NETWORK_ID = $(shell metalctl network list --name $(CLUSTER_NAME) -o template --template '{{ .id }}'))
100104
$(eval CONTROL_PLANE_IP = $(shell metalctl network ip list --name "$(CLUSTER_NAME)-vip" -o template --template '{{ .id }}'))
101105
cat metal-ccm.yaml | envsubst | kubectl --kubeconfig=.capms-cluster-kubeconfig.yaml apply -f -

capi-lab/metal-ccm.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,14 +184,14 @@ spec:
184184
value: mini-lab
185185
# associates service type load balancer ips with this cluster:
186186
- name: METAL_CLUSTER_ID
187-
value: ${METAL_CLUSTER_ID}
187+
value: ${NAMESPACE}.${CLUSTER_NAME}
188188
- name: METAL_DEFAULT_EXTERNAL_NETWORK_ID
189189
value: internet-mini-lab
190190
- name: METAL_ADDITIONAL_NETWORKS
191191
value: internet-mini-lab,${METAL_NODE_NETWORK_ID}
192192
- name: METAL_SSH_PUBLICKEY
193193
value: ""
194-
image: ghcr.io/metal-stack/metal-ccm:v0.9.4
194+
image: ghcr.io/metal-stack/metal-ccm:v0.9.7
195195
imagePullPolicy: IfNotPresent
196196
livenessProbe:
197197
failureThreshold: 2

config/target-cluster/metal-ccm.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,14 +184,14 @@ spec:
184184
value: ${METAL_PARTITION}
185185
# associates service type load balancer ips with this cluster:
186186
- name: METAL_CLUSTER_ID
187-
value: ${NAMESPACE}/${CLUSTER_NAME}
187+
value: ${NAMESPACE}.${CLUSTER_NAME}
188188
- name: METAL_DEFAULT_EXTERNAL_NETWORK_ID
189189
value: internet
190190
- name: METAL_ADDITIONAL_NETWORKS
191191
value: internet,${METAL_NODE_NETWORK_ID}
192192
- name: METAL_SSH_PUBLICKEY
193193
value: ""
194-
image: ghcr.io/metal-stack/metal-ccm:v0.9.4
194+
image: ghcr.io/metal-stack/metal-ccm:v0.9.7
195195
imagePullPolicy: IfNotPresent
196196
livenessProbe:
197197
failureThreshold: 2

internal/controller/metalstackcluster_controller.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ func (r *clusterReconciler) ensureControlPlaneIP() (string, error) {
337337

338338
defaultNetwork := nwResp.Payload[0]
339339
resp, err := r.metalClient.IP().AllocateIP(ipmodels.NewAllocateIPParams().WithBody(&models.V1IPAllocateRequest{
340-
Description: fmt.Sprintf("%s/%s control plane ip", r.infraCluster.GetNamespace(), r.infraCluster.GetName()),
340+
Description: fmt.Sprintf("%s control plane ip", r.infraCluster.GetClusterID()),
341341
Name: r.infraCluster.GetName() + "-control-plane",
342342
Networkid: defaultNetwork.ID,
343343
Projectid: &r.infraCluster.Spec.ProjectID,

internal/controller/metalstackcluster_controller_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ var _ = Describe("MetalStackCluster Controller", func() {
275275
"metal-stack.infrastructure.cluster.x-k8s.io/purpose=control-plane",
276276
},
277277
Name: resource.Name + "-control-plane",
278-
Description: resource.Namespace + "/" + resource.Name + " control plane ip",
278+
Description: resource.GetClusterID() + " control plane ip",
279279
Networkid: ptr.To("internet"),
280280
Projectid: ptr.To("test-project"),
281281
Type: ptr.To("ephemeral"),

0 commit comments

Comments
 (0)