Skip to content

Commit 512c8c4

Browse files
authored
boilerplating e2e suite (#498)
* boilerplating e2e * boilerplating e2e + bp update * remove old makefile will be provided by bp * bp update
1 parent abb536b commit 512c8c4

20 files changed

+365
-60
lines changed

.github/dependabot.yml

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,5 @@
11
version: 2
22
updates:
3-
- package-ecosystem: "gomod"
4-
directories:
5-
- "/"
6-
- "interceptor/"
7-
allow:
8-
- dependency-type: all
9-
schedule:
10-
interval: "daily"
113
- package-ecosystem: "docker"
124
directory: "/build"
135
labels:

Makefile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ define ADDITIONAL_IMAGE_SPECS
77
endef
88

99
include boilerplate/generated-includes.mk
10-
include test/e2e/project.mk
1110

1211
GOLANGCI_LINT_VERSION=v2.0.2
1312
MOCKGEN_VERSION=v0.5.0

OWNERS_ALIASES

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,14 +65,14 @@ aliases:
6565
- smarthall
6666
srep-infra-cicd:
6767
- mmazur
68-
- mrsantamaria
6968
- ritmun
7069
- jbpratt
7170
- yiqinzhang
71+
- varunraokadaparthi
7272
srep-functional-leads:
7373
- abyrne55
7474
- clcollins
75-
- Nikokolas3270
75+
- bergmannf
7676
- theautoroboto
7777
- smarthall
7878
- sam-nguyen7
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
25d548ae98a0a1c8125aecf14cc168ad36968920
1+
b655ba1347f9bd549afec9f383b5154ca4747c37

boilerplate/generated-includes.mk

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,5 @@
33
# conventions. Please ensure your base Makefile includes only this file.
44
include boilerplate/_lib/boilerplate.mk
55
include boilerplate/openshift/osd-container-image/standard.mk
6+
include boilerplate/openshift/golang-osd-e2e/project.mk
7+
include boilerplate/openshift/golang-osd-e2e/standard.mk
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
reviewers:
2+
- srep-infra-cicd
3+
approvers:
4+
- srep-infra-cicd
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# Conventions for Ginkgo based e2e tests
2+
3+
- [Conventions for Ginkgo based e2e tests](#conventions-for-ginkgo-based-e2e-tests)
4+
- [Consuming](#consuming)
5+
- [`make` targets and functions.](#make-targets-and-functions)
6+
- [E2E Test](#e2e-test)
7+
- [Local Testing](#e2e-local-testing)
8+
9+
## Consuming
10+
Currently, this convention is only intended for OSD operators. To adopt this convention, your `boilerplate/update.cfg` should include:
11+
12+
```
13+
openshift/golang-osd-e2e
14+
```
15+
16+
## `make` targets and functions.
17+
18+
**Note:** Your repository's main `Makefile` needs to be edited to include:
19+
20+
```
21+
include boilerplate/generated-includes.mk
22+
```
23+
24+
One of the primary purposes of these `make` targets is to allow you to
25+
standardize your prow and app-sre pipeline configurations using the
26+
following:
27+
28+
### E2e Test
29+
30+
| `make` target | Purpose |
31+
|------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
32+
| `e2e-binary-build` | Compiles ginkgo tests under test/e2e and creates the ginkgo binary. |
33+
| `e2e-image-build-push` | Builds e2e image and pushes to operator's quay repo. Image name is defaulted to <operator-image-name>-test-harness. Quay repository must be created beforehand. |
34+
35+
#### E2E Local Testing
36+
37+
Please follow [this README](https://github.com/openshift/ops-sop/blob/master/v4/howto/osde2e/operator-test-harnesses.md#using-ginkgo) to run your e2e tests locally
38+

test/e2e/test-e2e-suite-template.yml renamed to boilerplate/openshift/golang-osd-e2e/e2e-template.yml

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
1+
# THIS FILE IS GENERATED BY BOILERPLATE. DO NOT EDIT.
12
apiVersion: template.openshift.io/v1
23
kind: Template
34
metadata:
45
name: osde2e-focused-tests
5-
66
parameters:
77
- name: OSDE2E_CONFIGS
88
required: true
9-
- name: TEST_E2E_SUITE_IMAGE
10-
required: true
11-
- name: OCM_TOKEN
9+
- name: TEST_IMAGE
1210
required: true
11+
- name: OCM_CLIENT_ID
12+
required: false
13+
- name: OCM_CLIENT_SECRET
14+
required: false
1315
- name: OCM_CCS
1416
required: false
1517
- name: AWS_ACCESS_KEY_ID
@@ -32,7 +34,7 @@ objects:
3234
- apiVersion: batch/v1
3335
kind: Job
3436
metadata:
35-
name: configuration-anomaly-detection-${IMAGE_TAG}-${JOBID}
37+
name: osde2e-${OPERATOR_NAME}-${IMAGE_TAG}-${JOBID}
3638
spec:
3739
backoffLimit: 0
3840
template:
@@ -45,6 +47,9 @@ objects:
4547
- /osde2e
4648
args:
4749
- test
50+
- --only-health-check-nodes
51+
- --skip-destroy-cluster
52+
- --skip-must-gather
4853
- --configs
4954
- ${OSDE2E_CONFIGS}
5055
securityContext:
@@ -55,10 +60,12 @@ objects:
5560
seccompProfile:
5661
type: RuntimeDefault
5762
env:
58-
- name: TEST_HARNESSES
59-
value: ${TEST_E2E_SUITE_IMAGE}:${IMAGE_TAG}
60-
- name: OCM_TOKEN
61-
value: ${OCM_TOKEN}
63+
- name: AD_HOC_TEST_IMAGES
64+
value: ${TEST_IMAGE}:${IMAGE_TAG}
65+
- name: OCM_CLIENT_ID
66+
value: ${OCM_CLIENT_ID}
67+
- name: OCM_CLIENT_SECRET
68+
value: ${OCM_CLIENT_SECRET}
6269
- name: OCM_CCS
6370
value: ${OCM_CCS}
6471
- name: AWS_ACCESS_KEY_ID
@@ -70,4 +77,4 @@ objects:
7077
- name: GCP_CREDS_JSON
7178
value: ${GCP_CREDS_JSON}
7279
- name: LOG_BUCKET
73-
value: ${LOG_BUCKET}
80+
value: ${LOG_BUCKET}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Project specific values
2+
OPERATOR_NAME?=$(shell sed -n 's/.*OperatorName .*"\([^"]*\)".*/\1/p' config/config.go)
3+
4+
E2E_IMAGE_REGISTRY?=quay.io
5+
E2E_IMAGE_REPOSITORY?=app-sre
6+
E2E_IMAGE_NAME?=$(OPERATOR_NAME)-e2e
7+
8+
9+
REGISTRY_USER?=$(QUAY_USER)
10+
REGISTRY_TOKEN?=$(QUAY_TOKEN)
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
# Validate variables in project.mk exist
2+
ifndef OPERATOR_NAME
3+
$(error OPERATOR_NAME is not set; only operators should consume this convention; check project.mk file)
4+
endif
5+
ifndef E2E_IMAGE_REGISTRY
6+
$(error E2E_IMAGE_REGISTRY is not set; check project.mk file)
7+
endif
8+
ifndef E2E_IMAGE_REPOSITORY
9+
$(error E2E_IMAGE_REPOSITORY is not set; check project.mk file)
10+
endif
11+
12+
# Use current commit as e2e image tag
13+
CURRENT_COMMIT=$(shell git rev-parse --short=7 HEAD)
14+
E2E_IMAGE_TAG=$(CURRENT_COMMIT)
15+
16+
### Accommodate docker or podman
17+
#
18+
# The docker/podman creds cache needs to be in a location unique to this
19+
# invocation; otherwise it could collide across jenkins jobs. We'll use
20+
# a .docker folder relative to pwd (the repo root).
21+
CONTAINER_ENGINE_CONFIG_DIR = .docker
22+
JENKINS_DOCKER_CONFIG_FILE = /var/lib/jenkins/.docker/config.json
23+
export REGISTRY_AUTH_FILE = ${CONTAINER_ENGINE_CONFIG_DIR}/config.json
24+
25+
# If this configuration file doesn't exist, podman will error out. So
26+
# we'll create it if it doesn't exist.
27+
ifeq (,$(wildcard $(REGISTRY_AUTH_FILE)))
28+
$(shell mkdir -p $(CONTAINER_ENGINE_CONFIG_DIR))
29+
# Copy the node container auth file so that we get access to the registries the
30+
# parent node has access to
31+
$(shell if test -f $(JENKINS_DOCKER_CONFIG_FILE); then cp $(JENKINS_DOCKER_CONFIG_FILE) $(REGISTRY_AUTH_FILE); fi)
32+
endif
33+
34+
# ==> Docker uses --config=PATH *before* (any) subcommand; so we'll glue
35+
# that to the CONTAINER_ENGINE variable itself. (NOTE: I tried half a
36+
# dozen other ways to do this. This was the least ugly one that actually
37+
# works.)
38+
ifndef CONTAINER_ENGINE
39+
CONTAINER_ENGINE=$(shell command -v podman 2>/dev/null || echo docker --config=$(CONTAINER_ENGINE_CONFIG_DIR))
40+
endif
41+
42+
REGISTRY_USER ?=
43+
REGISTRY_TOKEN ?=
44+
45+
# TODO: Figure out how to discover this dynamically
46+
OSDE2E_CONVENTION_DIR := boilerplate/openshift/golang-osd-operator-osde2e
47+
48+
# log into quay.io
49+
.PHONY: container-engine-login
50+
container-engine-login:
51+
@test "${REGISTRY_USER}" != "" && test "${REGISTRY_TOKEN}" != "" || (echo "REGISTRY_USER and REGISTRY_TOKEN must be defined" && exit 1)
52+
mkdir -p ${CONTAINER_ENGINE_CONFIG_DIR}
53+
@${CONTAINER_ENGINE} login -u="${REGISTRY_USER}" -p="${REGISTRY_TOKEN}" quay.io
54+
55+
######################
56+
# Targets used by e2e test suite
57+
######################
58+
59+
# create binary
60+
.PHONY: e2e-binary-build
61+
e2e-binary-build: GOFLAGS_MOD=-mod=mod
62+
e2e-binary-build: GOENV=GOOS=${GOOS} GOARCH=${GOARCH} CGO_ENABLED=0 GOFLAGS="${GOFLAGS_MOD}"
63+
e2e-binary-build:
64+
go mod tidy
65+
go test ./test/e2e -v -c --tags=osde2e -o e2e.test
66+
67+
# push e2e image tagged as latest and as repo commit hash
68+
.PHONY: e2e-image-build-push
69+
e2e-image-build-push: container-engine-login
70+
${CONTAINER_ENGINE} build --pull -f test/e2e/Dockerfile -t $(E2E_IMAGE_REGISTRY)/$(E2E_IMAGE_REPOSITORY)/$(E2E_IMAGE_NAME):$(E2E_IMAGE_TAG) .
71+
${CONTAINER_ENGINE} tag $(E2E_IMAGE_REGISTRY)/$(E2E_IMAGE_REPOSITORY)/$(E2E_IMAGE_NAME):$(E2E_IMAGE_TAG) $(E2E_IMAGE_REGISTRY)/$(E2E_IMAGE_REPOSITORY)/$(E2E_IMAGE_NAME):latest
72+
${CONTAINER_ENGINE} push $(E2E_IMAGE_REGISTRY)/$(E2E_IMAGE_REPOSITORY)/$(E2E_IMAGE_NAME):$(E2E_IMAGE_TAG)
73+
${CONTAINER_ENGINE} push $(E2E_IMAGE_REGISTRY)/$(E2E_IMAGE_REPOSITORY)/$(E2E_IMAGE_NAME):latest

0 commit comments

Comments
 (0)