Skip to content

Commit e0fd9de

Browse files
authored
Merge pull request #617 from chewong/extend-ci-script
🏃extend ci-conformance.sh testing capability
2 parents 2056f2f + f981465 commit e0fd9de

File tree

4 files changed

+245
-12
lines changed

4 files changed

+245
-12
lines changed

docs/development.md

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ To build a kind cluster and start Tilt, just run:
140140
```shell
141141
make tilt-up
142142
```
143-
By default, the Cluster API components deployed by Tilt have experimental features turned off.
143+
By default, the Cluster API components deployed by Tilt have experimental features turned off.
144144
If you would like to enable these features, add `extra_args` as specified in [The Cluster API Book](https://cluster-api.sigs.k8s.io/developer/tilt.html#create-a-tilt-settingsjson-file).
145145

146146
Once your kind management cluster is up and running, you can [deploy a workload cluster](#deploying-a-workload-cluster).
@@ -350,26 +350,33 @@ You can optionally set `AZURE_SSH_PUBLIC_KEY_FILE` to use your own SSH key.
350350
To run Conformance locally, set `AZURE_CLIENT_ID`, `AZURE_CLIENT_SECRET`, `AZURE_SUBSCRIPTION_ID`, `AZURE_TENANT_ID` and run:
351351

352352
```bash
353-
./scripts/ci-conformance.sh
353+
./scripts/ci-entrypoint.sh
354354
```
355355

356356
You can optionally set the following variables:
357357

358-
| Variable | Description |
359-
| --------------------------- | -------------------------------------------------------------------------------------------------------------- |
360-
| `AZURE_SSH_PUBLIC_KEY_FILE` | Use your own SSH key. |
361-
| `SKIP_CREATE_CLUSTER` | Skip cluster creation. |
362-
| `SKIP_TESTS` | Skip running Kubernetes E2E tests. |
358+
| Variable | Description |
359+
|-----------------------------|---------------------------------------------------------------------------------------------------------------|
360+
| `AZURE_SSH_PUBLIC_KEY_FILE` | Use your own SSH key. |
361+
| `SKIP_CREATE_CLUSTER` | Skip cluster creation. |
362+
| `SKIP_UPSTREAM_E2E_TESTS` | Skip running upstream Kubernetes E2E tests. |
363363
| `SKIP_CLEANUP` | Skip deleting the cluster after the tests finish running. |
364-
| `KUBECONFIG` | Provide your existing cluster kubeconfig filepath. If no kubeconfig is provided, `./kubeconfig` will be used. |
365-
| `SKIP` | Regexp for test cases to skip. |
366-
| `FOCUS` | Regexp for which test cases to run. |
364+
| `KUBECONFIG` | Provide your existing cluster kubeconfig filepath. If no kubeconfig is provided, `./kubeconfig` will be used. |
365+
| `SKIP` | Regexp for test cases to skip. |
366+
| `FOCUS` | Regexp for which test cases to run. |
367367
| `PARALLEL` | Skip serial tests and set --ginkgo-parallel. |
368-
| `USE_CI_ARTIFACTS` | Use a CI version of Kubernetes, ie. not a released version (eg. `v1.19.0-alpha.1.426+0926c9c47677e9`) |
369-
| `CI_VERSION` | Provide a custom CI version of Kubernetes. By default, the latest master commit will be used. |
368+
| `USE_CI_ARTIFACTS` | Use a CI version of Kubernetes, ie. not a released version (eg. `v1.19.0-alpha.1.426+0926c9c47677e9`) |
369+
| `CI_VERSION` | Provide a custom CI version of Kubernetes. By default, the latest master commit will be used. |
370370

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

373+
In addition to upstream E2E, you can append custom commands to `./scripts/ci-entrypoint.sh` to run E2E from other projects against a CAPZ cluster:
374+
375+
```bash
376+
export SKIP_UPSTREAM_E2E_TESTS="false"
377+
./scripts/ci-entrypoint.sh bash -c "cd ${GOPATH}/src/github.com/my-org/my-project && make e2e"
378+
```
379+
373380
<!-- References -->
374381

375382
[go]: https://golang.org/doc/install

scripts/ci-entrypoint.sh

Lines changed: 177 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,177 @@
1+
#!/bin/bash
2+
3+
# Copyright 2020 The Kubernetes Authors.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
###############################################################################
18+
19+
# To run locally, set AZURE_CLIENT_ID, AZURE_CLIENT_SECRET, AZURE_SUBSCRIPTION_ID, AZURE_TENANT_ID
20+
21+
set -o errexit
22+
set -o nounset
23+
set -o pipefail
24+
25+
REPO_ROOT=$(dirname "${BASH_SOURCE[0]}")/..
26+
cd "${REPO_ROOT}" || exit 1
27+
28+
# shellcheck source=../hack/ensure-go.sh
29+
source "${REPO_ROOT}/hack/ensure-go.sh"
30+
# shellcheck source=../hack/ensure-kind.sh
31+
source "${REPO_ROOT}/hack/ensure-kind.sh"
32+
# shellcheck source=../hack/ensure-kubectl.sh
33+
source "${REPO_ROOT}/hack/ensure-kubectl.sh"
34+
# shellcheck source=../hack/ensure-kustomize.sh
35+
source "${REPO_ROOT}/hack/ensure-kustomize.sh"
36+
# shellcheck source=../hack/parse-prow-creds.sh
37+
source "${REPO_ROOT}/hack/parse-prow-creds.sh"
38+
39+
random-string() {
40+
cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w ${1:-32} | head -n 1
41+
}
42+
43+
# build Kubernetes E2E binaries
44+
build_k8s() {
45+
# possibly enable bazel build caching before building kubernetes
46+
if [[ "${BAZEL_REMOTE_CACHE_ENABLED:-false}" == "true" ]]; then
47+
create_bazel_cache_rcs.sh || true
48+
fi
49+
50+
pushd "$(go env GOPATH)/src/k8s.io/kubernetes"
51+
52+
# make sure we have e2e requirements
53+
bazel build //cmd/kubectl //test/e2e:e2e.test //vendor/github.com/onsi/ginkgo/ginkgo
54+
55+
# ensure the e2e script will find our binaries ...
56+
mkdir -p "${PWD}/_output/bin/"
57+
cp -f "${PWD}/bazel-bin/test/e2e/e2e.test" "${PWD}/_output/bin/e2e.test"
58+
59+
PATH="$(dirname "$(find "${PWD}/bazel-bin/" -name kubectl -type f)"):${PATH}"
60+
export PATH
61+
62+
# attempt to release some memory after building
63+
sync || true
64+
(echo 1 > /proc/sys/vm/drop_caches) 2>/dev/null || true
65+
66+
popd
67+
}
68+
69+
create_cluster() {
70+
# export cluster template which contains the manifests needed for creating the Azure cluster to run the tests
71+
if [[ -n ${CI_VERSION:-} || -n ${USE_CI_ARTIFACTS:-} ]]; then
72+
KUBERNETES_BRANCH="$(cd $(go env GOPATH)/src/k8s.io/kubernetes && git rev-parse --abbrev-ref HEAD)"
73+
if [[ "${KUBERNETES_BRANCH:-}" =~ "release-" ]]; then
74+
CI_VERSION_URL="https://dl.k8s.io/ci/latest-${KUBERNETES_BRANCH/release-}.txt"
75+
else
76+
CI_VERSION_URL="https://dl.k8s.io/ci/k8s-master.txt"
77+
fi
78+
export CLUSTER_TEMPLATE="test/cluster-template-conformance-ci-version.yaml"
79+
export CI_VERSION="${CI_VERSION:-$(curl -sSL ${CI_VERSION_URL})}"
80+
export KUBERNETES_VERSION="${CI_VERSION}"
81+
else
82+
export CLUSTER_TEMPLATE="test/cluster-template-conformance.yaml"
83+
fi
84+
85+
export CLUSTER_NAME="capz-$(head /dev/urandom | LC_ALL=C tr -dc a-z0-9 | head -c 6 ; echo '')"
86+
# Need a cluster with at least 2 nodes
87+
export CONTROL_PLANE_MACHINE_COUNT=${CONTROL_PLANE_MACHINE_COUNT:-1}
88+
export WORKER_MACHINE_COUNT=${WORKER_MACHINE_COUNT:-2}
89+
export REGISTRY=capz
90+
export JOB_NAME="${JOB_NAME:-"cluster-api-provider-azure-conformance"}"
91+
# timestamp is in RFC-3339 format to match kubetest
92+
export TIMESTAMP=$(date -u '+%Y-%m-%dT%H:%M:%SZ')
93+
${REPO_ROOT}/hack/create-dev-cluster.sh
94+
}
95+
96+
run_upstream_e2e_tests() {
97+
# export the target cluster KUBECONFIG if not already set
98+
export KUBECONFIG="${KUBECONFIG:-${PWD}/kubeconfig}"
99+
# ginkgo regexes
100+
SKIP="${SKIP:-}"
101+
FOCUS="${FOCUS:-"\\[Conformance\\]"}"
102+
# if we set PARALLEL=true, skip serial tests set --ginkgo-parallel
103+
if [[ "${PARALLEL:-false}" == "true" ]]; then
104+
export GINKGO_PARALLEL=y
105+
if [[ -z "${SKIP}" ]]; then
106+
SKIP="\\[Serial\\]"
107+
else
108+
SKIP="\\[Serial\\]|${SKIP}"
109+
fi
110+
fi
111+
112+
# get the number of worker nodes
113+
NUM_NODES="$(kubectl get nodes --kubeconfig="$KUBECONFIG" \
114+
-o=jsonpath='{range .items[*]}{.metadata.name}{"\t"}{.spec.taints}{"\n"}{end}' \
115+
| grep -cv "node-role.kubernetes.io/master" )"
116+
117+
# wait for all the nodes to be ready
118+
kubectl wait --for=condition=Ready node --kubeconfig="$KUBECONFIG" --all || true
119+
120+
# setting this env prevents ginkg e2e from trying to run provider setup
121+
export KUBERNETES_CONFORMANCE_TEST="y"
122+
# run the tests
123+
(cd "$(go env GOPATH)/src/k8s.io/kubernetes" && ./hack/ginkgo-e2e.sh \
124+
'--provider=skeleton' "--num-nodes=${NUM_NODES}" \
125+
"--ginkgo.focus=${FOCUS}" "--ginkgo.skip=${SKIP}" \
126+
"--report-dir=${ARTIFACTS}" '--disable-log-dump=true')
127+
128+
unset KUBECONFIG
129+
unset KUBERNETES_CONFORMANCE_TEST
130+
}
131+
132+
get_logs() {
133+
kubectl logs deploy/capz-controller-manager -n capz-system manager > "${ARTIFACTS}/logs/capz-manager.log" || true
134+
}
135+
136+
# cleanup all resources we use
137+
cleanup() {
138+
timeout 600 kubectl \
139+
delete cluster "${CLUSTER_NAME}" || true
140+
timeout 600 kubectl \
141+
wait --for=delete cluster/"${CLUSTER_NAME}" || true
142+
make kind-reset || true
143+
# clean up e2e.test symlink
144+
(cd "$(go env GOPATH)/src/k8s.io/kubernetes" && rm -f _output/bin/e2e.test) || true
145+
}
146+
147+
on_exit() {
148+
unset KUBECONFIG
149+
get_logs
150+
# cleanup
151+
if [[ -z "${SKIP_CLEANUP:-}" ]]; then
152+
cleanup
153+
fi
154+
}
155+
156+
trap on_exit EXIT
157+
ARTIFACTS="${ARTIFACTS:-${PWD}/_artifacts}"
158+
mkdir -p "${ARTIFACTS}/logs"
159+
160+
# create cluster
161+
if [[ -z "${SKIP_CREATE_CLUSTER:-}" ]]; then
162+
create_cluster
163+
fi
164+
165+
# build k8s binaries and run upstream e2e tests
166+
if [[ -z "${SKIP_UPSTREAM_E2E_TESTS:-}" ]]; then
167+
build_k8s
168+
run_upstream_e2e_tests
169+
fi
170+
171+
if [[ "${#}" -gt 0 ]]; then
172+
# disable error exit so we can run post-command cleanup
173+
set +o errexit
174+
"${@}"
175+
EXIT_VALUE="${?}"
176+
exit ${EXIT_VALUE}
177+
fi
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
apiVersion: storage.k8s.io/v1beta1
2+
kind: StorageClass
3+
metadata:
4+
name: default
5+
annotations:
6+
storageclass.beta.kubernetes.io/is-default-class: "true"
7+
labels:
8+
kubernetes.io/cluster-service: "true"
9+
provisioner: kubernetes.io/azure-disk
10+
parameters:
11+
kind: Managed
12+
storageaccounttype: Standard_LRS
13+
cachingmode: ReadOnly
14+
---
15+
apiVersion: storage.k8s.io/v1beta1
16+
kind: StorageClass
17+
metadata:
18+
name: managed-premium
19+
annotations:
20+
labels:
21+
kubernetes.io/cluster-service: "true"
22+
provisioner: kubernetes.io/azure-disk
23+
parameters:
24+
kind: Managed
25+
storageaccounttype: Premium_LRS
26+
cachingmode: ReadOnly
27+
---
28+
apiVersion: storage.k8s.io/v1beta1
29+
kind: StorageClass
30+
metadata:
31+
name: managed-standard
32+
annotations:
33+
labels:
34+
kubernetes.io/cluster-service: "true"
35+
provisioner: kubernetes.io/azure-disk
36+
parameters:
37+
kind: Managed
38+
storageaccounttype: Standard_LRS
39+
cachingmode: ReadOnly
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
kind: StorageClass
2+
apiVersion: storage.k8s.io/v1
3+
metadata:
4+
name: azurefile
5+
annotations:
6+
labels:
7+
kubernetes.io/cluster-service: "true"
8+
provisioner: kubernetes.io/azure-file
9+
parameters:
10+
skuName: Standard_LRS

0 commit comments

Comments
 (0)