Skip to content

Commit

Permalink
cluster-up, kind: add extra port mapping for kind cluster
Browse files Browse the repository at this point in the history
Signed-off-by: howard zhang <[email protected]>
  • Loading branch information
zhlhahaha committed Jan 2, 2025
1 parent 24bc58c commit 22c37a8
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
1 change: 1 addition & 0 deletions cluster-up/cluster/kind-1.28/provider.sh
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ function up() {
cp $KIND_MANIFESTS_DIR/kind.yaml ${KUBEVIRTCI_CONFIG_PATH}/$KUBEVIRT_PROVIDER/kind.yaml
_add_kubeadm_cpu_manager_config_patch
_add_extra_mounts
_add_extra_portmapping
export CONFIG_WORKER_CPU_MANAGER=true
kind_up

Expand Down
1 change: 1 addition & 0 deletions cluster-up/cluster/kind-1.31/provider.sh
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ function up() {
cp $KIND_MANIFESTS_DIR/kind.yaml ${KUBEVIRTCI_CONFIG_PATH}/$KUBEVIRT_PROVIDER/kind.yaml
_add_kubeadm_cpu_manager_config_patch
_add_extra_mounts
_add_extra_portmapping
export CONFIG_WORKER_CPU_MANAGER=true
kind_up

Expand Down
19 changes: 19 additions & 0 deletions cluster-up/cluster/kind/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ CONFIG_WORKER_CPU_MANAGER=${CONFIG_WORKER_CPU_MANAGER:-false}
# avaliable value: ipv4, ipv6, dual
IPFAMILY=${IPFAMILY}

# setup the port mapping for kind cluster, this is needed for some e2e tests
# KIND_PORT_MAPPING=cluster_port:host_port e.g. KIND_PORT_MAPPING=30001:30002
KIND_PORT_MAPPING=${KIND_PORT_MAPPING}

# check CPU arch
PLATFORM=$(uname -m)
case ${PLATFORM} in
Expand Down Expand Up @@ -263,6 +267,21 @@ EOF
fi
}

function _add_extra_portmapping() {
if [[ "$KIND_PORT_MAPPING" != "" ]]; then
IFS=':' read -r container_port host_port <<< "$KIND_PORT_MAPPING"
if [[ -z "$container_port" || -z "$host_port" ]]; then
echo "Invalid KIND_PORT_MAPPING format. Expected 'container_port:host_port'."
exit 1
fi
cat <<EOF >> ${KUBEVIRTCI_CONFIG_PATH}/$KUBEVIRT_PROVIDER/kind.yaml
extraPortMappings:
- containerPort: $container_port
hostPort: $host_port
EOF
fi
}

function _add_kubeadm_cpu_manager_config_patch() {
cat << EOF >> ${KUBEVIRTCI_CONFIG_PATH}/$KUBEVIRT_PROVIDER/kind.yaml
kubeadmConfigPatches:
Expand Down

0 comments on commit 22c37a8

Please sign in to comment.