Skip to content

Commit ae247ed

Browse files
committed
ci: deploy ipv6 talos cluster without ipv4 addresses (#5401)
Signed-off-by: zhangzujian <[email protected]>
1 parent 663a68a commit ae247ed

File tree

6 files changed

+87
-30
lines changed

6 files changed

+87
-30
lines changed

.gitignore

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,9 @@ ovn-cert.pem
5656
ovn-privkey.pem
5757
anp-test-report.yaml
5858
# Generated files used for Talos testing
59-
libvirt-domain.xml
60-
talosconfig
61-
controlplane.yaml
62-
worker.yaml
63-
cluster-patch.yaml
64-
machine-patch.yaml
59+
talos/libvirt-domain.xml
60+
talos/talosconfig
61+
talos/controlplane.yaml
62+
talos/worker.yaml
63+
talos/cluster-config.yaml
64+
talos/machine-config.yaml

talos.mk

Lines changed: 39 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,12 @@ TALOS_IMAGE_PATH = $(TALOS_IMAGE_DIR)/$(TALOS_IMAGE_ISO)
99

1010
TALOS_REGISTRY_MIRROR_NAME ?= talos-registry-mirror
1111
# libvirt network gateway address
12-
TALOS_REGISTRY_MIRROR_HOST ?= 172.99.99.1
12+
TALOS_REGISTRY_MIRROR_HOST_IPV4 ?= 172.99.99.1
13+
TALOS_REGISTRY_MIRROR_HOST_IPV6 ?= 2001:db8:99:99::1
1314
TALOS_REGISTRY_MIRROR_PORT ?= 6000
14-
TALOS_REGISTRY_MIRROR = $(TALOS_REGISTRY_MIRROR_HOST):$(TALOS_REGISTRY_MIRROR_PORT)
15-
TALOS_REGISTRY_MIRROR_URL = http://$(TALOS_REGISTRY_MIRROR)
15+
TALOS_REGISTRY_MIRROR = [$(TALOS_REGISTRY_MIRROR_HOST)]:$(TALOS_REGISTRY_MIRROR_PORT)
16+
TALOS_REGISTRY_MIRROR_URL_IPV4 = http://$(TALOS_REGISTRY_MIRROR_HOST_IPV4):$(TALOS_REGISTRY_MIRROR_PORT)
17+
TALOS_REGISTRY_MIRROR_URL_IPV6 = http://[$(TALOS_REGISTRY_MIRROR_HOST_IPV6)]:$(TALOS_REGISTRY_MIRROR_PORT)
1618

1719
TALOS_LIBVIRT_NETWORK_NAME ?= talos
1820
TALOS_LIBVIRT_NETWORK_XML ?= talos/libvirt-network.xml
@@ -23,6 +25,8 @@ TALOS_LIBVIRT_DOMAIN_XML ?= talos/libvirt-domain.xml
2325

2426
TALOS_CLUSTER_NAME ?= talos
2527
TALOS_CONTROL_PLANE_NODE = $(TALOS_CLUSTER_NAME)-control-plane
28+
TALOS_CONTROL_PLANE_IPV4 = 172.99.99.10
29+
TALOS_CONTROL_PLANE_IPV6 = 2001:db8:99:99::10
2630
TALOS_WORKER_NODE = $(TALOS_CLUSTER_NAME)-worker
2731
TALOS_K8S_VERSION ?= 1.31.9
2832
# DO NOT CHANGE CONTROL PLANE COUNT
@@ -114,12 +118,16 @@ talos-libvirt-init: talos-libvirt-clean
114118
echo ">>> Creating libvirt domain for $${name}..." && \
115119
sudo virsh create --validate "$(TALOS_LIBVIRT_DOMAIN_XML)"; \
116120
done
121+
@$(MAKE) talos-libvirt-wait-address
122+
123+
.PHONY: talos-libvirt-wait-address-%
124+
talos-libvirt-wait-address-%:
117125
@sudo virsh list --name | grep '^$(TALOS_CLUSTER_NAME)-' | while read name; do \
118126
echo ">>> Waiting for interface addresses of libvirt domain $${name}..."; \
119127
while true; do \
120-
ip=$$(sudo virsh domifaddr --full "$${name}" | grep -w vnet0 | grep -iw ipv4 | awk '{print $$NF}' | awk -F/ '{print $$1}'); \
128+
ip=$$(sudo virsh domifaddr --full "$${name}" | grep -w vnet0 | grep -iw $* | awk '{print $$NF}' | awk -F/ '{print $$1}'); \
121129
if [ -z "$${ip}" ]; then \
122-
echo ">>> Waiting for IP address..."; \
130+
echo ">>> Waiting for $* address..."; \
123131
sleep 2; \
124132
else \
125133
echo ">>> IP address $${ip} found."; \
@@ -128,6 +136,9 @@ talos-libvirt-init: talos-libvirt-clean
128136
done; \
129137
done
130138

139+
.PHONY: talos-libvirt-wait-address
140+
talos-libvirt-wait-address: talos-libvirt-wait-address-ipv4
141+
131142
.PHONY: talos-libvirt-clean
132143
talos-libvirt-clean:
133144
@echo ">>> Cleaning up libvirt domains..."
@@ -140,38 +151,46 @@ talos-libvirt-clean:
140151
sudo virsh net-destroy $(TALOS_LIBVIRT_NETWORK_NAME); \
141152
fi
142153

143-
.PHONY: talos-init-%
144-
talos-init-%: talos-libvirt-init talos-prepare-images
145-
$(eval TALOS_CONTROL_PLANE_IP = $(shell sudo virsh domifaddr --full "$(TALOS_CONTROL_PLANE_NODE)" | grep -w vnet0 | grep -iw ipv4 | awk '{print $$NF}' | awk -F/ '{print $$1}'))
146-
$(eval TALOS_ENDPOINT = https://$(TALOS_CONTROL_PLANE_IP):6443)
154+
.PHONY: talos-apply-config-%
155+
talos-apply-config-%:
156+
$(eval TALOS_ENDPOINT_IP_FAMILY = $(shell echo $* | sed 's/dual/ipv4/'))
157+
$(eval TALOS_CONTROL_PLANE_IP = $(TALOS_CONTROL_PLANE_$(shell echo $(TALOS_ENDPOINT_IP_FAMILY) | tr '[:lower:]' '[:upper:]')))
158+
$(eval TALOS_ENDPOINT = https://[$(TALOS_CONTROL_PLANE_IP)]:6443)
159+
$(eval TALOS_REGISTRY_MIRROR_URL = $(TALOS_REGISTRY_MIRROR_URL_$(shell echo $(TALOS_ENDPOINT_IP_FAMILY) | tr '[:lower:]' '[:upper:]')))
147160
@echo ">>> Generating Talos configuration..."
148-
ip_family=$* jinjanate talos/cluster-patch.yaml.j2 -o talos/cluster-patch.yaml
149-
talosctl gen config --force \
161+
ip_family=$* jinjanate talos/cluster-config.yaml.j2 -o talos/cluster-config.yaml
162+
talosctl gen config --force -o talos \
150163
--kubernetes-version "$(TALOS_K8S_VERSION)" \
151164
--registry-mirror docker.io=$(TALOS_REGISTRY_MIRROR_URL) \
152165
--registry-mirror gcr.io=$(TALOS_REGISTRY_MIRROR_URL) \
153166
--registry-mirror ghcr.io=$(TALOS_REGISTRY_MIRROR_URL) \
154167
--registry-mirror registry.k8s.io=$(TALOS_REGISTRY_MIRROR_URL) \
155-
--config-patch "@talos/cluster-patch.yaml" "$(TALOS_CLUSTER_NAME)" "$(TALOS_ENDPOINT)"
156-
mv talosconfig ~/.talos/config
157-
@echo ">>> Applying Talos node configuration..."
168+
--config-patch "@talos/cluster-config.yaml" "$(TALOS_CLUSTER_NAME)" "$(TALOS_ENDPOINT)"
169+
mv talos/talosconfig ~/.talos/config
170+
@echo ">>> Applying Talos node $* configuration..."
158171
@sudo virsh list --name | grep '^$(TALOS_CONTROL_PLANE_NODE)' | while read node; do \
159172
echo ">>>>>> Applying Talos control plane configuration to $${node}..."; \
160173
ip=$$(sudo virsh domifaddr --full "$${node}" | grep -w vnet0 | grep -iw ipv4 | awk '{print $$NF}' | awk -F/ '{print $$1}'); \
161-
ip_family=$* cluster=$(TALOS_CLUSTER_NAME) node=$${node} jinjanate talos/machine-patch.yaml.j2 -o talos/machine-patch.yaml && \
162-
talosctl apply-config --insecure --nodes $${ip} --file controlplane.yaml --config-patch "@talos/machine-patch.yaml"; \
174+
ip_family=$* cluster=$(TALOS_CLUSTER_NAME) node=$${node} jinjanate talos/machine-config.yaml.j2 -o talos/machine-config.yaml && \
175+
talosctl apply-config --insecure --nodes $${ip} --file talos/controlplane.yaml --config-patch "@talos/machine-config.yaml"; \
163176
echo ">>>>>> Talos control plane configuration applied to $${node}."; \
164177
done
165178
@sudo virsh list --name | grep '^$(TALOS_WORKER_NODE)' | while read node; do \
166179
echo ">>>>>> Applying Talos worker configuration to $${node}..."; \
167180
ip=$$(sudo virsh domifaddr --full "$${node}" | grep -w vnet0 | grep -iw ipv4 | awk '{print $$NF}' | awk -F/ '{print $$1}'); \
168-
ip_family=$* cluster=$(TALOS_CLUSTER_NAME) node=$${node} jinjanate talos/machine-patch.yaml.j2 -o talos/machine-patch.yaml && \
169-
talosctl apply-config --insecure --nodes $${ip} --file worker.yaml --config-patch "@talos/machine-patch.yaml"; \
181+
ip_family=$* cluster=$(TALOS_CLUSTER_NAME) node=$${node} jinjanate talos/machine-config.yaml.j2 -o talos/machine-config.yaml && \
182+
talosctl apply-config --insecure --nodes $${ip} --file talos/worker.yaml --config-patch "@talos/machine-config.yaml"; \
170183
echo ">>>>>> Talos worker configuration applied to $${node}."; \
171184
done
185+
@$(MAKE) talos-libvirt-wait-address-$(TALOS_ENDPOINT_IP_FAMILY)
186+
187+
.PHONY: talos-init-%
188+
talos-init-%: talos-libvirt-init talos-prepare-images talos-apply-config-%
189+
$(eval TALOS_ENDPOINT_IP_FAMILY = $(shell echo $* | sed 's/dual/ipv4/'))
190+
$(eval TALOS_CONTROL_PLANE_IP = $(TALOS_CONTROL_PLANE_$(shell echo $(TALOS_ENDPOINT_IP_FAMILY) | tr '[:lower:]' '[:upper:]')))
172191
@echo ">>> Waiting for Talos machines to be ready for bootstrapping..."
173192
@sudo virsh list --name | grep '^$(TALOS_CLUSTER_NAME)-' | while read node; do \
174-
ip=$$(sudo virsh domifaddr --full "$${node}" | grep -w vnet0 | grep -iw ipv4 | awk '{print $$NF}' | awk -F/ '{print $$1}'); \
193+
ip=$$(sudo virsh domifaddr --full "$${node}" | grep -w vnet0 | grep -iw $(TALOS_ENDPOINT_IP_FAMILY) | awk '{print $$NF}' | awk -F/ '{print $$1}'); \
175194
echo ">>>>>> Machine $${node} has an ip address $${ip}."; \
176195
while true; do \
177196
stage=$$(talosctl --endpoints $${ip} --nodes $${ip} get machinestatus -o jsonpath='{.spec.stage}' 2>/dev/null); \
@@ -263,7 +282,7 @@ talos-install: talos-install-prepare
263282
$(MAKE) install-chart
264283

265284
.PHONY: talos-install-%
266-
talos-install-%: talos-install-overlay-$*
285+
talos-install-%: talos-install-overlay-%
267286

268287
.PHONY: talos-install-ipv4
269288
talos-install-ipv4: talos-install-overlay-ipv4

talos/cluster-patch.yaml.j2 renamed to talos/cluster-config.yaml.j2

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,14 @@
22
{%- set ip_family = "ipv4" -%}
33
{%- endif -%}
44
cluster:
5+
discovery:
6+
enabled: false
57
allowSchedulingOnControlPlanes: true
8+
apiServer:
9+
certSANs:
10+
- talos-control-plane
11+
- 172.99.99.10
12+
- 2001:db8:99:99::10
613
controllerManager:
714
extraArgs:
815
{%- if ip_family is equalto "ipv4" %}
@@ -21,7 +28,7 @@ cluster:
2128
- 10.16.0.0/16
2229
{%- endif %}
2330
{%- if ip_family is equalto "ipv6" or ip_family is equalto "dual" %}
24-
- fd00:10:96::/108
31+
- fd00:10:16::/112
2532
{%- endif %}
2633
serviceSubnets:
2734
{%- if ip_family is equalto "ipv4" or ip_family is equalto "dual" %}
@@ -30,4 +37,3 @@ cluster:
3037
{%- if ip_family is equalto "ipv6" or ip_family is equalto "dual" %}
3138
- fd00:10:96::/108
3239
{%- endif %}
33-

talos/libvirt-domain.xml.j2

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@
5353
<model type='virtio'/>
5454
<driver iommu='off'/>
5555
<address type='pci' domain='0x0000' bus='0x00' slot='0x05' function='0x0'/>
56+
{%- if 'control-plane' in name %}
57+
<mac address="aa:bb:cc:dd:ee:ff"/>
58+
{%- endif %}
5659
</interface>
5760
<interface type='network'>
5861
<source network='talos' bridge='talos-virbr0'/>

talos/libvirt-network.xml

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,20 @@
44
<bridge name='talos-virbr0' stp='on' delay='0'/>
55
<ip address='172.99.99.1' prefix='24'>
66
<dhcp>
7-
<range start='172.99.99.11' end='172.99.99.99'/>
7+
<range start='172.99.99.11' end='172.99.99.99'>
8+
<lease expiry='1' unit='hours'/>
9+
</range>
10+
<!-- Use fixed ipv4 address for the control plane node -->
11+
<host mac="aa:bb:cc:dd:ee:ff" ip="172.99.99.10"/>
812
</dhcp>
913
</ip>
1014
<ip family='ipv6' address='2001:db8:99:99::1' prefix='120'>
1115
<dhcp>
12-
<range start='2001:db8:99:99::11' end='2001:db8:99:99::99'/>
16+
<range start='2001:db8:99:99::11' end='2001:db8:99:99::99'>
17+
<lease expiry='1' unit='hours'/>
18+
</range>
19+
<!-- Use fixed ipv6 address for the control plane node -->
20+
<host id="0:3:0:1:aa:bb:cc:dd:ee:ff" ip="2001:db8:99:99::10"/>
1321
</dhcp>
1422
</ip>
1523
</network>

talos/machine-patch.yaml.j2 renamed to talos/machine-config.yaml.j2

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,22 @@
1+
{% macro random_duid_uuid() -%}
2+
{{- "0004" -}}
3+
{%- for i in range(0, 32) -%}
4+
{{- [0,1,2,3,4,5,6,7,8,9,"a","b","c","d","e","f"] | random -}}
5+
{%- endfor -%}
6+
{%- endmacro -%}
7+
{%- set duidv6 = random_duid_uuid() -%}
8+
{%- if 'control-plane' in node -%}
9+
{%- set duidv6 = '00030001aabbccddeeff' -%}
10+
{%- endif -%}
111
{%- if ip_family is not defined -%}
212
{%- set ip_family = "ipv4" -%}
313
{%- endif -%}
414
machine:
515
install:
616
disk: /dev/vda
717
wipe: true
18+
time:
19+
disabled: true
820
kernel:
921
modules:
1022
# the following kernel modules configuration may be unnecessary
@@ -20,8 +32,17 @@ machine:
2032
mtu: 1500
2133
dhcp: true
2234
dhcpOptions:
35+
{%- if ip_family is equalto "ipv4" or ip_family is equalto "dual" %}
2336
ipv4: true
37+
{%- else %}
38+
ipv4: false
39+
{%- endif %}
40+
{%- if ip_family is equalto "ipv6" or ip_family is equalto "dual" %}
2441
ipv6: true
42+
duidv6: {{ duidv6 }}
43+
{%- else %}
44+
ipv6: false
45+
{%- endif %}
2546
- deviceSelector:
2647
busPath: 0000:00:05.1
2748
mtu: 1500

0 commit comments

Comments
 (0)