Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 78 additions & 1 deletion automation/cluster.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,28 +28,105 @@ OVN_K8S_REPO_COMMIT="b4388c5a8766e35d5ae5d63833fd7ee00cf0592f"
OVN_K8S_REPO_PATH="${SCRIPT_PATH}/_ovn-k8s/"
OVN_K8S_KIND="${SCRIPT_PATH}/_ovn-k8s/contrib"

KIND_LOCAL_REGISTRY_NAME="registry-ovn-k8s"
KIND_LOCAL_REGISTRY_PORT=5000
KIND_LOCAL_REGISTRY_VOLUME="ovn-k8s"

OVN_IMAGE_REMOTE_TAG="ghcr.io/ovn-org/ovn-kubernetes/ovn-kube-f:master"
OVN_IMAGE_TAG="localhost:${KIND_LOCAL_REGISTRY_PORT}/ovn-org/ovn-kubernetes/ovn-kube-f:master"

MULTUS_VERSION="v4.0.2"

if [ ! -d ${OVN_K8S_REPO_PATH} ]; then
git clone ${OVN_K8S_REPO} --branch ${OVN_K8S_BRANCH} --single-branch ${OVN_K8S_REPO_PATH}
pushd ${OVN_K8S_REPO_PATH}
git checkout ${OVN_K8S_REPO_COMMIT}
popd
fi

setup_local_registry() {
if [ "$(${OCI_BIN} inspect -f '{{.State.Running}}' "${KIND_LOCAL_REGISTRY_NAME}" 2>/dev/null || true)" != 'true' ]; then
${OCI_BIN} run -d --restart=always --name "${KIND_LOCAL_REGISTRY_NAME}" \
-p "127.0.0.1:${KIND_LOCAL_REGISTRY_PORT}:5000" \
-v ${KIND_LOCAL_REGISTRY_VOLUME}:/var/lib/registry \
registry:2
fi
}

teardown_local_registry() {
${OCI_BIN} stop ${KIND_LOCAL_REGISTRY_NAME} || true
${OCI_BIN} rm ${KIND_LOCAL_REGISTRY_NAME} || true
}

pull_ovn_k8s_image() {
# pull the image to container runtime registry to enable kind.sh detect and use its digest in ovn-k8s manifests
if ! ${OCI_BIN} inspect "${OVN_IMAGE_TAG}" &> /dev/null; then
${OCI_BIN} pull "${OVN_IMAGE_REMOTE_TAG}"
${OCI_BIN} tag "${OVN_IMAGE_REMOTE_TAG}" "${OVN_IMAGE_TAG}"
fi

# store the image in tests local registry
local -r runtime_registry_tag="docker-daemon:${OVN_IMAGE_TAG}"
local -r local_registry_tag="docker://${OVN_IMAGE_TAG}"
if ! skopeo inspect --tls-verify=false "${local_registry_tag}" &> /dev/null; then
skopeo copy "${runtime_registry_tag}" --dest-tls-verify=false "${local_registry_tag}"
fi
}

copy_image() {
if ! skopeo inspect --tls-verify=false "docker://${2}" &> /dev/null; then
skopeo copy --dest-tls-verify=false "docker://${1}" "docker://${2}"
fi
}

pull_multus_image() {
local -r remote_tag="ghcr.io/k8snetworkplumbingwg/multus-cni:${MULTUS_VERSION}"
local -r local_tag="localhost:${KIND_LOCAL_REGISTRY_PORT}/k8snetworkplumbingwg/multus-cni:${MULTUS_VERSION}"
copy_image "${remote_tag}" "${local_tag}"
}

deploy_multus() {
echo "Deploying Multus.."
curl -L "https://raw.githubusercontent.com/k8snetworkplumbingwg/multus-cni/${MULTUS_VERSION}/deployments/multus-daemonset.yml" | \
sed -e "s?ghcr.io?localhost:${KIND_LOCAL_REGISTRY_PORT}?g" -e "s?:snapshot?:${MULTUS_VERSION}?g" | \
kubectl apply -f -
}

wait_for_multus_ready() {
echo "Waiting for Multus to become ready.."
kubectl rollout status -n kube-system ds/kube-multus-ds --timeout=10m
}

cluster_up() {
setup_local_registry

pull_ovn_k8s_image
pull_multus_image

(
cd "${OVN_K8S_KIND}"
export KIND_LOCAL_REGISTRY_NAME
./kind.sh \
--experimental-provider ${OCI_BIN} \
--num-workers 0 \
--multi-network-enable \
--local-kind-registry \
--ovn-image ${OVN_IMAGE_TAG} \
$(NULL)
)

export KUBECONFIG=~/ovn.conf

deploy_multus

wait_for_multus_ready
}

cluster_down() {
(
cd "${OVN_K8S_KIND}"
./kind.sh --experimental-provider ${OCI_BIN} --delete

teardown_local_registry
)
}

Expand Down