Skip to content

Commit f2f5c9b

Browse files
authored
Merge pull request kubernetes-sigs#638 from chewong/clusterctl-test-framework
✨ switch to clusterctl-based e2e framework
2 parents d4ba874 + b349326 commit f2f5c9b

18 files changed

+532
-1330
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ tilt-settings.json
5454

5555
# e2e output
5656
test/e2e/junit.e2e_suite.*.xml
57+
test/e2e/capz-e2e-*.yaml
58+
test/e2e/config/azure-dev-envsubst.yaml
5759
test/e2e/logs/*
5860
_artifacts
5961

Makefile

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,13 @@ RBAC_ROOT ?= $(MANIFEST_ROOT)/rbac
7373
# Allow overriding the imagePullPolicy
7474
PULL_POLICY ?= Always
7575

76+
# Allow overriding the e2e configurations
77+
ARTIFACTS ?= $(ROOT_DIR)/_artifacts
78+
E2E_CONF_FILE ?= $(ROOT_DIR)/test/e2e/config/azure-dev.yaml
79+
E2E_CONF_FILE_ENVSUBST := $(ROOT_DIR)/test/e2e/config/azure-dev-envsubst.yaml
80+
SKIP_CLEANUP ?= false
81+
SKIP_CREATE_MGMT_CLUSTER ?= false
82+
7683
CLUSTER_TEMPLATE ?= cluster-template.yaml
7784
MANAGED_CLUSTER_TEMPLATE ?= cluster-template-aks.yaml
7885

@@ -101,10 +108,15 @@ test-integration: ## Run integration tests
101108
go test -v -tags=integration ./test/integration/...
102109

103110
.PHONY: test-e2e
104-
test-e2e: ## Run e2e tests
111+
test-e2e: $(ENVSUBST) ## Run e2e tests
105112
PULL_POLICY=IfNotPresent $(MAKE) docker-build
106113
MANAGER_IMAGE=$(CONTROLLER_IMG)-$(ARCH):$(TAG) \
107-
go test ./test/e2e -v -tags=e2e -ginkgo.v -ginkgo.trace -count=1 -timeout=90m
114+
$(ENVSUBST) < $(E2E_CONF_FILE) > $(E2E_CONF_FILE_ENVSUBST) && \
115+
go test ./test/e2e -v -tags=e2e -ginkgo.v -ginkgo.trace -count=1 -timeout=90m \
116+
-e2e.artifacts-folder="$(ARTIFACTS)" \
117+
-e2e.config="$(E2E_CONF_FILE_ENVSUBST)" \
118+
-e2e.skip-resource-cleanup="$(SKIP_CLEANUP)" \
119+
-e2e.use-existing-cluster="$(SKIP_CREATE_MGMT_CLUSTER)"
108120

109121
$(KUBECTL) $(KUBE_APISERVER) $(ETCD): ## install test asset kubectl, kube-apiserver, etcd
110122
source ./scripts/fetch_ext_bins.sh && fetch_tools

docs/development.md

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

338+
339+
338340
#### E2E Testing
339341

340342
To run E2E locally, set `AZURE_CLIENT_ID`, `AZURE_CLIENT_SECRET`, `AZURE_SUBSCRIPTION_ID`, `AZURE_TENANT_ID` and run:
@@ -343,7 +345,15 @@ To run E2E locally, set `AZURE_CLIENT_ID`, `AZURE_CLIENT_SECRET`, `AZURE_SUBSCRI
343345
./scripts/ci-e2e.sh
344346
```
345347

346-
You can optionally set `AZURE_SSH_PUBLIC_KEY_FILE` to use your own SSH key.
348+
You can optionally set the following variables:
349+
350+
| Variable | Description | Default |
351+
|----------------------------|---------------------------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------|
352+
| `E2E_CONF_FILE` | The path of the [E2E configuration file](https://cluster-api.sigs.k8s.io/developer/e2e.html#defining-an-e2e-config-file). | `${GOPATH}/src/sigs.k8s.io/cluster-api-provider-azure/test/e2e/config/azure-dev.yaml` |
353+
| `SKIP_CLEANUP` | Set to `true` if you do not want the bootstrap and workload clusters to be cleaned up after running E2E tests. | `false` |
354+
| `SKIP_CREATE_MGMT_CLUSTER` | Skip management cluster creation. | `false` |
355+
356+
You can also customize the configuration of the CAPZ cluster created by the E2E tests (except for `CLUSTER_NAME`, `AZURE_RESOURCE_GROUP`, `AZURE_VNET_NAME`, `CONTROL_PLANE_MACHINE_COUNT`, and `WORKER_MACHINE_COUNT`, since they are generated by individual test cases). See [Customizing the cluster deployment](#customizing-the-cluster-deployment) for more details.
347357

348358
#### Conformance Testing
349359

@@ -355,20 +365,20 @@ To run Conformance locally, set `AZURE_CLIENT_ID`, `AZURE_CLIENT_SECRET`, `AZURE
355365

356366
You can optionally set the following variables:
357367

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. |
363-
| `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. |
367-
| `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. |
370-
371-
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.
368+
| Variable | Description |
369+
|--------------------------------|---------------------------------------------------------------------------------------------------------------|
370+
| `AZURE_SSH_PUBLIC_KEY_FILE` | Use your own SSH key. |
371+
| `SKIP_CREATE_WORKLOAD_CLUSTER` | Skip workload cluster creation. |
372+
| `SKIP_UPSTREAM_E2E_TESTS` | Skip running upstream Kubernetes E2E tests. |
373+
| `SKIP_CLEANUP` | Skip deleting the cluster after the tests finish running. |
374+
| `KUBECONFIG` | Provide your existing cluster kubeconfig filepath. If no kubeconfig is provided, `./kubeconfig` will be used. |
375+
| `SKIP` | Regexp for test cases to skip. |
376+
| `FOCUS` | Regexp for which test cases to run. |
377+
| `PARALLEL` | Skip serial tests and set --ginkgo-parallel. |
378+
| `USE_CI_ARTIFACTS` | Use a CI version of Kubernetes, ie. not a released version (eg. `v1.19.0-alpha.1.426+0926c9c47677e9`) |
379+
| `CI_VERSION` | Provide a custom CI version of Kubernetes. By default, the latest master commit will be used. |
380+
381+
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.
372382

373383
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:
374384

go.mod

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,8 @@ require (
1515
github.com/google/gofuzz v1.1.0
1616
github.com/onsi/ginkgo v1.12.0
1717
github.com/onsi/gomega v1.9.0
18-
github.com/pelletier/go-toml v1.7.0
1918
github.com/pkg/errors v0.9.1
2019
github.com/spf13/pflag v1.0.5
21-
github.com/spf13/viper v1.6.3
2220
golang.org/x/crypto v0.0.0-20200302210943-78000ba7a073
2321
golang.org/x/net v0.0.0-20200301022130-244492dfa37a
2422
k8s.io/api v0.17.2

go.sum

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,6 @@ github.com/coredns/corefile-migration v1.0.7 h1:T2eOj/NKN1Q1W1bD9MFeZiBYryS0JlWT
9292
github.com/coredns/corefile-migration v1.0.7/go.mod h1:OFwBp/Wc9dJt5cAZzHWMNhK1r5L0p0jDwIBc6j8NC8E=
9393
github.com/coreos/bbolt v1.3.2/go.mod h1:iRUV2dpdMOn7Bo10OQBFzIJO9kkE559Wcmn+qkEiiKk=
9494
github.com/coreos/etcd v3.3.10+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE=
95-
github.com/coreos/etcd v3.3.13+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE=
9695
github.com/coreos/go-etcd v2.0.0+incompatible/go.mod h1:Jez6KQU2B/sWsbdaef3ED8NzMklzPG4d5KIOhIy30Tk=
9796
github.com/coreos/go-oidc v2.1.0+incompatible/go.mod h1:CgnwVTmzoESiwO9qyAFEMiHoZ1nMCKZlZ9V6mm3/LKc=
9897
github.com/coreos/go-semver v0.2.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk=
@@ -373,8 +372,6 @@ github.com/pborman/uuid v1.2.0/go.mod h1:X/NO0urCmaxf9VXbdlT7C2Yzkj2IKimNn4k+gtP
373372
github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic=
374373
github.com/pelletier/go-toml v1.6.0 h1:aetoXYr0Tv7xRU/V4B4IZJ2QcbtMUFoNb3ORp7TzIK4=
375374
github.com/pelletier/go-toml v1.6.0/go.mod h1:5N711Q9dKgbdkxHL+MEfF31hpT7l0S0s/t2kKREewys=
376-
github.com/pelletier/go-toml v1.7.0 h1:7utD74fnzVc/cpcyy8sjrlFr5vYpypUixARcHIMIGuI=
377-
github.com/pelletier/go-toml v1.7.0/go.mod h1:vwGMzjaWMwyfHwgIBhI2YUM4fB6nL6lVAvS1LBMMhTE=
378375
github.com/peterbourgon/diskv v2.0.1+incompatible h1:UBdAOUP5p4RWqPBg048CAvpKN+vxiaj6gdUUzhl4XmI=
379376
github.com/peterbourgon/diskv v2.0.1+incompatible/go.mod h1:uqqh8zWWbv1HBMNONnaR/tNboyR3/BZd58JJSHlUSCU=
380377
github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
@@ -450,8 +447,6 @@ github.com/spf13/viper v1.3.2/go.mod h1:ZiWeW+zYFKm7srdB9IoDzzZXaJaI5eL9QjNiN/DM
450447
github.com/spf13/viper v1.4.0/go.mod h1:PTJ7Z/lr49W6bUbkmS1V3by4uWynFiR9p7+dSq/yZzE=
451448
github.com/spf13/viper v1.6.2 h1:7aKfF+e8/k68gda3LOjo5RxiUqddoFxVq4BKBPrxk5E=
452449
github.com/spf13/viper v1.6.2/go.mod h1:t3iDnF5Jlj76alVNuyFBk5oUMCvsrkbvZK0WQdfDi5k=
453-
github.com/spf13/viper v1.6.3 h1:pDDu1OyEDTKzpJwdq4TiuLyMsUgRa/BT5cn5O62NoHs=
454-
github.com/spf13/viper v1.6.3/go.mod h1:jUMtyi0/lB5yZH/FjyGAoH7IMNrIhlBf6pXZmbMDvzw=
455450
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
456451
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
457452
github.com/stretchr/objx v0.2.0 h1:Hbg2NidpLE8veEBkEZTL3CvlkUIVzuU9jDplZO54c48=

scripts/ci-e2e.sh

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,42 @@ source "${REPO_ROOT}/hack/ensure-kind.sh"
3333
source "${REPO_ROOT}/hack/ensure-kubectl.sh"
3434
# shellcheck source=../hack/ensure-kustomize.sh
3535
source "${REPO_ROOT}/hack/ensure-kustomize.sh"
36+
# shellcheck source=../hack/parse-prow-creds.sh
37+
source "${REPO_ROOT}/hack/parse-prow-creds.sh"
3638

37-
export REGISTRY=e2e
39+
# Verify the required Environment Variables are present.
40+
: "${AZURE_SUBSCRIPTION_ID:?Environment variable empty or not defined.}"
41+
: "${AZURE_TENANT_ID:?Environment variable empty or not defined.}"
42+
: "${AZURE_CLIENT_ID:?Environment variable empty or not defined.}"
43+
: "${AZURE_CLIENT_SECRET:?Environment variable empty or not defined.}"
44+
45+
get_random_region() {
46+
local REGIONS=("eastus" "eastus2" "southcentralus" "westus2" "westeurope")
47+
echo "${REGIONS[${RANDOM} % ${#REGIONS[@]}]}"
48+
}
49+
50+
export REGISTRY="e2e"
51+
export AZURE_SUBSCRIPTION_ID_B64="$(echo -n "$AZURE_SUBSCRIPTION_ID" | base64 | tr -d '\n')"
52+
export AZURE_TENANT_ID_B64="$(echo -n "$AZURE_TENANT_ID" | base64 | tr -d '\n')"
53+
export AZURE_CLIENT_ID_B64="$(echo -n "$AZURE_CLIENT_ID" | base64 | tr -d '\n')"
54+
export AZURE_CLIENT_SECRET_B64="$(echo -n "$AZURE_CLIENT_SECRET" | base64 | tr -d '\n')"
55+
export AZURE_LOCATION="${AZURE_LOCATION:-$(get_random_region)}"
56+
export AZURE_CONTROL_PLANE_MACHINE_TYPE="${AZURE_CONTROL_PLANE_MACHINE_TYPE:-"Standard_D2s_v3"}"
57+
export AZURE_NODE_MACHINE_TYPE="${AZURE_NODE_MACHINE_TYPE:-"Standard_D2s_v3"}"
58+
59+
# Generate SSH key.
60+
AZURE_SSH_PUBLIC_KEY_FILE=${AZURE_SSH_PUBLIC_KEY_FILE:-""}
61+
if ! [ -n "${AZURE_SSH_PUBLIC_KEY_FILE}" ]; then
62+
SSH_KEY_FILE=.sshkey
63+
rm -f "${SSH_KEY_FILE}" 2>/dev/null
64+
ssh-keygen -t rsa -b 2048 -f "${SSH_KEY_FILE}" -N '' 1>/dev/null
65+
AZURE_SSH_PUBLIC_KEY_FILE="${SSH_KEY_FILE}.pub"
66+
fi
67+
export AZURE_SSH_PUBLIC_KEY=$(cat "${AZURE_SSH_PUBLIC_KEY_FILE}" | base64 | tr -d '\r\n')
68+
69+
# timestamp is in RFC-3339 format to match kubetest
70+
export TIMESTAMP="$(date -u '+%Y-%m-%dT%H:%M:%SZ')"
71+
export JOB_NAME="${JOB_NAME:-"cluster-api-provider-azure-e2e"}"
3872

3973
make test-e2e
4074
test_status="${?}"

scripts/ci-entrypoint.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ ARTIFACTS="${ARTIFACTS:-${PWD}/_artifacts}"
156156
mkdir -p "${ARTIFACTS}/logs"
157157

158158
# create cluster
159-
if [[ -z "${SKIP_CREATE_CLUSTER:-}" ]]; then
159+
if [[ -z "${SKIP_CREATE_WORKLOAD_CLUSTER:-}" ]]; then
160160
create_cluster
161161
fi
162162

test/e2e/auth/creds.go

Lines changed: 0 additions & 66 deletions
This file was deleted.

0 commit comments

Comments
 (0)