From 87765a22f3270d6b2e756ef19541d60a59cbfc6b Mon Sep 17 00:00:00 2001 From: Valentin Knabel Date: Thu, 23 Jan 2025 13:07:09 +0100 Subject: [PATCH 1/5] feat: the sample cluster now relies on our template By using the same template as our users, we ensure that it is always up to date. This also reduces duplicate code. --- CONTRIBUTING.md | 4 +- Makefile | 36 +++++++++ config/samples/example-kubeadm.yaml | 117 ---------------------------- config/samples/kustomization.yaml | 6 -- 4 files changed, 38 insertions(+), 125 deletions(-) delete mode 100644 config/samples/example-kubeadm.yaml delete mode 100644 config/samples/kustomization.yaml diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 105654f..d03d2b1 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -22,10 +22,10 @@ Next install our CAPMS provider into the cluster. make push-to-capi-lab ``` -A basic cluster configuration resides in `config/samples`. +A basic cluster configuration that relies on `config/clusterctl-templates/cluster-template.yaml` can be generated and applied to the mangement cluster using a make target. ```bash -kubectl apply -k config/samples +make apply-sample-cluster ``` For now it is required to manually create the firewall. This might be changed in the future, but for now run: diff --git a/Makefile b/Makefile index 0743dee..e161501 100644 --- a/Makefile +++ b/Makefile @@ -196,6 +196,7 @@ $(LOCALBIN): ## Tool Binaries KUBECTL ?= kubectl KUSTOMIZE ?= $(LOCALBIN)/kustomize +CLUSTERCTL ?= $(LOCALBIN)/clusterctl CONTROLLER_GEN ?= $(LOCALBIN)/controller-gen ENVTEST ?= $(LOCALBIN)/setup-envtest GOLANGCI_LINT = $(LOCALBIN)/golangci-lint @@ -246,3 +247,38 @@ endef .PHONY: up up: bake deploy-cloud-stack + +.PHONY: apply-sample-cluster +apply-sample-cluster: generate manifests + METAL_PARTITION=$(or $(METAL_PARTITION),metal-test) \ + METAL_PROJECT_ID=$(or $(METAL_PROJECT_ID),00000000-0000-0000-0000-000000000001) \ + CONTROL_PLANE_ENDPOINT=$(or $(CONTROL_PLANE_ENDPOINT),203.0.113.129:443) \ + CONTROL_PLANE_MACHINE_IMAGE=$(or $(CONTROL_PLANE_MACHINE_IMAGE),ubuntu-24.04) \ + CONTROL_PLANE_MACHINE_SIZE=$(or $(CONTROL_PLANE_MACHINE_SIZE),v1-small-x86) \ + WORKER_MACHINE_IMAGE=$(or $(WORKER_MACHINE_IMAGE),ubuntu-24.04) \ + WORKER_MACHINE_SIZE=$(or $(WORKER_MACHINE_SIZE),v1-small-x86) \ + clusterctl generate cluster metal-test \ + --kubeconfig=$(KUBECONFIG) \ + --worker-machine-count 1 \ + --control-plane-count 1 \ + --kubernetes-version 1.30.6 \ + --from config/clusterctl-templates/cluster-template.yaml \ + | kubectl --kubeconfig=$(KUBECONFIG) apply -f - + +.PHONY: delete-sample-cluster +delete-sample-cluster: generate manifests + METAL_PARTITION=$(or $(METAL_PARTITION),metal-test) \ + METAL_PROJECT_ID=$(or $(METAL_PROJECT_ID),00000000-0000-0000-0000-000000000001) \ + CONTROL_PLANE_ENDPOINT=$(or $(CONTROL_PLANE_ENDPOINT),203.0.113.129:443) \ + CONTROL_PLANE_MACHINE_IMAGE=$(or $(CONTROL_PLANE_MACHINE_IMAGE),ubuntu-24.04) \ + CONTROL_PLANE_MACHINE_SIZE=$(or $(CONTROL_PLANE_MACHINE_SIZE),v1-small-x86) \ + WORKER_MACHINE_IMAGE=$(or $(WORKER_MACHINE_IMAGE),ubuntu-24.04) \ + WORKER_MACHINE_SIZE=$(or $(WORKER_MACHINE_SIZE),v1-small-x86) \ + clusterctl generate cluster metal-test \ + --kubeconfig=$(KUBECONFIG) \ + --worker-machine-count 1 \ + --control-plane-count 1 \ + --kubernetes-version 1.30.6 \ + --from config/clusterctl-templates/cluster-template.yaml \ + | kubectl --kubeconfig=$(KUBECONFIG) delete -f - + diff --git a/config/samples/example-kubeadm.yaml b/config/samples/example-kubeadm.yaml deleted file mode 100644 index 82d2ac0..0000000 --- a/config/samples/example-kubeadm.yaml +++ /dev/null @@ -1,117 +0,0 @@ ---- -apiVersion: cluster.x-k8s.io/v1beta1 -kind: Cluster -metadata: - name: metal-test -spec: - clusterNetwork: - pods: - cidrBlocks: ["10.240.0.0/12"] - controlPlaneRef: - apiVersion: controlplane.cluster.x-k8s.io/v1beta1 - kind: KubeadmControlPlane - name: metal-test-controlplane - infrastructureRef: - apiVersion: infrastructure.cluster.x-k8s.io/v1alpha1 - kind: MetalStackCluster - name: metal-test ---- -apiVersion: infrastructure.cluster.x-k8s.io/v1alpha1 -kind: MetalStackCluster -metadata: - name: metal-test -spec: - projectID: 00000000-0000-0000-0000-000000000001 - partition: mini-lab ---- -apiVersion: infrastructure.cluster.x-k8s.io/v1alpha1 -kind: MetalStackMachineTemplate -metadata: - name: metal-test-controlplane -spec: - template: - spec: - image: ubuntu-24.04 - size: v1-small-x86 ---- -apiVersion: infrastructure.cluster.x-k8s.io/v1alpha1 -kind: MetalStackMachineTemplate -metadata: - name: metal-test-worker -spec: - template: - spec: - image: ubuntu-24.04 - size: v1-small-x86 ---- -kind: KubeadmControlPlane -apiVersion: controlplane.cluster.x-k8s.io/v1beta1 -metadata: - name: metal-test-controlplane -spec: - replicas: 1 - version: v1.30.6 - machineTemplate: - nodeDrainTimeout: 10m - infrastructureRef: - kind: MetalStackMachineTemplate - apiVersion: infrastructure.cluster.x-k8s.io/v1alpha1 - name: metal-test-controlplane - kubeadmConfigSpec: - format: ignition - clusterConfiguration: - controlPlaneEndpoint: 203.0.113.129:443 - initConfiguration: - localAPIEndpoint: - advertiseAddress: 127.0.0.1 - bindPort: 443 - nodeRegistration: {} - joinConfiguration: - controlPlane: {} - nodeRegistration: {} ---- -apiVersion: cluster.x-k8s.io/v1beta1 -kind: MachineDeployment -metadata: - name: metal-test-md-0 - labels: - cluster.x-k8s.io/cluster-name: metal-test - nodepool: nodepool-0 -spec: - clusterName: metal-test - replicas: 1 - selector: - matchLabels: - cluster.x-k8s.io/cluster-name: metal-test - nodepool: nodepool-0 - template: - metadata: - labels: - cluster.x-k8s.io/cluster-name: metal-test - nodepool: nodepool-0 - spec: - nodeDrainTimeout: 120s - clusterName: metal-test - version: "v1.30.6" - bootstrap: - configRef: - name: metal-test-md-0 - apiVersion: bootstrap.cluster.x-k8s.io/v1beta1 - kind: KubeadmConfigTemplate - infrastructureRef: - name: metal-test-worker - apiVersion: infrastructure.cluster.x-k8s.io/v1beta1 - kind: MetalStackMachineTemplate ---- -apiVersion: bootstrap.cluster.x-k8s.io/v1beta1 -kind: KubeadmConfigTemplate -metadata: - name: metal-test-md-0 -spec: - template: - spec: - format: ignition - clusterConfiguration: - controlPlaneEndpoint: 203.0.113.129:443 - joinConfiguration: - nodeRegistration: {} diff --git a/config/samples/kustomization.yaml b/config/samples/kustomization.yaml deleted file mode 100644 index 2291d43..0000000 --- a/config/samples/kustomization.yaml +++ /dev/null @@ -1,6 +0,0 @@ -## Append samples of your project ## -namespace: default - -resources: -- example-kubeadm.yaml -# +kubebuilder:scaffold:manifestskustomizesamples From a797dfb910918cec789fcf8c771257b3da2e39fd Mon Sep 17 00:00:00 2001 From: Valentin Knabel Date: Thu, 23 Jan 2025 13:10:14 +0100 Subject: [PATCH 2/5] docs: improve docs --- CONTRIBUTING.md | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index d03d2b1..a06707c 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -22,7 +22,7 @@ Next install our CAPMS provider into the cluster. make push-to-capi-lab ``` -A basic cluster configuration that relies on `config/clusterctl-templates/cluster-template.yaml` can be generated and applied to the mangement cluster using a make target. +A basic cluster configuration that relies on `config/clusterctl-templates/cluster-template.yaml` can be generated and applied to the management cluster using a make target. ```bash make apply-sample-cluster @@ -112,19 +112,17 @@ make deploy IMG=/cluster-api-provider-metal-stack:tag privileges or be logged in as admin. **Create instances of your solution** -You can apply the samples (examples) from the config/sample: +You can apply the sample cluster configuration: ```sh -kubectl apply -k config/samples/ +make apply-sample-cluster ``` ->**NOTE**: Ensure that the samples has default values to test it out. - ### To Uninstall **Delete the instances (CRs) from the cluster:** ```sh -kubectl delete -k config/samples/ +make delete-sample-cluster ``` **Delete the APIs(CRDs) from the cluster:** From 3d386eeb043d5ed54c055e9ad5096ef8b015dfc8 Mon Sep 17 00:00:00 2001 From: Valentin Knabel Date: Thu, 23 Jan 2025 13:30:02 +0100 Subject: [PATCH 3/5] refactor: centralized envs --- Makefile | 28 ++++++++++------------------ 1 file changed, 10 insertions(+), 18 deletions(-) diff --git a/Makefile b/Makefile index e161501..43fe496 100644 --- a/Makefile +++ b/Makefile @@ -196,7 +196,6 @@ $(LOCALBIN): ## Tool Binaries KUBECTL ?= kubectl KUSTOMIZE ?= $(LOCALBIN)/kustomize -CLUSTERCTL ?= $(LOCALBIN)/clusterctl CONTROLLER_GEN ?= $(LOCALBIN)/controller-gen ENVTEST ?= $(LOCALBIN)/setup-envtest GOLANGCI_LINT = $(LOCALBIN)/golangci-lint @@ -245,40 +244,33 @@ endef # mini-lab developer environment +export METAL_PARTITION ?= metal-test +export METAL_PROJECT_ID ?= 00000000-0000-0000-0000-000000000001 +export CONTROL_PLANE_ENDPOINT ?= 203.0.113.129:443 +export CONTROL_PLANE_MACHINE_IMAGE ?= ubuntu-24.04 +export CONTROL_PLANE_MACHINE_SIZE ?= v1-small-x86 +export WORKER_MACHINE_IMAGE ?= ubuntu-24.04 +export WORKER_MACHINE_SIZE ?= v1-small-x86 + .PHONY: up up: bake deploy-cloud-stack .PHONY: apply-sample-cluster apply-sample-cluster: generate manifests - METAL_PARTITION=$(or $(METAL_PARTITION),metal-test) \ - METAL_PROJECT_ID=$(or $(METAL_PROJECT_ID),00000000-0000-0000-0000-000000000001) \ - CONTROL_PLANE_ENDPOINT=$(or $(CONTROL_PLANE_ENDPOINT),203.0.113.129:443) \ - CONTROL_PLANE_MACHINE_IMAGE=$(or $(CONTROL_PLANE_MACHINE_IMAGE),ubuntu-24.04) \ - CONTROL_PLANE_MACHINE_SIZE=$(or $(CONTROL_PLANE_MACHINE_SIZE),v1-small-x86) \ - WORKER_MACHINE_IMAGE=$(or $(WORKER_MACHINE_IMAGE),ubuntu-24.04) \ - WORKER_MACHINE_SIZE=$(or $(WORKER_MACHINE_SIZE),v1-small-x86) \ clusterctl generate cluster metal-test \ --kubeconfig=$(KUBECONFIG) \ --worker-machine-count 1 \ - --control-plane-count 1 \ + --control-plane-machine-count 1 \ --kubernetes-version 1.30.6 \ --from config/clusterctl-templates/cluster-template.yaml \ | kubectl --kubeconfig=$(KUBECONFIG) apply -f - .PHONY: delete-sample-cluster delete-sample-cluster: generate manifests - METAL_PARTITION=$(or $(METAL_PARTITION),metal-test) \ - METAL_PROJECT_ID=$(or $(METAL_PROJECT_ID),00000000-0000-0000-0000-000000000001) \ - CONTROL_PLANE_ENDPOINT=$(or $(CONTROL_PLANE_ENDPOINT),203.0.113.129:443) \ - CONTROL_PLANE_MACHINE_IMAGE=$(or $(CONTROL_PLANE_MACHINE_IMAGE),ubuntu-24.04) \ - CONTROL_PLANE_MACHINE_SIZE=$(or $(CONTROL_PLANE_MACHINE_SIZE),v1-small-x86) \ - WORKER_MACHINE_IMAGE=$(or $(WORKER_MACHINE_IMAGE),ubuntu-24.04) \ - WORKER_MACHINE_SIZE=$(or $(WORKER_MACHINE_SIZE),v1-small-x86) \ clusterctl generate cluster metal-test \ --kubeconfig=$(KUBECONFIG) \ --worker-machine-count 1 \ - --control-plane-count 1 \ + --control-plane-machine-count 1 \ --kubernetes-version 1.30.6 \ --from config/clusterctl-templates/cluster-template.yaml \ | kubectl --kubeconfig=$(KUBECONFIG) delete -f - - From b5c765654e8f5acd567278eb897e3b3af0036f36 Mon Sep 17 00:00:00 2001 From: Valentin Knabel Date: Thu, 23 Jan 2025 13:34:48 +0100 Subject: [PATCH 4/5] fix: quote control plane endpoint --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 43fe496..b8801e3 100644 --- a/Makefile +++ b/Makefile @@ -246,7 +246,7 @@ endef export METAL_PARTITION ?= metal-test export METAL_PROJECT_ID ?= 00000000-0000-0000-0000-000000000001 -export CONTROL_PLANE_ENDPOINT ?= 203.0.113.129:443 +export CONTROL_PLANE_ENDPOINT ?= "203.0.113.129:443" export CONTROL_PLANE_MACHINE_IMAGE ?= ubuntu-24.04 export CONTROL_PLANE_MACHINE_SIZE ?= v1-small-x86 export WORKER_MACHINE_IMAGE ?= ubuntu-24.04 From dad870e2f920c0f841798ae91da7c59c0fa3d842 Mon Sep 17 00:00:00 2001 From: Valentin Knabel Date: Thu, 23 Jan 2025 15:57:59 +0100 Subject: [PATCH 5/5] feat: create node network --- CONTRIBUTING.md | 12 ++++++++---- Makefile | 3 ++- capi-lab/Makefile | 4 ++++ config/clusterctl-templates/cluster-template.yaml | 1 + config/clusterctl-templates/example_variables.rc | 2 +- 5 files changed, 16 insertions(+), 6 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index a06707c..3870d65 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -22,17 +22,21 @@ Next install our CAPMS provider into the cluster. make push-to-capi-lab ``` -A basic cluster configuration that relies on `config/clusterctl-templates/cluster-template.yaml` can be generated and applied to the management cluster using a make target. +Before creating a cluster some manual steps are required beforehand: you need to allocate a node network and a firewall. + +```bash +make -C capi-lab node-network firewall +``` + +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. ```bash make apply-sample-cluster ``` -For now it is required to manually create the firewall. This might be changed in the future, but for now run: +Once the control plane node has phoned home, run: ```bash -make -C capi-lab firewall -# once the firewall is up run make -C capi-lab mtu-fix ``` diff --git a/Makefile b/Makefile index b8801e3..51b42f8 100644 --- a/Makefile +++ b/Makefile @@ -244,8 +244,9 @@ endef # mini-lab developer environment -export METAL_PARTITION ?= metal-test +export METAL_PARTITION ?= mini-lab export METAL_PROJECT_ID ?= 00000000-0000-0000-0000-000000000001 +export METAL_NODE_NETWORK_ID ?= $(shell metalctl network list --name metal-test -o template --template '{{ .id }}') export CONTROL_PLANE_ENDPOINT ?= "203.0.113.129:443" export CONTROL_PLANE_MACHINE_IMAGE ?= ubuntu-24.04 export CONTROL_PLANE_MACHINE_SIZE ?= v1-small-x86 diff --git a/capi-lab/Makefile b/capi-lab/Makefile index efe9e8b..cdc1919 100644 --- a/capi-lab/Makefile +++ b/capi-lab/Makefile @@ -38,6 +38,10 @@ controller: firewall: 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 }}') +.PHONY: node-network +node-network: + metalctl network allocate --description "node network for metal-test cluster" --name metal-test --project 00000000-0000-0000-0000-000000000001 --partition mini-lab + .PHONY: mtu-fix mtu-fix: cd mini-lab && ssh -F files/ssh/config leaf01 'ip link set dev vtep-1001 mtu 9100 && echo done' diff --git a/config/clusterctl-templates/cluster-template.yaml b/config/clusterctl-templates/cluster-template.yaml index cca26c6..f746e2b 100644 --- a/config/clusterctl-templates/cluster-template.yaml +++ b/config/clusterctl-templates/cluster-template.yaml @@ -27,6 +27,7 @@ metadata: spec: projectID: ${METAL_PROJECT_ID} partition: ${METAL_PARTITION} + nodeNetworkID: ${METAL_NODE_NETWORK_ID} --- apiVersion: infrastructure.cluster.x-k8s.io/v1alpha1 kind: MetalStackMachineTemplate diff --git a/config/clusterctl-templates/example_variables.rc b/config/clusterctl-templates/example_variables.rc index 6515e33..f7c54d0 100644 --- a/config/clusterctl-templates/example_variables.rc +++ b/config/clusterctl-templates/example_variables.rc @@ -4,12 +4,12 @@ export METAL_API_HMAC=metal-admin export METAL_PROJECT_ID=00000000-0000-0000-0000-000000000001 export POD_CIDR=10.240.0.0/12 export METAL_PARTITION=mini-lab +export METAL_NODE_NETWORK_ID=00000000-0000-0000-0000-000000000002 export FIREWALL_MACHINE_SIZE=v1-small-x86 export FIREWALL_MACHINE_IMAGE= export FIREWALL_NETWORKS=[internet] -export NODE_NETWORK_ID=00000000-0000-0000-0000-000000000002 export CONTROL_PLANE_ENDPOINT=203.0.113.129:443 export CONTROL_PLANE_PORT=443 export CONTROL_PLANE_MACHINE_SIZE=v1-small-x86