Skip to content

Commit 9cbeb7d

Browse files
committed
Ignition service for bootstrapping kubeadm and kubelet.
1 parent cfba940 commit 9cbeb7d

File tree

3 files changed

+67
-26
lines changed

3 files changed

+67
-26
lines changed
Lines changed: 55 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -29,33 +29,70 @@ spec:
2929
networks:
3030
- internet-mini-lab
3131
---
32+
apiVersion: infrastructure.cluster.x-k8s.io/v1alpha1
33+
kind: MetalStackMachineTemplate
34+
metadata:
35+
name: metal-test-controlplane
36+
spec:
37+
template:
38+
spec:
39+
image: ubuntu-24.04
40+
size: v1-small-x86
41+
---
3242
kind: KubeadmControlPlane
3343
apiVersion: controlplane.cluster.x-k8s.io/v1beta1
3444
metadata:
3545
name: metal-test-controlplane
3646
spec:
47+
replicas: 1
48+
version: v1.30.6
49+
machineTemplate:
50+
nodeDrainTimeout: 10m
51+
infrastructureRef:
52+
kind: MetalStackMachineTemplate
53+
apiVersion: infrastructure.cluster.x-k8s.io/v1alpha1
54+
name: metal-test-controlplane
3755
kubeadmConfigSpec:
3856
format: ignition
3957
initConfiguration:
4058
nodeRegistration: {}
4159
joinConfiguration:
4260
controlPlane: {}
4361
nodeRegistration: {}
44-
machineTemplate:
45-
nodeDrainTimeout: 10m
46-
infrastructureRef:
47-
kind: MetalStackMachineTemplate
48-
apiVersion: infrastructure.cluster.x-k8s.io/v1alpha1
49-
name: metal-test-controlplane
50-
replicas: 1
51-
version: v1.30.6
52-
---
53-
apiVersion: infrastructure.cluster.x-k8s.io/v1alpha1
54-
kind: MetalStackMachineTemplate
55-
metadata:
56-
name: metal-test-controlplane
57-
spec:
58-
template:
59-
spec:
60-
image: ubuntu-24.04
61-
size: v1-small-x86
62+
ignition:
63+
containerLinuxConfig:
64+
additionalConfig: |
65+
systemd:
66+
units:
67+
- name: cluster-api-init.service
68+
enable: true
69+
contents: |-
70+
[Unit]
71+
Description=Prepares the node for bootstrapping with cluster-api kubeadm
72+
Before=kubeadm.service
73+
After=network-online.target
74+
Wants=network-online.target
75+
[Service]
76+
Type=oneshot
77+
Restart=on-failure
78+
RestartSec=5
79+
StartLimitBurst=0
80+
EnvironmentFile=/etc/environment
81+
ExecStart=/var/lib/cluster-api-init/bootstrap.sh
82+
[Install]
83+
WantedBy=multi-user.target
84+
files:
85+
- path: /var/lib/cluster-api-init/bootstrap.sh
86+
owner: "root:root"
87+
permissions: "0744"
88+
content: |
89+
#!/usr/bin/env bash
90+
set -eo pipefail
91+
set +x
92+
93+
curl -fsSL https://pkgs.k8s.io/core:/stable:/v1.30/deb/Release.key | gpg --dearmor -o /etc/apt/keyrings/kubernetes-apt-keyring.gpg
94+
echo 'deb [signed-by=/etc/apt/keyrings/kubernetes-apt-keyring.gpg] https://pkgs.k8s.io/core:/stable:/v1.30/deb/ /' | tee /etc/apt/sources.list.d/kubernetes.list
95+
96+
apt-get update
97+
apt-get install -y kubelet kubeadm kubectl
98+
apt-mark hold kubelet kubeadm kubectl

config/samples/kustomization.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
namespace: default
33

44
resources:
5-
- example.yaml
5+
- example-kubeadm.yaml
66
# +kubebuilder:scaffold:manifestskustomizesamples

internal/controller/metalstackcluster_controller.go

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -166,12 +166,12 @@ func (r *MetalStackClusterReconciler) SetupWithManager(mgr ctrl.Manager) error {
166166
}
167167

168168
func (r *clusterReconciler) reconcile() error {
169-
nodeCIDR, err := r.ensureNodeNetwork()
169+
nodeNetworkID, err := r.ensureNodeNetwork()
170170
if err != nil {
171171
return fmt.Errorf("unable to ensure node network: %w", err)
172172
}
173173

174-
r.log.Info("reconciled node network", "cidr", nodeCIDR)
174+
r.log.Info("reconciled node network", "network-id", nodeNetworkID)
175175

176176
ip, err := r.ensureControlPlaneIP()
177177
if err != nil {
@@ -197,7 +197,7 @@ func (r *clusterReconciler) reconcile() error {
197197
return fmt.Errorf("failed to update infra cluster control plane endpoint: %w", err)
198198
}
199199

200-
fwdeploy, err := r.ensureFirewallDeployment(nodeCIDR)
200+
fwdeploy, err := r.ensureFirewallDeployment(nodeNetworkID)
201201
if err != nil {
202202
return fmt.Errorf("unable to ensure firewall deployment: %w", err)
203203
}
@@ -259,15 +259,15 @@ func (r *clusterReconciler) ensureNodeNetwork() (string, error) {
259259
return "", fmt.Errorf("error creating node network: %w", err)
260260
}
261261

262-
return resp.Payload.Prefixes[0], nil
262+
return *resp.Payload.ID, nil
263263
case 1:
264264
nw := nws[0]
265265

266266
if len(nw.Prefixes) == 0 {
267267
return "", errors.New("node network exists but the prefix is gone")
268268
}
269269

270-
return nw.Prefixes[0], nil
270+
return *nw.ID, nil
271271
default:
272272
return "", fmt.Errorf("more than a single node network exists for this cluster, operator investigation is required")
273273
}
@@ -399,7 +399,7 @@ func (r *clusterReconciler) findControlPlaneIP() ([]*models.V1IPResponse, error)
399399
return resp.Payload, nil
400400
}
401401

402-
func (r *clusterReconciler) ensureFirewallDeployment(nodeCIDR string) (*fcmv2.FirewallDeployment, error) {
402+
func (r *clusterReconciler) ensureFirewallDeployment(nodeNetworkID string) (*fcmv2.FirewallDeployment, error) {
403403
deploy := &fcmv2.FirewallDeployment{
404404
ObjectMeta: metav1.ObjectMeta{
405405
Name: r.infraCluster.Name,
@@ -440,7 +440,7 @@ func (r *clusterReconciler) ensureFirewallDeployment(nodeCIDR string) (*fcmv2.Fi
440440

441441
deploy.Spec.Template.Spec.Size = r.infraCluster.Spec.Firewall.Size
442442
deploy.Spec.Template.Spec.Image = r.infraCluster.Spec.Firewall.Image
443-
deploy.Spec.Template.Spec.Networks = append(r.infraCluster.Spec.Firewall.AdditionalNetworks, nodeCIDR)
443+
deploy.Spec.Template.Spec.Networks = append(r.infraCluster.Spec.Firewall.AdditionalNetworks, nodeNetworkID)
444444
deploy.Spec.Template.Spec.RateLimits = r.infraCluster.Spec.Firewall.RateLimits
445445
deploy.Spec.Template.Spec.EgressRules = r.infraCluster.Spec.Firewall.EgressRules
446446
deploy.Spec.Template.Spec.LogAcceptedConnections = ptr.Deref(r.infraCluster.Spec.Firewall.LogAcceptedConnections, false)
@@ -452,6 +452,10 @@ func (r *clusterReconciler) ensureFirewallDeployment(nodeCIDR string) (*fcmv2.Fi
452452
deploy.Spec.Template.Spec.NftablesExporterVersion = ""
453453
deploy.Spec.Template.Spec.NftablesExporterURL = ""
454454

455+
// TODO: we need to allow internet connection for the nodes before the firewall-controller can connect to the control-plane
456+
// the FCM currently does not support this
457+
deploy.Spec.Template.Spec.Userdata = ""
458+
455459
// TODO: do we need to generate ssh keys for the machines and the firewall in this controller?
456460
deploy.Spec.Template.Spec.SSHPublicKeys = nil
457461

0 commit comments

Comments
 (0)