Skip to content

Commit 7f7c1b5

Browse files
committed
🏃 support MachinePool clusters in ci-entrypoint.sh
1 parent 9fc12dc commit 7f7c1b5

File tree

14 files changed

+858
-21
lines changed

14 files changed

+858
-21
lines changed

Makefile

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ KUSTOMIZE := $(TOOLS_BIN_DIR)/kustomize
5252
MOCKGEN := $(TOOLS_BIN_DIR)/mockgen
5353
RELEASE_NOTES := $(TOOLS_BIN_DIR)/release-notes
5454
GO_APIDIFF := $(TOOLS_BIN_DIR)/go-apidiff
55-
EXP_DIR := exp
5655

5756
# Define Docker related variables. Releases should modify and double check these vars.
5857
REGISTRY ?= gcr.io/$(shell gcloud config get-value project)
@@ -83,6 +82,10 @@ SKIP_CREATE_MGMT_CLUSTER ?= false
8382
# Build time versioning details.
8483
LDFLAGS := $(shell hack/version.sh)
8584

85+
# Allow overriding the feature gates
86+
FEATURE_GATE_MACHINE_POOL ?= false
87+
FEATURE_GATES_JSON_PATCH := [{"op": "add", "path": "/spec/template/spec/containers/1/args/-", "value": "--feature-gates=MachinePool=$(FEATURE_GATE_MACHINE_POOL)"}]
88+
8689
CLUSTER_TEMPLATE ?= cluster-template.yaml
8790
MANAGED_CLUSTER_TEMPLATE ?= cluster-template-aks.yaml
8891

@@ -350,13 +353,19 @@ create-management-cluster: $(KUSTOMIZE) $(ENVSUBST)
350353
kind load docker-image $(CONTROLLER_IMG)-$(ARCH):$(TAG) --name=capz
351354
$(KUSTOMIZE) build config | $(ENVSUBST) | kubectl apply -f -
352355

353-
# Wait for CAPI pods
354-
kubectl wait --for=condition=Ready --timeout=5m -n capi-system pod -l cluster.x-k8s.io/provider=cluster-api
355-
kubectl wait --for=condition=Ready --timeout=5m -n capi-kubeadm-bootstrap-system pod -l cluster.x-k8s.io/provider=bootstrap-kubeadm
356-
kubectl wait --for=condition=Ready --timeout=5m -n capi-kubeadm-control-plane-system pod -l cluster.x-k8s.io/provider=control-plane-kubeadm
356+
# Patch controllers with feature gates flag
357+
kubectl patch deployment capi-controller-manager -n capi-system --type=json -p='$(FEATURE_GATES_JSON_PATCH)'
358+
kubectl patch deployment capi-kubeadm-bootstrap-controller-manager -n capi-kubeadm-bootstrap-system --type=json -p='$(FEATURE_GATES_JSON_PATCH)'
359+
kubectl patch deployment capz-controller-manager -n capz-system --type=json -p='$(FEATURE_GATES_JSON_PATCH)'
360+
kubectl patch deployment capi-controller-manager -n capi-webhook-system --type=json -p='$(FEATURE_GATES_JSON_PATCH)'
361+
362+
# Wait for CAPI deployments
363+
kubectl wait --for=condition=Available --timeout=5m -n capi-system deployment -l cluster.x-k8s.io/provider=cluster-api
364+
kubectl wait --for=condition=Available --timeout=5m -n capi-kubeadm-bootstrap-system deployment -l cluster.x-k8s.io/provider=bootstrap-kubeadm
365+
kubectl wait --for=condition=Available --timeout=5m -n capi-kubeadm-control-plane-system deployment -l cluster.x-k8s.io/provider=control-plane-kubeadm
357366

358-
# Wait for CAPZ pods
359-
kubectl wait --for=condition=Ready --timeout=5m -n capz-system pod -l cluster.x-k8s.io/provider=infrastructure-azure
367+
# Wait for CAPZ deployments
368+
kubectl wait --for=condition=Available --timeout=5m -n capz-system deployment -l cluster.x-k8s.io/provider=infrastructure-azure
360369

361370
# required sleep for when creating management and workload cluster simultaneously
362371
sleep 10

docs/development.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -335,8 +335,6 @@ To generate the mocks you can run
335335
make generate-go
336336
```
337337

338-
339-
340338
#### E2E Testing
341339

342340
To run E2E locally, set `AZURE_CLIENT_ID`, `AZURE_CLIENT_SECRET`, `AZURE_SUBSCRIPTION_ID`, `AZURE_TENANT_ID` and run:
@@ -377,6 +375,7 @@ You can optionally set the following variables:
377375
| `PARALLEL` | Skip serial tests and set --ginkgo-parallel. |
378376
| `USE_CI_ARTIFACTS` | Use a CI version of Kubernetes, ie. not a released version (eg. `v1.19.0-alpha.1.426+0926c9c47677e9`) |
379377
| `CI_VERSION` | Provide a custom CI version of Kubernetes. By default, the latest master commit will be used. |
378+
| `FEATURE_GATE_MACHINE_POOL` | Use [Machine Pool](topics/machinepools.md) for worker machines. |
380379

381380
You can also customize the configuration of the CAPZ cluster (assuming that `SKIP_CREATE_WORKLOAD_CLUSTER` is not set). See [Customizing the cluster deployment](#customizing-the-cluster-deployment) for more details.
382381

hack/gen-flavors.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,4 @@ find "${flavors_dir}"* -maxdepth 0 -type d -print0 | xargs -0 -I {} basename {}
3030
mv "${root}/templates/cluster-template-default.yaml" "${root}/templates/cluster-template.yaml"
3131

3232
rm -f "${test_dir}cluster-template"*
33-
find "${test_dir}"* -maxdepth 0 -type d -print0 | xargs -0 -I {} basename {} | xargs -I {} sh -c "${kustomize} build --reorder none ${test_dir}{} > ${test_dir}cluster-template-{}.yaml"
33+
find "${test_dir}"* -maxdepth 0 -type d -print0 | xargs -0 -I {} basename {} | grep -v patches | xargs -I {} sh -c "${kustomize} build --load_restrictor none --reorder none ${test_dir}{} > ${test_dir}cluster-template-{}.yaml"

scripts/ci-entrypoint.sh

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,10 @@ create_cluster() {
8282
export CLUSTER_TEMPLATE="test/cluster-template-prow.yaml"
8383
fi
8484

85+
if [[ "${FEATURE_GATE_MACHINE_POOL:-}" == "true" ]]; then
86+
export CLUSTER_TEMPLATE="${CLUSTER_TEMPLATE/prow/prow-machine-pool}"
87+
fi
88+
8589
export CLUSTER_NAME="capz-$(head /dev/urandom | LC_ALL=C tr -dc a-z0-9 | head -c 6 ; echo '')"
8690
# Need a cluster with at least 2 nodes
8791
export CONTROL_PLANE_MACHINE_COUNT=${CONTROL_PLANE_MACHINE_COUNT:-1}
@@ -93,6 +97,19 @@ create_cluster() {
9397
${REPO_ROOT}/hack/create-dev-cluster.sh
9498
}
9599

100+
wait_for_nodes() {
101+
echo "Waiting for ${CONTROL_PLANE_MACHINE_COUNT} control plane machine(s) and ${WORKER_MACHINE_COUNT} worker machine(s) to become Ready"
102+
103+
# Ensure that all nodes are registered with the API server before checking for readiness
104+
local total_nodes="$((${CONTROL_PLANE_MACHINE_COUNT} + ${WORKER_MACHINE_COUNT}))"
105+
while [[ $(kubectl get nodes -ojson | jq '.items | length') -ne "${total_nodes}" ]]; do
106+
sleep 10
107+
done
108+
109+
kubectl wait --for=condition=Ready node --all --timeout=5m
110+
kubectl get nodes -owide
111+
}
112+
96113
run_upstream_e2e_tests() {
97114
# ginkgo regexes
98115
SKIP="${SKIP:-}"
@@ -107,19 +124,11 @@ run_upstream_e2e_tests() {
107124
fi
108125
fi
109126

110-
# get the number of worker nodes
111-
NUM_NODES="$(kubectl get nodes --kubeconfig="$KUBECONFIG" \
112-
-o=jsonpath='{range .items[*]}{.metadata.name}{"\t"}{.spec.taints}{"\n"}{end}' \
113-
| grep -cv "node-role.kubernetes.io/master" )"
114-
115-
# wait for all the nodes to be ready
116-
kubectl wait --for=condition=Ready node --kubeconfig="$KUBECONFIG" --all || true
117-
118127
# setting this env prevents ginkg e2e from trying to run provider setup
119128
export KUBERNETES_CONFORMANCE_TEST="y"
120129
# run the tests
121130
(cd "$(go env GOPATH)/src/k8s.io/kubernetes" && ./hack/ginkgo-e2e.sh \
122-
'--provider=skeleton' "--num-nodes=${NUM_NODES}" \
131+
'--provider=skeleton' \
123132
"--ginkgo.focus=${FOCUS}" "--ginkgo.skip=${SKIP}" \
124133
"--report-dir=${ARTIFACTS}" '--disable-log-dump=true')
125134

@@ -163,6 +172,9 @@ fi
163172
# export the target cluster KUBECONFIG if not already set
164173
export KUBECONFIG="${KUBECONFIG:-${PWD}/kubeconfig}"
165174

175+
export -f wait_for_nodes
176+
timeout --foreground 1800 bash -c wait_for_nodes
177+
166178
# build k8s binaries and run upstream e2e tests
167179
if [[ -z "${SKIP_UPSTREAM_E2E_TESTS:-}" ]]; then
168180
build_k8s

0 commit comments

Comments
 (0)