Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
## --------------------------------------
Expand Down Expand Up @@ -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
Expand All @@ -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.
Expand Down Expand Up @@ -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

## --------------------------------------
Expand Down
25 changes: 12 additions & 13 deletions scripts/ci-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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}"
Comment thread
CecileRobertMichon marked this conversation as resolved.
# 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"
Expand All @@ -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
Comment thread
CecileRobertMichon marked this conversation as resolved.
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
}

Expand Down
7 changes: 5 additions & 2 deletions scripts/kind-with-registry.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 <<EOF | kubectl apply -f -
cat <<EOF | "${KUBECTL}" --kubeconfig "${REPO_ROOT}/${KIND_CLUSTER_NAME}.kubeconfig" apply -f -
apiVersion: v1
kind: ConfigMap
metadata:
Expand All @@ -68,4 +71,4 @@ data:
help: "https://kind.sigs.k8s.io/docs/user/local-registry/"
EOF

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