diff --git a/cni-plugin/integration/manifests/calico/setup.sh b/cni-plugin/integration/manifests/calico/setup.sh new file mode 100755 index 00000000..a0d82694 --- /dev/null +++ b/cni-plugin/integration/manifests/calico/setup.sh @@ -0,0 +1,40 @@ +#!/usr/bin/env bash +set -euo pipefail + +# setup.sh - Setup a calico cluster as per the instructions: +# https://k3d.io/v5.8.3/usage/advanced/calico/#1-create-the-cluster-without-flannel +# +# 1. ensure the kube config current context is set +# 2. install the calico tigera operator + poll/wait for deployment +# 3. install calico CRDs + poll/wait for availability +# 4. poll/wait for calico kube controllers and node rollout +printf '# calico/setup.sh\n' + +kube_ctx=$(kubectl config current-context 2>/dev/null) +if [ -z "${kube_ctx}" ]; +then + printf "%s requires current context be set\n" "${BASH_SOURCE[0]}" + exit 1 +fi + +kubectl apply -f https://raw.githubusercontent.com/projectcalico/calico/v3.31.0/manifests/tigera-operator.yaml +kubectl --namespace tigera-operator rollout status --timeout=5m deploy/tigera-operator + +until kubectl apply -f https://raw.githubusercontent.com/projectcalico/calico/v3.31.0/manifests/custom-resources.yaml 1>/dev/null 2>&1; do + echo "retrying calico custom resources installation..." + sleep 2 +done +for resource in apiserver calico goldmane ippools whisker; do + until kubectl wait --for=condition=available --timeout=120s tigerastatus "$resource" 1>/dev/null 2>&1; do + echo "retrying tigerastatus/$resource availability check..." + sleep 2 + done +done +for rollout in deployment/calico-kube-controllers daemonset/calico-node; +do + until kubectl rollout status --namespace calico-system --timeout=2m "${rollout}" 1>/dev/null 2>&1; + do + echo "retry calico-system/${rollout} rollout check..." + sleep 2 + done +done diff --git a/cni-plugin/integration/run-ordering.sh b/cni-plugin/integration/run-ordering.sh index 8548f21e..f1df8882 100755 --- a/cni-plugin/integration/run-ordering.sh +++ b/cni-plugin/integration/run-ordering.sh @@ -9,20 +9,7 @@ NODE_NAME=l5d-server-extra kubectl config use-context "k3d-$K3D_CLUSTER_NAME" printf '\n# Install calico and linkerd-cni...\n' -# Install calico per instructions from https://k3d.io/v5.8.3/usage/advanced/calico/#1-create-the-cluster-without-flannel -kubectl apply -f https://raw.githubusercontent.com/projectcalico/calico/v3.31.0/manifests/tigera-operator.yaml -kubectl --namespace tigera-operator rollout status --timeout=5m deploy/tigera-operator -until kubectl apply -f https://raw.githubusercontent.com/projectcalico/calico/v3.31.0/manifests/custom-resources.yaml; do - echo "retrying calico custom resources installation..." - sleep 5 -done -for tigerastatus_name in apiserver calico goldmane ippools whisker; do - until kubectl wait --for=condition=available --timeout=120s tigerastatus "$tigerastatus_name"; do - echo "retrying tigerastatus/$tigerastatus_name availability check..." - sleep 5 - done -done - +manifests/calico/setup.sh kubectl apply -f manifests/calico/linkerd-cni.yaml printf '\n# Label node and then add node selectors to calico and linkerd-cni to run only on the current node...\n' diff --git a/cni-plugin/integration/run.sh b/cni-plugin/integration/run.sh index 3b51339a..dde6d896 100755 --- a/cni-plugin/integration/run.sh +++ b/cni-plugin/integration/run.sh @@ -1,19 +1,18 @@ #!/usr/bin/env bash -set -euxo pipefail +set -euo pipefail cd "${BASH_SOURCE[0]%/*}" SCENARIO=${CNI_TEST_SCENARIO:-flannel} IPTABLES_MODE=${IPTABLES_MODE:-legacy} -# Run kubectl with the correct context. +# TEST_CTX must be set in the environment prior to running this script +kubectl config use-context "${TEST_CTX}" + +# Run kubectl function k() { - if [ -n "${TEST_CTX:-}" ]; then - kubectl --context="$TEST_CTX" "$@" - else - kubectl "$@" - fi + kubectl "$@" } function create_test_lab() { @@ -28,6 +27,13 @@ function create_test_lab() { do envsubst < "$f" | k apply -f - done + setup_file="./manifests/${SCENARIO}/setup.sh" + if [ -x "${setup_file}" ]; + then + # executing the setup file will initialize local kubernetes for the test + # run as per the scenario. + "${setup_file}" + fi } function cleanup() { @@ -56,7 +62,7 @@ function wait_rollout() { echo "!! $name didn't rollout properly, printing logs"; k describe "$name" -n "$ns"|| echo "$name not found" k logs "$name" -n "$ns" || echo "logs not found for $name" - exit $? + exit 1 fi } @@ -69,13 +75,6 @@ fi create_test_lab -# If installing Calico, need to wait for it to roll first, otherwise pods will -# be blocked (e.g pods for linkerd-cni) -if [ "$SCENARIO" == "calico" ]; then - wait_rollout "deploy/calico-kube-controllers" "kube-system" "2m" - wait_rollout "daemonset/calico-node" "kube-system" "2m" -fi - # Wait for linkerd-cni daemonset to complete wait_rollout "daemonset/linkerd-cni" "linkerd-cni" "30s"