@@ -29,6 +29,8 @@ HELM="${REPO_ROOT}/hack/tools/bin/helm"
2929KIND=" ${REPO_ROOT} /hack/tools/bin/kind"
3030KUSTOMIZE=" ${REPO_ROOT} /hack/tools/bin/kustomize"
3131make --directory=" ${REPO_ROOT} " " ${KUBECTL##*/ } " " ${HELM##*/ } " " ${KIND##*/ } " " ${KUSTOMIZE##*/ } "
32+ KIND_CLUSTER_NAME=" ${KIND_CLUSTER_NAME:- capz} "
33+ export KIND_CLUSTER_NAME
3234# export the variables so they are available in bash -c wait_for_nodes below
3335export KUBECTL
3436export HELM
@@ -129,6 +131,10 @@ select_cluster_template() {
129131
130132create_cluster () {
131133 " ${REPO_ROOT} /hack/create-dev-cluster.sh"
134+ if [ ! -f " ${REPO_ROOT} /${KIND_CLUSTER_NAME} .kubeconfig" ]; then
135+ echo " Unable to find kubeconfig for kind mgmt cluster ${KIND_CLUSTER_NAME} "
136+ exit 1
137+ fi
132138}
133139
134140# get_cidrs derives the CIDR from the Cluster's '.spec.clusterNetwork.pods.cidrBlocks' metadata
@@ -279,22 +285,14 @@ install_addons() {
279285
280286copy_secret () {
281287 # point at the management cluster
282- unset KUBECONFIG
283- " ${KUBECTL} " get secret " ${CLUSTER_NAME} -control-plane-azure-json" -o jsonpath=' {.data.control-plane-azure\.json}' | base64 --decode > azure_json
288+ " ${KUBECTL} " --kubeconfig " ${REPO_ROOT} /${KIND_CLUSTER_NAME} .kubeconfig" get secret " ${CLUSTER_NAME} -control-plane-azure-json" -o jsonpath=' {.data.control-plane-azure\.json}' | base64 --decode > azure_json
284289
285- # set KUBECONFIG back to the workload cluster
286- export KUBECONFIG=" ${KUBECONFIG:- ${PWD} / kubeconfig} "
290+ # create the secret on the workload cluster
287291 " ${KUBECTL} " create secret generic " ${CONFIG_SECRET_NAME} " -n kube-system \
288292 --from-file=cloud-config=azure_json
289293 rm azure_json
290294}
291295
292- # cleanup all resources we use
293- cleanup () {
294- timeout 1800 " ${KUBECTL} " delete cluster " ${CLUSTER_NAME} " || true
295- make kind-reset || true
296- }
297-
298296on_exit () {
299297 if [[ -n ${KUBECONFIG:- } ]]; then
300298 " ${KUBECTL} " get nodes -o wide || echo " Unable to get nodes"
@@ -305,9 +303,10 @@ on_exit() {
305303 unset KUBECONFIG
306304 go run -tags e2e " ${REPO_ROOT} " /test/logger.go --name " ${CLUSTER_NAME} " --namespace default
307305 " ${REPO_ROOT} /hack/log/redact.sh" || true
308- # cleanup
309- if [[ -z " ${SKIP_CLEANUP:- } " ]]; then
310- cleanup
306+ # cleanup all resources we use
307+ if [[ ! " ${SKIP_CLEANUP:- } " == " true" ]]; then
308+ timeout 1800 " ${KUBECTL} " --kubeconfig " ${REPO_ROOT} /${KIND_CLUSTER_NAME} .kubeconfig" delete cluster " ${CLUSTER_NAME} " || echo " Unable to delete cluster ${CLUSTER_NAME} "
309+ make --directory=" ${REPO_ROOT} " kind-reset || true
311310 fi
312311}
313312
0 commit comments