Skip to content

Commit 0367ec8

Browse files
committed
ci: add ipv6 support to storage network pipeline and fix multus misconfiguration
Signed-off-by: Yang Chiu <yang.chiu@suse.com>
1 parent e79cc96 commit 0367ec8

13 files changed

Lines changed: 278 additions & 43 deletions

File tree

pipelines/storage_network/Jenkinsfile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ def REGISTRY_URL = ""
1818
// parameter for hdd test
1919
def USE_HDD = params.USE_HDD ? params.USE_HDD : false
2020

21+
def NETWORK_STACK = params.NETWORK_STACK ? params.NETWORK_STACK : "ipv4"
22+
2123
node {
2224

2325
withCredentials([
@@ -82,6 +84,7 @@ node {
8284
--env TF_VAR_mtu=${MTU_SIZE} \
8385
--env TF_VAR_multus_version=${MULTUS_VERSION} \
8486
--env TF_VAR_thick_plugin=${THICK_PLUGIN} \
87+
--env TF_VAR_network_stack="${NETWORK_STACK}" \
8588
${imageName}
8689
"""
8790
}
@@ -97,7 +100,7 @@ node {
97100
}
98101

99102
stage ('download support bundle') {
100-
sh "docker exec ${JOB_BASE_NAME}-${BUILD_NUMBER} pipelines/storage_network/scripts/download-support-bundle.sh ${JOB_BASE_NAME}-${BUILD_NUMBER}-bundle.zip"
103+
sh "docker exec ${JOB_BASE_NAME}-${BUILD_NUMBER} pipelines/storage_network/scripts/download-support-bundle.sh ${JOB_BASE_NAME}-${BUILD_NUMBER}-bundle.zip"
101104
sh "docker cp ${JOB_BASE_NAME}-${BUILD_NUMBER}:${WORKSPACE}/${JOB_BASE_NAME}-${BUILD_NUMBER}-bundle.zip ."
102105
archiveArtifacts allowEmptyArchive: true, artifacts: '**/*.zip', followSymlinks: false
103106
}

pipelines/storage_network/scripts/download-support-bundle.sh

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#!/usr/bin/env bash
22

3+
source pipelines/utilities/longhorn_ui.sh
4+
35
set -e
46

57
SUPPORT_BUNDLE_FILE_NAME=${1:-"lh-support-bundle.zip"}
@@ -10,10 +12,6 @@ set_kubeconfig_envvar(){
1012
export KUBECONFIG="${PWD}/pipelines/storage_network/terraform/k3s.yaml"
1113
}
1214

13-
export_longhorn_ui_url(){
14-
export LONGHORN_CLIENT_URL="http://$(cat /tmp/controlplane_public_ip):30000"
15-
}
16-
1715
set_kubeconfig_envvar
1816
export_longhorn_ui_url
1917

@@ -27,7 +25,7 @@ SUPPORT_BUNDLE_READY=false
2725
while [[ ${SUPPORT_BUNDLE_READY} == false ]]; do
2826
PERCENT=`kubectl exec -n longhorn-system svc/longhorn-frontend -- curl -H 'Accept: application/json' ${SUPPORT_BUNDLE_URL} | jq -r '.progressPercentage' || true`
2927
echo ${PERCENT}
30-
28+
3129
if [[ ${PERCENT} == 100 ]]; then SUPPORT_BUNDLE_READY=true; fi
3230
done
3331

pipelines/storage_network/scripts/longhorn-setup.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,11 @@ source pipelines/utilities/create_aws_secret.sh
88
source pipelines/utilities/create_registry_secret.sh
99
source pipelines/utilities/install_backupstores.sh
1010
source pipelines/utilities/storage_network.sh
11+
source pipelines/utilities/coredns.sh
1112
source pipelines/utilities/create_longhorn_namespace.sh
1213
source pipelines/utilities/longhorn_manifest.sh
14+
source pipelines/utilities/longhorn_status.sh
15+
source pipelines/utilities/longhorn_ui.sh
1316
source pipelines/utilities/run_longhorn_test.sh
1417

1518
# create and clean tmpdir
@@ -44,6 +47,9 @@ main(){
4447
fi
4548
deploy_network_attachment_definition
4649

50+
patch_coredns_ipv6_name_servers
51+
scale_up_coredns
52+
4753
create_longhorn_namespace
4854
install_backupstores
4955
setup_azurite_backup_store
@@ -55,7 +61,13 @@ main(){
5561
customize_longhorn_manifest_registry
5662
install_longhorn
5763

64+
setup_longhorn_ui_nodeport
65+
export_longhorn_ui_url
66+
5867
update_storage_network_setting
68+
# instance manager pods should restart after the storage network setting applied
69+
wait_longhorn_status_running
70+
validate_storage_network_setting_taking_effect
5971

6072
run_longhorn_test
6173
}

pipelines/storage_network/scripts/terraform-setup.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,6 @@ for id in ${NETWORK_INTERFACE_IDS}; do
1010
aws ec2 modify-network-interface-attribute --network-interface-id "${id}" --no-source-dest-check
1111
done
1212

13+
terraform -chdir=pipelines/storage_network/terraform output -raw controlplane_public_ip > /tmp/controlplane_public_ip
14+
1315
exit $?

pipelines/storage_network/terraform/data.tf

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@ data "aws_ami" "aws_ami_sles" {
1212
data "template_file" "provision_k3s_server" {
1313
template = var.k8s_distro_name == "k3s" ? file("${path.module}/user-data-scripts/provision_k3s_server.sh.tpl") : null
1414
vars = {
15+
network_stack = var.network_stack
16+
control_plane_ipv4 = aws_eip.aws_eip[0].public_ip
1517
k3s_cluster_secret = random_password.cluster_secret.result
16-
k3s_server_public_ip = aws_eip.aws_eip[0].public_ip
1718
k3s_version = var.k8s_distro_version
1819
thick_plugin = var.thick_plugin
1920
}
@@ -23,6 +24,7 @@ data "template_file" "provision_k3s_server" {
2324
data "template_file" "provision_k3s_agent" {
2425
template = var.k8s_distro_name == "k3s" ? file("${path.module}/user-data-scripts/provision_k3s_agent.sh.tpl") : null
2526
vars = {
27+
network_stack = var.network_stack
2628
k3s_server_url = "https://${aws_eip.aws_eip[0].public_ip}:6443"
2729
k3s_cluster_secret = random_password.cluster_secret.result
2830
k3s_version = var.k8s_distro_version
@@ -48,5 +50,8 @@ data "template_file" "routes" {
4850
N1 = aws_network_interface.instance_eth1[0].private_ip
4951
N2 = aws_network_interface.instance_eth1[1].private_ip
5052
N3 = aws_network_interface.instance_eth1[2].private_ip
53+
N1_v6 = aws_network_interface.instance_eth1[0].ipv6_address_list[0]
54+
N2_v6 = aws_network_interface.instance_eth1[1].ipv6_address_list[0]
55+
N3_v6 = aws_network_interface.instance_eth1[2].ipv6_address_list[0]
5156
}
5257
}

pipelines/storage_network/terraform/main.tf

Lines changed: 44 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ resource "random_password" "cluster_secret" {
2828
resource "aws_vpc" "aws_vpc" {
2929
cidr_block = "10.0.0.0/16"
3030

31+
assign_generated_ipv6_cidr_block = true
32+
enable_dns_support = true
33+
enable_dns_hostnames = true
34+
3135
tags = {
3236
Name = "${var.aws_vpc_name}-${random_string.random_suffix.id}"
3337
Owner = var.resources_owner
@@ -55,16 +59,23 @@ resource "aws_route_table" "aws_public_rt" {
5559
gateway_id = aws_internet_gateway.aws_igw.id
5660
}
5761

62+
route {
63+
ipv6_cidr_block = "::/0"
64+
gateway_id = aws_internet_gateway.aws_igw.id
65+
}
66+
5867
tags = {
5968
Name = "lh_aws_public_rt-${random_string.random_suffix.id}"
6069
Owner = var.resources_owner
6170
}
6271
}
6372

6473
resource "aws_subnet" "aws_subnet_1" {
65-
vpc_id = aws_vpc.aws_vpc.id
66-
availability_zone = "us-east-1c"
67-
cidr_block = "10.0.1.0/24"
74+
vpc_id = aws_vpc.aws_vpc.id
75+
availability_zone = "us-east-1c"
76+
cidr_block = "10.0.1.0/24"
77+
ipv6_cidr_block = cidrsubnet(aws_vpc.aws_vpc.ipv6_cidr_block, 8, 0)
78+
assign_ipv6_address_on_creation = true
6879

6980
tags = {
7081
Name = "lh_subnet_1-${random_string.random_suffix.id}"
@@ -73,9 +84,11 @@ resource "aws_subnet" "aws_subnet_1" {
7384
}
7485

7586
resource "aws_subnet" "aws_subnet_2" {
76-
vpc_id = aws_vpc.aws_vpc.id
77-
availability_zone = "us-east-1c"
78-
cidr_block = "10.0.2.0/24"
87+
vpc_id = aws_vpc.aws_vpc.id
88+
availability_zone = "us-east-1c"
89+
cidr_block = "10.0.2.0/24"
90+
ipv6_cidr_block = cidrsubnet(aws_vpc.aws_vpc.ipv6_cidr_block, 8, 1)
91+
assign_ipv6_address_on_creation = true
7992

8093
tags = {
8194
Name = "lh_subnet_2-${random_string.random_suffix.id}"
@@ -109,19 +122,19 @@ resource "aws_security_group" "aws_secgrp" {
109122
vpc_id = aws_vpc.aws_vpc.id
110123

111124
ingress {
112-
description = "Allow SSH"
113-
from_port = 22
114-
to_port = 22
115-
protocol = "tcp"
125+
description = "Allow all ports"
126+
from_port = 0
127+
to_port = 0
128+
protocol = "-1"
116129
cidr_blocks = ["0.0.0.0/0"]
117130
}
118131

119132
ingress {
120-
description = "Allow all ports"
133+
description = "Allow all ports over IPv6"
121134
from_port = 0
122135
to_port = 0
123136
protocol = "-1"
124-
cidr_blocks = ["0.0.0.0/0"]
137+
ipv6_cidr_blocks = ["::/0"]
125138
}
126139

127140
egress {
@@ -131,6 +144,13 @@ resource "aws_security_group" "aws_secgrp" {
131144
cidr_blocks = ["0.0.0.0/0"]
132145
}
133146

147+
egress {
148+
from_port = 0
149+
to_port = 0
150+
protocol = "-1"
151+
ipv6_cidr_blocks = ["::/0"]
152+
}
153+
134154
tags = {
135155
Name = "lh_aws_secgrp-${random_string.random_suffix.id}"
136156
Owner = var.resources_owner
@@ -145,6 +165,7 @@ resource "aws_key_pair" "aws_pair_key" {
145165
resource "aws_network_interface" "instance_eth0" {
146166
subnet_id = aws_subnet.aws_subnet_1.id
147167
security_groups = [aws_security_group.aws_secgrp.id]
168+
ipv6_address_count = 1
148169

149170
count = var.aws_instance_count
150171

@@ -195,6 +216,7 @@ resource "aws_network_interface" "instance_eth1" {
195216

196217
subnet_id = aws_subnet.aws_subnet_2.id
197218
security_groups = [aws_security_group.aws_secgrp.id]
219+
ipv6_address_count = 1
198220

199221
count = var.aws_instance_count
200222

@@ -257,7 +279,16 @@ resource "null_resource" "rsync_kubeconfig_file" {
257279
}
258280

259281
provisioner "local-exec" {
260-
command = "rsync -aPvz --rsync-path=\"sudo rsync\" -e \"ssh -o StrictHostKeyChecking=no -l ec2-user -i ${var.aws_ssh_private_key_file_path}\" ${aws_eip.aws_eip[0].public_ip}:/etc/rancher/k3s/k3s.yaml . && sed -i 's#https://127.0.0.1:6443#https://${aws_eip.aws_eip[0].public_ip}:6443#' k3s.yaml"
282+
command = <<EOT
283+
export K3S_SERVER_IP=$(
284+
[ "${var.network_stack}" = "ipv6" ] && echo "[${aws_instance.aws_instance[0].ipv6_addresses[0]}]" || echo ${aws_eip.aws_eip[0].public_ip}
285+
)
286+
export LOCAL_IP=$(
287+
[ "${var.network_stack}" = "ipv6" ] && echo "\[::1\]" || echo "127.0.0.1"
288+
)
289+
rsync -aPvz --rsync-path="sudo rsync" -e "ssh -o StrictHostKeyChecking=no -l ec2-user -i ${var.aws_ssh_private_key_file_path}" "${aws_eip.aws_eip[0].public_ip}:/etc/rancher/k3s/k3s.yaml" . && \
290+
sed -i "s#https://$LOCAL_IP:6443#https://$K3S_SERVER_IP:6443#" k3s.yaml
291+
EOT
261292
}
262293
}
263294

pipelines/storage_network/terraform/output.tf

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,12 @@ output "network_interface_ids" {
44
aws_network_interface.instance_eth1
55
]
66
value = join(" ", concat(aws_network_interface.instance_eth0[*].id, aws_network_interface.instance_eth1[*].id))
7-
}
7+
}
8+
9+
output "controlplane_public_ip" {
10+
depends_on = [
11+
aws_eip.aws_eip,
12+
aws_instance.aws_instance
13+
]
14+
value = var.network_stack == "ipv6" ? "[${aws_instance.aws_instance[0].ipv6_addresses[0]}]" : aws_eip.aws_eip[0].public_ip
15+
}

pipelines/storage_network/terraform/user-data-scripts/flannel.sh.tpl

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#!/bin/bash
22
STORAGE_NETWORK_PREFIX="192.168"
3+
STORAGE_NETWORK_PREFIX_V6="fd00:168"
34

45
ETH1_IP=`ip a | grep eth1 | grep -Eo 'inet (addr:)?([0-9]*\.){3}[0-9]*' | awk '{print $2}'`
56

@@ -16,4 +17,11 @@ FLANNEL_NETWORK=$STORAGE_NETWORK_PREFIX.0.0/16
1617
FLANNEL_SUBNET=$STORAGE_NETWORK_PREFIX.$NET.0/24
1718
FLANNEL_MTU=${mtu}
1819
FLANNEL_IPMASQ=true
19-
EOF
20+
EOF
21+
22+
cat << EOF | sudo tee -a /run/flannel/multus-subnet-$STORAGE_NETWORK_PREFIX_V6.0.0.env
23+
FLANNEL_NETWORK=$STORAGE_NETWORK_PREFIX_V6::/48
24+
FLANNEL_SUBNET=$STORAGE_NETWORK_PREFIX_V6:$NET::/64
25+
FLANNEL_MTU=${mtu}
26+
FLANNEL_IPMASQ=false
27+
EOF

pipelines/storage_network/terraform/user-data-scripts/provision_k3s_agent.sh.tpl

Lines changed: 40 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ set -e
55
sudo systemctl restart guestregister # Sometimes registration fails on first boot.
66
sudo zypper ref
77
sudo zypper install -y -t pattern devel_basis
8-
sudo zypper install -y open-iscsi nfs-client cryptsetup
8+
sudo zypper install -y open-iscsi nfs-client cryptsetup go
99
sudo systemctl -q enable iscsid
1010
sudo systemctl start iscsid
1111

@@ -30,16 +30,49 @@ fi
3030
# TODO: It looks like "set -e" will break the intended functionality of the remaining code. Consider a refactor.
3131
set +e
3232

33-
until (curl -sfL https://get.k3s.io | INSTALL_K3S_EXEC="agent --token ${k3s_cluster_secret}" K3S_URL="${k3s_server_url}" INSTALL_K3S_VERSION="${k3s_version}" sh -); do
33+
if [[ "${network_stack}" == "ipv6" ]]; then
34+
tee /etc/sysctl.d/99-ipv6.conf > /dev/null <<EOF
35+
net.ipv6.conf.eth0.accept_ra = 2
36+
net.ipv6.conf.eth1.accept_ra = 2
37+
net.ipv6.conf.default.accept_ra = 2
38+
net.ipv6.conf.all.forwarding = 1
39+
net.ipv6.conf.eth1.forwarding = 1
40+
net.ipv6.conf.all.proxy_ndp = 1
41+
net.ipv6.conf.eth0.proxy_ndp = 1
42+
net.ipv6.conf.eth1.proxy_ndp = 1
43+
net.ipv6.conf.cni0.proxy_ndp = 1
44+
EOF
45+
sysctl --system
46+
cat <<EOF > /etc/resolv.conf
47+
nameserver 2606:4700:4700::1111
48+
nameserver 2001:4860:4860::8888
49+
nameserver 8.8.8.8
50+
nameserver 1.1.1.1
51+
EOF
52+
chattr +i /etc/resolv.conf || true
53+
IP=$(ip -6 addr show scope global | awk '/inet6/ && !/fe80/ {print $2}' | cut -d/ -f1 | head -n1)
54+
else
55+
IP=$(hostname -I | awk '{print $1}')
56+
fi
57+
58+
# TODO: It looks like "set -e" will break the intended functionality of the remaining code. Consider a refactor.
59+
set +e
60+
61+
until (curl -sfL https://get.k3s.io | INSTALL_K3S_EXEC="agent --node-ip=$IP --token ${k3s_cluster_secret}" K3S_URL="${k3s_server_url}" INSTALL_K3S_VERSION="${k3s_version}" sh -); do
3462
echo 'k3s agent did not install correctly'
3563
sleep 2
3664
done
3765

3866
if [[ "${thick_plugin}" == true ]]; then
39-
ln -s /var/lib/rancher/k3s/agent/etc/cni/net.d /etc/cni
40-
ln -s /var/lib/rancher/k3s/data/current/bin /opt/cni
67+
mkdir -p /etc/cni
68+
ln -s /var/lib/rancher/k3s/agent/etc/cni/net.d /etc/cni/net.d
69+
mkdir -p /opt/cni
70+
ln -s /var/lib/rancher/k3s/data/cni /opt/cni/bin
4171
fi
4272

43-
curl -OL https://github.com/containernetworking/plugins/releases/download/v1.3.0/cni-plugins-linux-amd64-v1.3.0.tgz
44-
tar -zxvf cni-plugins-linux-amd64-v1.3.0.tgz
45-
cp ipvlan /var/lib/rancher/k3s/data/current/bin/
73+
mkdir -p /tmp/gocache
74+
export GOCACHE=/tmp/gocache
75+
git clone https://github.com/c3y1huang/cni-plugins.git
76+
cd cni-plugins
77+
git checkout 6888978
78+
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o /var/lib/rancher/k3s/data/cni/ipvlan ./plugins/main/ipvlan

0 commit comments

Comments
 (0)