@@ -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
@@ -133,6 +135,10 @@ select_cluster_template() {
133135
134136create_cluster () {
135137 " ${REPO_ROOT} /hack/create-dev-cluster.sh"
138+ if [ ! -f " ${REPO_ROOT} /${KIND_CLUSTER_NAME} .kubeconfig" ]; then
139+ echo " Unable to find kubeconfig for kind mgmt cluster ${KIND_CLUSTER_NAME} "
140+ exit 1
141+ fi
136142}
137143
138144# get_cidrs derives the CIDR from the Cluster's '.spec.clusterNetwork.pods.cidrBlocks' metadata
@@ -292,22 +298,14 @@ install_addons() {
292298
293299copy_secret () {
294300 # point at the management cluster
295- unset KUBECONFIG
296- " ${KUBECTL} " get secret " ${CLUSTER_NAME} -control-plane-azure-json" -o jsonpath=' {.data.control-plane-azure\.json}' | base64 --decode > azure_json
301+ " ${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
297302
298- # set KUBECONFIG back to the workload cluster
299- export KUBECONFIG=" ${KUBECONFIG:- ${PWD} / kubeconfig} "
303+ # create the secret on the workload cluster
300304 " ${KUBECTL} " create secret generic " ${CONFIG_SECRET_NAME} " -n kube-system \
301305 --from-file=cloud-config=azure_json
302306 rm azure_json
303307}
304308
305- # cleanup all resources we use
306- cleanup () {
307- timeout 1800 " ${KUBECTL} " delete cluster " ${CLUSTER_NAME} " || true
308- make kind-reset || true
309- }
310-
311309on_exit () {
312310 if [[ -n ${KUBECONFIG:- } ]]; then
313311 " ${KUBECTL} " get nodes -o wide || echo " Unable to get nodes"
@@ -318,9 +316,10 @@ on_exit() {
318316 unset KUBECONFIG
319317 go run -tags e2e " ${REPO_ROOT} " /test/logger.go --name " ${CLUSTER_NAME} " --namespace default
320318 " ${REPO_ROOT} /hack/log/redact.sh" || true
321- # cleanup
322- if [[ -z " ${SKIP_CLEANUP:- } " ]]; then
323- cleanup
319+ # cleanup all resources we use
320+ if [[ ! " ${SKIP_CLEANUP:- } " == " true" ]]; then
321+ timeout 1800 " ${KUBECTL} " --kubeconfig " ${REPO_ROOT} /${KIND_CLUSTER_NAME} .kubeconfig" delete cluster " ${CLUSTER_NAME} " || echo " Unable to delete cluster ${CLUSTER_NAME} "
322+ make --directory=" ${REPO_ROOT} " kind-reset || true
324323 fi
325324}
326325
0 commit comments