diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 105654f..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 resides in `config/samples`. +Before creating a cluster some manual steps are required beforehand: you need to allocate a node network and a firewall. ```bash -kubectl apply -k config/samples +make -C capi-lab node-network firewall ``` -For now it is required to manually create the firewall. This might be changed in the future, but for now run: +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 +``` + +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 ``` @@ -112,19 +116,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:** diff --git a/Makefile b/Makefile index 0743dee..51b42f8 100644 --- a/Makefile +++ b/Makefile @@ -244,5 +244,34 @@ endef # mini-lab developer environment +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 +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 + clusterctl generate cluster metal-test \ + --kubeconfig=$(KUBECONFIG) \ + --worker-machine-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 + clusterctl generate cluster metal-test \ + --kubeconfig=$(KUBECONFIG) \ + --worker-machine-count 1 \ + --control-plane-machine-count 1 \ + --kubernetes-version 1.30.6 \ + --from config/clusterctl-templates/cluster-template.yaml \ + | kubectl --kubeconfig=$(KUBECONFIG) delete -f - 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 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