Skip to content

Commit

Permalink
Add IPv6 support for network attachements
Browse files Browse the repository at this point in the history
When NETWORK_ISOLATION_IPV6 (default: false) is true, configure the NAD for IPv6.
Likewize NETWORK_ISOLATION_IPV4 (default: true) controls if IPv4 is configured.

Enabling both IPv6 and IPv4 should work for dual stack.

Signed-off-by: Harald Jensås <[email protected]>
  • Loading branch information
hjensas committed Jan 15, 2024
1 parent 7980ed5 commit e69fc20
Show file tree
Hide file tree
Showing 2 changed files with 140 additions and 13 deletions.
12 changes: 12 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ NETWORK_ISOLATION_IPV6 ?= false
NETWORK_MTU ?= 1500
NETWORK_VLAN_START ?= 20
NETWORK_VLAN_STEP ?= 1
NETWORK_ISOLATION_IPV4_ADDRESS ?= 172.16.1.1/24
NETWORK_ISOLATION_IPV6_ADDRESS ?= fd00:aaaa::1/64

ifeq ($(NETWORK_ISOLATION_USE_DEFAULT_NETWORK), true)
METALLB_POOL ?=192.168.122.80-192.168.122.90
Expand Down Expand Up @@ -2014,6 +2016,16 @@ ifeq ($(NETWORK_BGP), true)
netattach: export INTERFACE_BGP_1=${NNCP_BGP_1_INTERFACE}
netattach: export INTERFACE_BGP_2=${NNCP_BGP_2_INTERFACE}
endif
ifeq ($(NETWORK_ISOLATION_IPV4), true)
netattach: export IPV4_ENABLED=true
netattach: export CTLPLANE_IP_ADDRESS_PREFIX=${NNCP_CTLPLANE_IP_ADDRESS_PREFIX}
netattach: export CTLPLANE_IP_ADDRESS_SUFFIX=${NNCP_CTLPLANE_IP_ADDRESS_SUFFIX}
endif
ifeq ($(NETWORK_ISOLATION_IPV6), true)
netattach: export IPV6_ENABLED=true
netattach: export CTLPLANE_IPV6_ADDRESS_PREFIX=${NNCP_CTLPLANE_IPV6_ADDRESS_PREFIX}
netattach: export CTLPLANE_IPV6_ADDRESS_SUFFIX=${NNCP_CTLPLANE_IPV6_ADDRESS_SUFFIX}
endif
netattach: export VLAN_START=${NETWORK_VLAN_START}
netattach: export VLAN_STEP=${NETWORK_VLAN_STEP}
netattach: export CTLPLANE_IP_ADDRESS_PREFIX=${NNCP_CTLPLANE_IP_ADDRESS_PREFIX}
Expand Down
141 changes: 128 additions & 13 deletions scripts/gen-netatt.sh
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,14 @@ echo DEPLOY_DIR ${DEPLOY_DIR}
echo INTERFACE ${INTERFACE}
echo VLAN_START ${VLAN_START}
echo VLAN_STEP ${VLAN_STEP}
echo CTLPLANE_IP_ADDRESS_PREFIX ${CTLPLANE_IP_ADDRESS_PREFIX}
if [ -n "$IPV4_ENABLED" ]; then
echo CTLPLANE_IP_ADDRESS_PREFIX ${CTLPLANE_IP_ADDRESS_PREFIX}
echo CTLPLANE_IP_ADDRESS_SUFFIX ${CTLPLANE_IP_ADDRESS_SUFFIX}
fi
if [ -n "$IPV6_ENABLED" ]; then
echo echo CTLPLANE_IPV6_ADDRESS_PREFIX ${CTLPLANE_IPV6_ADDRESS_PREFIX}
echo CTLPLANE_IPV6_ADDRESS_SUFFIX ${CTLPLANE_IPV6_ADDRESS_SUFFIX}
fi

cat > ${DEPLOY_DIR}/ctlplane.yaml <<EOF_CAT
apiVersion: k8s.cni.cncf.io/v1
Expand All @@ -62,9 +69,36 @@ spec:
"master": "${BRIDGE_NAME}",
"ipam": {
"type": "whereabouts",
"range": "${CTLPLANE_IP_ADDRESS_PREFIX}.0/24",
"range_start": "${CTLPLANE_IP_ADDRESS_PREFIX}.30",
"range_end": "${CTLPLANE_IP_ADDRESS_PREFIX}.70"
"ipRanges": [
EOF_CAT
if [ -n "$IPV4_ENABLED" ]; then
cat >> ${DEPLOY_DIR}/ctlplane.yaml <<EOF_CAT
{
"range": "${CTLPLANE_IP_ADDRESS_PREFIX}.0/24",
"range_start": "${CTLPLANE_IP_ADDRESS_PREFIX}.30",
"range_end": "${CTLPLANE_IP_ADDRESS_PREFIX}.70"
EOF_CAT
fi
if [ -n "$IPV4_ENABLED" ] && [ -n "$IPV6_ENABLED" ]; then
cat >> ${DEPLOY_DIR}/ctlplane.yaml <<EOF_CAT
},
EOF_CAT
elif [ -n "$IPV4_ENABLED" ] && [ -z "$IPV6_ENABLED" ]; then
cat >> ${DEPLOY_DIR}/ctlplane.yaml <<EOF_CAT
}
EOF_CAT
fi
if [ -n "$IPV6_ENABLED" ]; then
cat >> ${DEPLOY_DIR}/ctlplane.yaml <<EOF_CAT
{
"range": "${CTLPLANE_IPV6_ADDRESS_PREFIX}0/64",
"range_start": "${CTLPLANE_IPV6_ADDRESS_PREFIX}30",
"range_end": "${CTLPLANE_IPV6_ADDRESS_PREFIX}70"
}
EOF_CAT
fi
cat >> ${DEPLOY_DIR}/ctlplane.yaml <<EOF_CAT
]
}
}
EOF_CAT
Expand All @@ -86,9 +120,36 @@ spec:
"master": "${INTERFACE}.${VLAN_START}",
"ipam": {
"type": "whereabouts",
"range": "172.17.0.0/24",
"range_start": "172.17.0.30",
"range_end": "172.17.0.70"
"ipRanges": [
EOF_CAT
if [ -n "$IPV4_ENABLED" ]; then
cat >> ${DEPLOY_DIR}/internalapi.yaml <<EOF_CAT
{
"range": "172.17.0.0/24",
"range_start": "172.17.0.30",
"range_end": "172.17.0.70"
EOF_CAT
fi
if [ -n "$IPV4_ENABLED" ] && [ -n "$IPV6_ENABLED" ]; then
cat >> ${DEPLOY_DIR}/internalapi.yaml <<EOF_CAT
},
EOF_CAT
elif [ -n "$IPV4_ENABLED" ] && [ -z "$IPV6_ENABLED" ]; then
cat >> ${DEPLOY_DIR}/internalapi.yaml <<EOF_CAT
}
EOF_CAT
fi
if [ -n "$IPV6_ENABLED" ]; then
cat >> ${DEPLOY_DIR}/internalapi.yaml <<EOF_CAT
{
"range": "fd00:bbbb::/64",
"range_start": "fd00:bbbb::30",
"range_end": "fd00:bbbb::70"
}
EOF_CAT
fi
cat >> ${DEPLOY_DIR}/internalapi.yaml <<EOF_CAT
]
}
}
EOF_CAT
Expand All @@ -110,9 +171,36 @@ spec:
"master": "${INTERFACE}.$((${VLAN_START}+${VLAN_STEP}))",
"ipam": {
"type": "whereabouts",
"range": "172.18.0.0/24",
"range_start": "172.18.0.30",
"range_end": "172.18.0.70"
"ipRanges": [
EOF_CAT
if [ -n "$IPV4_ENABLED" ]; then
cat >> ${DEPLOY_DIR}/storage.yaml <<EOF_CAT
{
"range": "172.18.0.0/24",
"range_start": "172.18.0.30",
"range_end": "172.18.0.70"
EOF_CAT
fi
if [ -n "$IPV4_ENABLED" ] && [ -n "$IPV6_ENABLED" ]; then
cat >> ${DEPLOY_DIR}/storage.yaml <<EOF_CAT
},
EOF_CAT
elif [ -n "$IPV4_ENABLED" ] && [ -z "$IPV6_ENABLED" ]; then
cat >> ${DEPLOY_DIR}/storage.yaml <<EOF_CAT
}
EOF_CAT
fi
if [ -n "$IPV6_ENABLED" ]; then
cat >> ${DEPLOY_DIR}/storage.yaml <<EOF_CAT
{
"range": "fd00:cccc::/64",
"range_start": "fd00:cccc::30",
"range_end": "fd00:cccc::70"
}
EOF_CAT
fi
cat >> ${DEPLOY_DIR}/storage.yaml <<EOF_CAT
]
}
}
EOF_CAT
Expand All @@ -134,9 +222,36 @@ spec:
"master": "${INTERFACE}.$((${VLAN_START}+$((${VLAN_STEP}*2))))",
"ipam": {
"type": "whereabouts",
"range": "172.19.0.0/24",
"range_start": "172.19.0.30",
"range_end": "172.19.0.70"
"ipRanges": [
EOF_CAT
if [ -n "$IPV4_ENABLED" ]; then
cat >> ${DEPLOY_DIR}/tenant.yaml <<EOF_CAT
{
"range": "172.19.0.0/24",
"range_start": "172.19.0.30",
"range_end": "172.19.0.70"
EOF_CAT
fi
if [ -n "$IPV4_ENABLED" ] && [ -n "$IPV6_ENABLED" ]; then
cat >> ${DEPLOY_DIR}/tenant.yaml <<EOF_CAT
},
EOF_CAT
elif [ -n "$IPV4_ENABLED" ] && [ -z "$IPV6_ENABLED" ]; then
cat >> ${DEPLOY_DIR}/tenant.yaml <<EOF_CAT
}
EOF_CAT
fi
if [ -n "$IPV6_ENABLED" ]; then
cat >> ${DEPLOY_DIR}/tenant.yaml <<EOF_CAT
{
"range": "fd00:dddd::/64",
"range_start": "fd00:dddd::30",
"range_end": "fd00:dddd::70"
}
EOF_CAT
fi
cat >> ${DEPLOY_DIR}/tenant.yaml <<EOF_CAT
]
}
}
EOF_CAT
Expand Down

0 comments on commit e69fc20

Please sign in to comment.