Skip to content

Commit 8ca2d59

Browse files
add-node using IPv6 address (#4097)
* Fix ipv6 add-node * lint fixes * using ipaddress for checks * Test fix * minor nits, changed back to main
1 parent 7dab3b8 commit 8ca2d59

2 files changed

Lines changed: 14 additions & 3 deletions

File tree

scripts/generate-cni.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ function handle_calico {
3535

3636
sed -i '/Enable or Disable VXLAN on the default IPv6 IP pool./a \ - name: CALICO_IPV6POOL_CIDR' "$CNI_YAML"
3737
sed -i '/CALICO_IPV6POOL_CIDR/a \ value: '"${IPv6_CLUSTER_CIDR}" "$CNI_YAML"
38+
39+
sed -i '/Enable or Disable VXLAN on the default IPv6 IP pool./a \ - name: IP6_AUTODETECTION_METHOD' "$CNI_YAML"
40+
sed -i '/IP6_AUTODETECTION_METHOD/a \ value: "first-found"' "$CNI_YAML"
3841
fi
3942

4043
# Other configuration

scripts/wrappers/join.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import subprocess
1212
import sys
1313
import time
14+
import ipaddress
1415

1516
import click
1617
import requests
@@ -596,7 +597,14 @@ def update_dqlite(cluster_cert, cluster_key, voters, host):
596597
with open("{}/info.yaml".format(cluster_backup_dir)) as f:
597598
data = yaml.safe_load(f)
598599
if "Address" in data:
599-
port = data["Address"].split(":")[1]
600+
port = data["Address"].rsplit(":")[-1]
601+
602+
# If host is an IPv6 address, wrap it in square brackets
603+
try:
604+
if ipaddress.ip_address(host).version == 6:
605+
host = "[{}]".format(host)
606+
except ValueError:
607+
pass
600608

601609
init_data = {"Cluster": voters, "Address": "{}:{}".format(host, port)}
602610
with open("{}/init.yaml".format(cluster_dir), "w") as f:
@@ -640,7 +648,7 @@ def join_dqlite(connection_parts, verify=False, worker=False):
640648
:param connection_parts: connection string parts
641649
"""
642650
token = connection_parts[1]
643-
master_ep = connection_parts[0].split(":")
651+
master_ep = connection_parts[0].rsplit(":", 1)
644652
master_ip = master_ep[0]
645653
master_port = master_ep[1]
646654
fingerprint = None
@@ -825,7 +833,7 @@ def join_etcd(connection_parts, verify=True):
825833
:param connection_parts: connection string parts
826834
"""
827835
token = connection_parts[1]
828-
master_ep = connection_parts[0].split(":")
836+
master_ep = connection_parts[0].rsplit(":", 1)
829837
master_ip = master_ep[0]
830838
master_port = master_ep[1]
831839
callback_token = generate_callback_token()

0 commit comments

Comments
 (0)