Skip to content
Merged
Show file tree
Hide file tree
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
40 changes: 40 additions & 0 deletions cni-plugin/integration/manifests/calico/setup.sh
Original file line number Diff line number Diff line change
@@ -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
15 changes: 1 addition & 14 deletions cni-plugin/integration/run-ordering.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
29 changes: 14 additions & 15 deletions cni-plugin/integration/run.sh
Original file line number Diff line number Diff line change
@@ -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 "$@"
Comment on lines +10 to +15

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why this change? Previously a missing TEST_CTX was handled gracefully; with this change kubectl config use-context will fail.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking at all of the places it was called (w/in the justfile) TEST_CTX was always provided. So the branching was not required.

It make the script simpler to understand that TEST_CTX was not optional, and we set it for the entire run.

}

function create_test_lab() {
Expand All @@ -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() {
Expand Down Expand Up @@ -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
}

Expand All @@ -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"

Expand Down