From 4038e4fedef3b3a3f267daeb00c5a687ddf8ea2b Mon Sep 17 00:00:00 2001 From: luoyuanze Date: Fri, 14 Feb 2025 13:52:52 +0800 Subject: [PATCH] fix: Optimize e2e test scripts Signed-off-by: luoyuanze (cherry picked from commit f3ecf5784c7b4f4038d0143fc7e15fa6f16a4c6a) --- hack/cluster.sh | 4 ++-- hack/util.sh | 16 +++++++++++++++- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/hack/cluster.sh b/hack/cluster.sh index b3eab7d62..efe9eb979 100755 --- a/hack/cluster.sh +++ b/hack/cluster.sh @@ -184,8 +184,8 @@ function create_cluster() { docker exec ${clustername}-control-plane /bin/sh -c "cat /etc/kubernetes/admin.conf" | sed -e "s|${clustername}-control-plane|$dockerip|g" -e "/certificate-authority-data:/d" -e "5s/^/ insecure-skip-tls-verify: true\n/" -e "w ${CLUSTER_DIR}/kubeconfig-nodeIp" kubectl --kubeconfig $CLUSTER_DIR/kubeconfig create -f "$CURRENT/calicooperator/tigera-operator.yaml" || $("${REUSE}" -eq "true") - kind export kubeconfig --name "$clustername" - util::wait_for_crd installations.operator.tigera.io + #kind export kubeconfig --name "$clustername" + util::wait_for_crd --kubeconfig $CLUSTER_DIR/kubeconfig installations.operator.tigera.io kubectl --kubeconfig $CLUSTER_DIR/kubeconfig apply -f "${CLUSTER_DIR}"/calicoconfig echo "create cluster ${clustername} success" echo "wait all node ready" diff --git a/hack/util.sh b/hack/util.sh index 8b1cafd07..b65c6b04e 100755 --- a/hack/util.sh +++ b/hack/util.sh @@ -514,11 +514,25 @@ function util::wait_for_crd() { local crd_names=("$@") local timeout=500 local count=0 + local kubeconfig="" + + while [[ $# -gt 0 ]]; do + case "$1" in + --kubeconfig) + kubeconfig="$2" + shift 2 + ;; + *) + crd_names+=("$1") + shift + ;; + esac + done local end=$((SECONDS+timeout)) while [ $SECONDS -lt $end ]; do for crd_name in "${crd_names[@]}"; do - if kubectl get crd "$crd_name"; then + if kubectl ${kubeconfig:+--kubeconfig="$kubeconfig"} get crd "$crd_name" >/dev/null 2>&1; then echo "CRD $crd_name has been stored successfully." # delete crd from waiting list count=$(($count+1))