Skip to content

Commit e982749

Browse files
authored
Merge pull request #2041 from chrischdi/pr-e2e-retry-ipclaim
🐛 hack/e2e.sh: retry getting ipaddress object name
2 parents e06412d + a4fc6b6 commit e982749

File tree

1 file changed

+25
-3
lines changed

1 file changed

+25
-3
lines changed

hack/e2e.sh

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,20 +78,42 @@ function append_api_group() {
7878
echo "${resource}.ipam.metal3.io"
7979
}
8080

81+
function kubectl_get_jsonpath() {
82+
local OBJECT_KIND="${1}"
83+
local OBJECT_NAME="${2}"
84+
local JSON_PATH="${3}"
85+
local n=0
86+
until [ $n -ge 30 ]; do
87+
OUTPUT=$(kubectl --kubeconfig="${KUBECONFIG}" get "$(append_api_group "${OBJECT_KIND}")" "${OBJECT_NAME}" -o=jsonpath="${JSON_PATH}")
88+
if [[ "${OUTPUT}" != "" ]]; then
89+
break
90+
fi
91+
n=$((n + 1))
92+
sleep 1
93+
done
94+
95+
if [[ "${OUTPUT}" == "" ]]; then
96+
echo "Received empty output getting ${JSON_PATH} from ${OBJECT_KIND}/${OBJECT_NAME}" 1>&2
97+
return 1
98+
else
99+
echo "${OUTPUT}"
100+
return 0
101+
fi
102+
}
103+
81104
# Retrieve an IP to be used as the kube-vip IP
82105
KUBECONFIG="/root/ipam-conf/capv-services.conf"
83106
IPCLAIM_NAME="ip-claim-$(openssl rand -hex 20)"
84107
sed "s/IPCLAIM_NAME/${IPCLAIM_NAME}/" "${REPO_ROOT}/hack/ipclaim-template.yaml" | kubectl --kubeconfig=${KUBECONFIG} create -f -
85-
86-
IPADDRESS_NAME=$(kubectl --kubeconfig=${KUBECONFIG} get "$(append_api_group ipclaim)" "${IPCLAIM_NAME}" -o=jsonpath='{@.status.address.name}')
108+
IPADDRESS_NAME=$(kubectl_get_jsonpath ipclaim "${IPCLAIM_NAME}" '{@.status.address.name}')
87109
CONTROL_PLANE_ENDPOINT_IP=$(kubectl --kubeconfig=${KUBECONFIG} get "$(append_api_group ipaddresses)" "${IPADDRESS_NAME}" -o=jsonpath='{@.spec.address}')
88110
export CONTROL_PLANE_ENDPOINT_IP
89111
echo "Acquired Control Plane IP: $CONTROL_PLANE_ENDPOINT_IP"
90112

91113
# Retrieve an IP to be used for the workload cluster in v1a3/v1a4 -> v1b1 upgrade tests
92114
WORKLOAD_IPCLAIM_NAME="workload-ip-claim-$(openssl rand -hex 20)"
93115
sed "s/IPCLAIM_NAME/${WORKLOAD_IPCLAIM_NAME}/" "${REPO_ROOT}/hack/ipclaim-template.yaml" | kubectl --kubeconfig=${KUBECONFIG} create -f -
94-
WORKLOAD_IPADDRESS_NAME=$(kubectl --kubeconfig=${KUBECONFIG} get "$(append_api_group ipclaim)" "${WORKLOAD_IPCLAIM_NAME}" -o=jsonpath='{@.status.address.name}')
116+
WORKLOAD_IPADDRESS_NAME=$(kubectl_get_jsonpath ipclaim "${WORKLOAD_IPCLAIM_NAME}" '{@.status.address.name}')
95117
WORKLOAD_CONTROL_PLANE_ENDPOINT_IP=$(kubectl --kubeconfig=${KUBECONFIG} get "$(append_api_group ipaddresses)" "${WORKLOAD_IPADDRESS_NAME}" -o=jsonpath='{@.spec.address}')
96118
export WORKLOAD_CONTROL_PLANE_ENDPOINT_IP
97119
echo "Acquired Workload Cluster Control Plane IP: $WORKLOAD_CONTROL_PLANE_ENDPOINT_IP"

0 commit comments

Comments
 (0)