Skip to content

Commit 4c5559c

Browse files
authored
Add e2e test framework (#490)
1 parent f29d468 commit 4c5559c

File tree

11 files changed

+5223
-5
lines changed

11 files changed

+5223
-5
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ cover.out
2525
# JUnit test output from ginkgo unit tests
2626
junit*.xml
2727

28+
#e2e test files
29+
test/e2e/config/ibmcloud-e2e-envsubst.yaml
30+
2831
# dep ensured 3rd code
2932
vendor/sigs.k8s.io/cluster-api/docs/book/*.json
3033

Makefile

Lines changed: 48 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,15 @@ ARTIFACTS ?= $(REPO_ROOT)/_artifacts
2727
TOOLS_DIR := hack/tools
2828
TOOLS_BIN_DIR := $(TOOLS_DIR)/bin
2929
GO_INSTALL = ./scripts/go_install.sh
30+
E2E_CONF_FILE ?= $(REPO_ROOT)/test/e2e/config/ibmcloud-e2e.yaml
31+
E2E_CONF_FILE_ENVSUBST := $(REPO_ROOT)/test/e2e/config/ibmcloud-e2e-envsubst.yaml
3032

3133
GOLANGCI_LINT := $(TOOLS_BIN_DIR)/golangci-lint
3234
KUSTOMIZE := $(TOOLS_BIN_DIR)/kustomize
3335
GOJQ := $(TOOLS_BIN_DIR)/gojq
3436
CONVERSION_GEN := $(TOOLS_BIN_DIR)/conversion-gen
37+
GINKGO := $(TOOLS_BIN_DIR)/ginkgo
38+
ENVSUBST := $(TOOLS_BIN_DIR)/envsubst
3539

3640
STAGING_REGISTRY ?= gcr.io/k8s-staging-capi-ibmcloud
3741
STAGING_BUCKET ?= artifacts.k8s-staging-capi-ibmcloud.appspot.com
@@ -46,6 +50,7 @@ RELEASE_DIR := out
4650
TAG ?= dev
4751
ARCH ?= amd64
4852
ALL_ARCH ?= amd64 ppc64le
53+
PULL_POLICY ?= Always
4954

5055
# main controller
5156
CORE_IMAGE_NAME ?= cluster-api-ibmcloud-controller
@@ -72,10 +77,6 @@ endif
7277

7378
all: manager
7479

75-
# Run tests
76-
test: generate fmt vet manifests
77-
go test ./... -coverprofile cover.out
78-
7980
# Build manager binary
8081
manager: generate fmt vet
8182
go build -o bin/manager main.go
@@ -149,6 +150,33 @@ endif
149150
lint: $(GOLANGCI_LINT) ## Lint codebase
150151
$(GOLANGCI_LINT) run -v --fast=false
151152

153+
## --------------------------------------
154+
## Testing
155+
## --------------------------------------
156+
157+
# Run unit tests
158+
test: generate fmt vet manifests
159+
go test ./... -coverprofile cover.out
160+
161+
# Allow overriding the e2e configurations
162+
GINKGO_FOCUS ?= Workload cluster creation
163+
GINKGO_NODES ?= 3
164+
GINKGO_NOCOLOR ?= false
165+
GINKGO_ARGS ?= -v -trace -progress -v -tags=e2e -focus=$(GINKGO_FOCUS) -nodes=$(GINKGO_NODES) --noColor=$(GINKGO_NOCOLOR)
166+
ARTIFACTS ?= $(REPO_ROOT)/_artifacts
167+
SKIP_CLEANUP ?= false
168+
SKIP_CREATE_MGMT_CLUSTER ?= false
169+
170+
#Run the end-to-end tests
171+
.PHONY: test-e2e
172+
test-e2e: $(KUBECTL) $(GINKGO) $(ENVSUBST) e2e-image
173+
$(ENVSUBST) < $(E2E_CONF_FILE) > $(E2E_CONF_FILE_ENVSUBST)
174+
$(GINKGO) $(GINKGO_ARGS) ./test/e2e -- \
175+
-e2e.artifacts-folder="$(ARTIFACTS)" \
176+
-e2e.config="$(E2E_CONF_FILE_ENVSUBST)" \
177+
-e2e.skip-resource-cleanup=$(SKIP_CLEANUP) \
178+
-e2e.use-existing-cluster=$(SKIP_CREATE_MGMT_CLUSTER)
179+
152180
## --------------------------------------
153181
## Docker
154182
## --------------------------------------
@@ -166,6 +194,22 @@ docker-pull-prerequisites:
166194
docker pull docker.io/docker/dockerfile:1.1-experimental
167195
docker pull gcr.io/distroless/static:latest
168196

197+
.PHONY: e2e-image
198+
e2e-image: docker-pull-prerequisites
199+
docker build --tag=$(CORE_CONTROLLER_ORIGINAL_IMG):e2e .
200+
$(MAKE) set-manifest-image MANIFEST_IMG=$(CORE_CONTROLLER_ORIGINAL_IMG):e2e TARGET_RESOURCE="./config/default/manager_image_patch.yaml"
201+
$(MAKE) set-manifest-pull-policy PULL_POLICY=Never TARGET_RESOURCE="./config/default/manager_pull_policy.yaml"
202+
203+
.PHONY: set-manifest-image
204+
set-manifest-image:
205+
$(info Updating kustomize image patch file for default resource)
206+
sed -i'' -e 's@image: .*@image: '"${MANIFEST_IMG}"'@' ./config/default/manager_image_patch.yaml
207+
208+
.PHONY: set-manifest-pull-policy
209+
set-manifest-pull-policy:
210+
$(info Updating kustomize pull policy file for default resource)
211+
sed -i'' -e 's@imagePullPolicy: .*@imagePullPolicy: '"$(PULL_POLICY)"'@' ./config/default/manager_pull_policy.yaml
212+
169213
## --------------------------------------
170214
## Docker - All ARCH
171215
## --------------------------------------

config/default/kustomization.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ patchesStrategicMerge:
3333
- manager_credentials_patch.yaml
3434
- manager_auth_proxy_patch.yaml
3535
- manager_image_patch.yaml
36+
- manager_pull_policy.yaml
3637

3738
# [WEBHOOK] To enable webhook, uncomment all the sections with [WEBHOOK] prefix including the one in
3839
# crd/kustomization.yaml
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
apiVersion: apps/v1
2+
kind: Deployment
3+
metadata:
4+
name: controller-manager
5+
namespace: system
6+
spec:
7+
template:
8+
spec:
9+
containers:
10+
- name: manager
11+
imagePullPolicy: Always

go.mod

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,8 @@ require (
2121
k8s.io/kube-openapi v0.0.0-20211110012726-3cc51fd1e909 // indirect
2222
k8s.io/utils v0.0.0-20210930125809-cb0fa318a74b
2323
sigs.k8s.io/cluster-api v1.0.2
24+
sigs.k8s.io/cluster-api/test v1.0.2
2425
sigs.k8s.io/controller-runtime v0.10.3
2526
)
27+
28+
replace sigs.k8s.io/cluster-api => sigs.k8s.io/cluster-api v1.0.2

go.sum

Lines changed: 401 additions & 1 deletion
Large diffs are not rendered by default.

hack/tools/Makefile

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,3 +78,11 @@ $(GOJQ): $(BIN_DIR) go.mod go.sum
7878
CONVERSION_GEN := $(BIN_DIR)/conversion-gen
7979
$(CONVERSION_GEN): $(BIN_DIR) go.mod go.sum
8080
go build -tags=tools -o $@ k8s.io/code-generator/cmd/conversion-gen
81+
82+
GINKGO := $(BIN_DIR)/ginkgo
83+
$(GINKGO): $(BIN_DIR) go.mod go.sum
84+
go build -tags=tools -o $@ github.com/onsi/ginkgo/ginkgo
85+
86+
ENVSUBST := $(BIN_DIR)/envsubst
87+
$(ENVSUBST): $(BIN_DIR) go.mod go.sum
88+
go build -tags=tools -o $@ github.com/drone/envsubst/v2/cmd/envsubst

test/e2e/config/ibmcloud-e2e.yaml

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
managementClusterName: capi-ibmcloud-e2e
2+
3+
images:
4+
# Use local built images for e2e tests
5+
- name: gcr.io/k8s-staging-capi-ibmcloud/cluster-api-ibmcloud-controller:e2e
6+
loadBehavior: mustLoad
7+
8+
providers:
9+
- name: cluster-api
10+
type: CoreProvider
11+
versions:
12+
- name: v1.0.2
13+
value: https://github.com/kubernetes-sigs/cluster-api/releases/download/v1.0.2/core-components.yaml
14+
type: url
15+
files:
16+
- sourcePath: "${PWD}/test/e2e/data/shared/metadata.yaml"
17+
- name: kubeadm
18+
type: BootstrapProvider
19+
versions:
20+
- name: v1.0.2
21+
value: https://github.com/kubernetes-sigs/cluster-api/releases/download/v1.0.2/bootstrap-components.yaml
22+
type: url
23+
files:
24+
- sourcePath: "${PWD}/test/e2e/data/shared/metadata.yaml"
25+
- name: kubeadm
26+
type: ControlPlaneProvider
27+
versions:
28+
- name: v1.0.2
29+
value: https://github.com/kubernetes-sigs/cluster-api/releases/download/v1.0.2/control-plane-components.yaml
30+
type: url
31+
files:
32+
- sourcePath: "${PWD}/test/e2e/data/shared/metadata.yaml"
33+
- name: ibmcloud
34+
type: InfrastructureProvider
35+
versions:
36+
- name: v0.2.0
37+
value: "${PWD}/config/default"
38+
files:
39+
- sourcePath: "${PWD}/metadata.yaml"
40+
targetName: "metadata.yaml"
41+
- sourcePath: "${PWD}/templates/cluster-template-powervs.yaml"
42+
targetName: "cluster-template-powervs.yaml"
43+
- sourcePath: "${PWD}/templates/cluster-template.yaml"
44+
targetName: "cluster-template-vpc.yaml"
45+
46+
variables:
47+
KUBERNETES_VERSION: "${KUBERNETES_VERSION:-v1.22.4}"
48+
# Cluster Addons
49+
CNI: "${PWD}/test/e2e/data/cni/calico/calico.yaml"
50+
IP_FAMILY: "IPv4"
51+
52+
intervals:
53+
default/wait-controllers: ["3m", "10s"]
54+
default/wait-cluster: ["20m", "10s"]
55+
default/wait-control-plane: ["30m", "10s"]
56+
default/wait-worker-nodes: ["30m", "10s"]
57+
default/wait-delete-cluster: ["20m", "10s"]
58+
default/wait-machine-upgrade: ["50m", "10s"]
59+
default/wait-machine-remediation: ["30m", "10s"]
60+
default/wait-deployment: ["5m", "10s"]
61+
default/wait-job: ["5m", "10s"]
62+
default/wait-service: ["3m", "10s"]

0 commit comments

Comments
 (0)