diff --git a/Makefile b/Makefile index bb6fbf0998e..f5197d23078 100644 --- a/Makefile +++ b/Makefile @@ -175,6 +175,8 @@ LDFLAGS := $(shell hack/version.sh) CLUSTER_TEMPLATE ?= cluster-template.yaml MANAGED_CLUSTER_TEMPLATE ?= cluster-template-aks.yaml +export KIND_CLUSTER_NAME ?= capz + ## -------------------------------------- ## Binaries ## -------------------------------------- @@ -282,7 +284,7 @@ create-management-cluster: $(KUSTOMIZE) $(ENVSUBST) $(KUBECTL) $(KIND) ## Create curl --retry $(CURL_RETRIES) -sSL https://github.com/kubernetes-sigs/cluster-api/releases/download/v1.3.3/cluster-api-components.yaml | $(ENVSUBST) | $(KUBECTL) apply -f - # Deploy CAPZ - $(KIND) load docker-image $(CONTROLLER_IMG)-$(ARCH):$(TAG) --name=capz + $(KIND) load docker-image $(CONTROLLER_IMG)-$(ARCH):$(TAG) --name=$(KIND_CLUSTER_NAME) $(KUSTOMIZE) build config/default | $(ENVSUBST) | $(KUBECTL) apply -f - # Wait for CAPI deployments @@ -305,7 +307,7 @@ create-management-cluster: $(KUSTOMIZE) $(ENVSUBST) $(KUBECTL) $(KIND) ## Create timeout --foreground 300 bash -c "until $(KUBECTL) get clusters -A; do sleep 3; done" timeout --foreground 300 bash -c "until $(KUBECTL) get azureclusters -A; do sleep 3; done" timeout --foreground 300 bash -c "until $(KUBECTL) get kubeadmcontrolplanes -A; do sleep 3; done" - @echo 'Set kubectl context to the kind management cluster by running "$(KUBECTL) config set-context kind-capz"' + @echo 'Set kubectl context to the kind management cluster by running "$(KUBECTL) config set-context kind-$(KIND_CLUSTER_NAME)"' .PHONY: create-workload-cluster create-workload-cluster: $(ENVSUBST) $(KUBECTL) ## Create a workload cluster. @@ -720,7 +722,7 @@ delete-cluster: delete-workload-cluster ## Deletes the example kind cluster "ca .PHONY: kind-reset kind-reset: ## Destroys the "capz" and "capz-e2e" kind clusters. - $(KIND) delete cluster --name=capz || true + $(KIND) delete cluster --name=$(KIND_CLUSTER_NAME) || true $(KIND) delete cluster --name=capz-e2e || true ## -------------------------------------- diff --git a/scripts/ci-entrypoint.sh b/scripts/ci-entrypoint.sh index 1369d50b45e..08b11d11ed7 100755 --- a/scripts/ci-entrypoint.sh +++ b/scripts/ci-entrypoint.sh @@ -29,6 +29,8 @@ HELM="${REPO_ROOT}/hack/tools/bin/helm" KIND="${REPO_ROOT}/hack/tools/bin/kind" KUSTOMIZE="${REPO_ROOT}/hack/tools/bin/kustomize" make --directory="${REPO_ROOT}" "${KUBECTL##*/}" "${HELM##*/}" "${KIND##*/}" "${KUSTOMIZE##*/}" +KIND_CLUSTER_NAME="${KIND_CLUSTER_NAME:-capz}" +export KIND_CLUSTER_NAME # export the variables so they are available in bash -c wait_for_nodes below export KUBECTL export HELM @@ -129,6 +131,10 @@ select_cluster_template() { create_cluster() { "${REPO_ROOT}/hack/create-dev-cluster.sh" + if [ ! -f "${REPO_ROOT}/${KIND_CLUSTER_NAME}.kubeconfig" ]; then + echo "Unable to find kubeconfig for kind mgmt cluster ${KIND_CLUSTER_NAME}" + exit 1 + fi } # get_cidrs derives the CIDR from the Cluster's '.spec.clusterNetwork.pods.cidrBlocks' metadata @@ -279,22 +285,14 @@ install_addons() { copy_secret() { # point at the management cluster - unset KUBECONFIG - "${KUBECTL}" get secret "${CLUSTER_NAME}-control-plane-azure-json" -o jsonpath='{.data.control-plane-azure\.json}' | base64 --decode >azure_json + "${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 - # set KUBECONFIG back to the workload cluster - export KUBECONFIG="${KUBECONFIG:-${PWD}/kubeconfig}" + # create the secret on the workload cluster "${KUBECTL}" create secret generic "${CONFIG_SECRET_NAME}" -n kube-system \ --from-file=cloud-config=azure_json rm azure_json } -# cleanup all resources we use -cleanup() { - timeout 1800 "${KUBECTL}" delete cluster "${CLUSTER_NAME}" || true - make kind-reset || true -} - on_exit() { if [[ -n ${KUBECONFIG:-} ]]; then "${KUBECTL}" get nodes -o wide || echo "Unable to get nodes" @@ -305,9 +303,10 @@ on_exit() { unset KUBECONFIG go run -tags e2e "${REPO_ROOT}"/test/logger.go --name "${CLUSTER_NAME}" --namespace default "${REPO_ROOT}/hack/log/redact.sh" || true - # cleanup - if [[ -z "${SKIP_CLEANUP:-}" ]]; then - cleanup + # cleanup all resources we use + if [[ ! "${SKIP_CLEANUP:-}" == "true" ]]; then + timeout 1800 "${KUBECTL}" --kubeconfig "${REPO_ROOT}/${KIND_CLUSTER_NAME}.kubeconfig" delete cluster "${CLUSTER_NAME}" || echo "Unable to delete cluster ${CLUSTER_NAME}" + make --directory="${REPO_ROOT}" kind-reset || true fi } diff --git a/scripts/kind-with-registry.sh b/scripts/kind-with-registry.sh index 91454ca90ed..7367f794468 100755 --- a/scripts/kind-with-registry.sh +++ b/scripts/kind-with-registry.sh @@ -25,6 +25,7 @@ make --directory="${REPO_ROOT}" "${KUBECTL##*/}" "${KIND##*/}" # desired cluster name; default is "kind" KIND_CLUSTER_NAME="${KIND_CLUSTER_NAME:-capz}" +export KIND_CLUSTER_NAME if [[ "$("${KIND}" get clusters)" =~ .*"${KIND_CLUSTER_NAME}".* ]]; then echo "cluster already exists, moving on" @@ -54,9 +55,11 @@ EOF # (the network may already be connected) docker network connect "kind" "${reg_name}" || true +"${KIND}" get kubeconfig -n "${KIND_CLUSTER_NAME}" > "${REPO_ROOT}/${KIND_CLUSTER_NAME}.kubeconfig" + # Document the local registry # https://github.com/kubernetes/enhancements/tree/master/keps/sig-cluster-lifecycle/generic/1755-communicating-a-local-registry -cat <