Skip to content

Commit 835174a

Browse files
authored
Merge pull request #3235 from k8s-infra-cherrypick-robot/cherry-pick-3213-to-release-1.7
[release-1.7] more explicit delete in ci-entrypoint
2 parents f310144 + b3634c7 commit 835174a

File tree

3 files changed

+22
-18
lines changed

3 files changed

+22
-18
lines changed

Makefile

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,8 @@ LDFLAGS := $(shell hack/version.sh)
175175
CLUSTER_TEMPLATE ?= cluster-template.yaml
176176
MANAGED_CLUSTER_TEMPLATE ?= cluster-template-aks.yaml
177177

178+
export KIND_CLUSTER_NAME ?= capz
179+
178180
## --------------------------------------
179181
## Binaries
180182
## --------------------------------------
@@ -282,7 +284,7 @@ create-management-cluster: $(KUSTOMIZE) $(ENVSUBST) $(KUBECTL) $(KIND) ## Create
282284
curl --retry $(CURL_RETRIES) -sSL https://github.com/kubernetes-sigs/cluster-api/releases/download/v1.3.5/cluster-api-components.yaml | $(ENVSUBST) | $(KUBECTL) apply -f -
283285

284286
# Deploy CAPZ
285-
$(KIND) load docker-image $(CONTROLLER_IMG)-$(ARCH):$(TAG) --name=capz
287+
$(KIND) load docker-image $(CONTROLLER_IMG)-$(ARCH):$(TAG) --name=$(KIND_CLUSTER_NAME)
286288
$(KUSTOMIZE) build config/default | $(ENVSUBST) | $(KUBECTL) apply -f -
287289

288290
# Wait for CAPI deployments
@@ -305,7 +307,7 @@ create-management-cluster: $(KUSTOMIZE) $(ENVSUBST) $(KUBECTL) $(KIND) ## Create
305307
timeout --foreground 300 bash -c "until $(KUBECTL) get clusters -A; do sleep 3; done"
306308
timeout --foreground 300 bash -c "until $(KUBECTL) get azureclusters -A; do sleep 3; done"
307309
timeout --foreground 300 bash -c "until $(KUBECTL) get kubeadmcontrolplanes -A; do sleep 3; done"
308-
@echo 'Set kubectl context to the kind management cluster by running "$(KUBECTL) config set-context kind-capz"'
310+
@echo 'Set kubectl context to the kind management cluster by running "$(KUBECTL) config set-context kind-$(KIND_CLUSTER_NAME)"'
309311

310312
.PHONY: create-workload-cluster
311313
create-workload-cluster: $(ENVSUBST) $(KUBECTL) ## Create a workload cluster.
@@ -721,7 +723,7 @@ delete-cluster: delete-workload-cluster ## Deletes the example kind cluster "ca
721723

722724
.PHONY: kind-reset
723725
kind-reset: ## Destroys the "capz" and "capz-e2e" kind clusters.
724-
$(KIND) delete cluster --name=capz || true
726+
$(KIND) delete cluster --name=$(KIND_CLUSTER_NAME) || true
725727
$(KIND) delete cluster --name=capz-e2e || true
726728

727729
## --------------------------------------

scripts/ci-entrypoint.sh

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ HELM="${REPO_ROOT}/hack/tools/bin/helm"
2929
KIND="${REPO_ROOT}/hack/tools/bin/kind"
3030
KUSTOMIZE="${REPO_ROOT}/hack/tools/bin/kustomize"
3131
make --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
3335
export KUBECTL
3436
export HELM
@@ -129,6 +131,10 @@ select_cluster_template() {
129131

130132
create_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

280286
copy_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-
298296
on_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

scripts/kind-with-registry.sh

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ make --directory="${REPO_ROOT}" "${KUBECTL##*/}" "${KIND##*/}"
2525

2626
# desired cluster name; default is "kind"
2727
KIND_CLUSTER_NAME="${KIND_CLUSTER_NAME:-capz}"
28+
export KIND_CLUSTER_NAME
2829

2930
if [[ "$("${KIND}" get clusters)" =~ .*"${KIND_CLUSTER_NAME}".* ]]; then
3031
echo "cluster already exists, moving on"
@@ -54,9 +55,11 @@ EOF
5455
# (the network may already be connected)
5556
docker network connect "kind" "${reg_name}" || true
5657

58+
"${KIND}" get kubeconfig -n "${KIND_CLUSTER_NAME}" > "${REPO_ROOT}/${KIND_CLUSTER_NAME}.kubeconfig"
59+
5760
# Document the local registry
5861
# https://github.com/kubernetes/enhancements/tree/master/keps/sig-cluster-lifecycle/generic/1755-communicating-a-local-registry
59-
cat <<EOF | kubectl apply -f -
62+
cat <<EOF | "${KUBECTL}" --kubeconfig "${REPO_ROOT}/${KIND_CLUSTER_NAME}.kubeconfig" apply -f -
6063
apiVersion: v1
6164
kind: ConfigMap
6265
metadata:
@@ -68,4 +71,4 @@ data:
6871
help: "https://kind.sigs.k8s.io/docs/user/local-registry/"
6972
EOF
7073

71-
"${KUBECTL}" wait node "${KIND_CLUSTER_NAME}-control-plane" --for=condition=ready --timeout=90s
74+
"${KUBECTL}" --kubeconfig "${REPO_ROOT}/${KIND_CLUSTER_NAME}.kubeconfig" wait node "${KIND_CLUSTER_NAME}-control-plane" --for=condition=ready --timeout=90s

0 commit comments

Comments
 (0)