Skip to content

Commit 9a296a4

Browse files
authored
Change Cluster ID to be a valid label value (#90)
1 parent 5888cce commit 9a296a4

File tree

11 files changed

+79
-24
lines changed

11 files changed

+79
-24
lines changed

DEVELOPMENT.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ export WORKER_MACHINE_SIZE=
204204

205205
export CLUSTER_NAME=
206206
export NAMESPACE=default
207-
export KUBERNETES_VERSION=v1.30.6
207+
export KUBERNETES_VERSION=v1.31.6
208208

209209
export CONTROL_PLANE_MACHINE_COUNT=1
210210
export WORKER_MACHINE_COUNT=1

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"),

internal/controller/metalstackmachine_controller.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -560,8 +560,8 @@ func (r *machineReconciler) patchMachineLabels(m *models.V1MachineResponse) {
560560
func (r *machineReconciler) machineTags() []string {
561561
tags := []string{
562562
tag.New(tag.ClusterID, r.infraCluster.Spec.NodeNetworkID),
563-
tag.New(v1alpha1.TagInfraClusterResource, fmt.Sprintf("%s/%s", r.infraCluster.Namespace, r.infraCluster.Name)),
564-
tag.New(v1alpha1.TagInfraMachineResource, fmt.Sprintf("%s/%s", r.infraMachine.Namespace, r.infraMachine.Name)),
563+
tag.New(v1alpha1.TagInfraClusterResource, fmt.Sprintf("%s.%s", r.infraCluster.Namespace, r.infraCluster.Name)),
564+
tag.New(v1alpha1.TagInfraMachineResource, fmt.Sprintf("%s.%s", r.infraMachine.Namespace, r.infraMachine.Name)),
565565
}
566566

567567
if util.IsControlPlaneMachine(r.clusterMachine) {

0 commit comments

Comments
 (0)