Skip to content

Commit b495581

Browse files
authored
Add OSDe2e test harness scaffolding (#331)
* Add OSDe2e test harness scaffolding * update makefile * update e2e-image-build-push * update makefile
1 parent 0a20baf commit b495581

8 files changed

+166
-3
lines changed

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
SHELL := /usr/bin/env bash
22

3+
include osde2e/project.mk
34
# Verbosity
45
AT_ = @
56
AT = $(AT_$(V))

go.mod

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ require (
66
github.com/evanphx/json-patch v4.12.0+incompatible
77
github.com/ghodss/yaml v1.0.1-0.20190212211648-25d852aebe32
88
github.com/go-logr/logr v1.3.0
9+
github.com/onsi/ginkgo/v2 v2.13.0
10+
github.com/onsi/gomega v1.29.0
911
github.com/openshift/api v0.0.0-20230228142948-d170fcdc0fa6
1012
github.com/openshift/cluster-logging-operator v0.0.0-20230328172346-05f4f8be54d5
1113
github.com/openshift/hive/apis v0.0.0-20230327212335-7fd70848a6d5
@@ -32,6 +34,7 @@ require (
3234
github.com/go-openapi/jsonpointer v0.19.6 // indirect
3335
github.com/go-openapi/jsonreference v0.20.2 // indirect
3436
github.com/go-openapi/swag v0.22.3 // indirect
37+
github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 // indirect
3538
github.com/gogo/protobuf v1.3.2 // indirect
3639
github.com/golang/protobuf v1.5.3 // indirect
3740
github.com/google/gnostic v0.5.7-v3refs // indirect
@@ -47,8 +50,6 @@ require (
4750
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
4851
github.com/modern-go/reflect2 v1.0.2 // indirect
4952
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
50-
github.com/onsi/ginkgo/v2 v2.13.0 // indirect
51-
github.com/onsi/gomega v1.29.0 // indirect
5253
github.com/openshift/custom-resource-status v1.1.3-0.20220503160415-f2fdb4999d87 // indirect
5354
github.com/openshift/elasticsearch-operator v0.0.0-20220613183908-e1648e67c298 // indirect
5455
github.com/pkg/errors v0.9.1 // indirect
@@ -61,11 +62,11 @@ require (
6162
go.uber.org/multierr v1.11.0 // indirect
6263
golang.org/x/net v0.24.0 // indirect
6364
golang.org/x/oauth2 v0.10.0 // indirect
64-
golang.org/x/sync v0.3.0 // indirect
6565
golang.org/x/sys v0.19.0 // indirect
6666
golang.org/x/term v0.19.0 // indirect
6767
golang.org/x/text v0.14.0 // indirect
6868
golang.org/x/time v0.3.0 // indirect
69+
golang.org/x/tools v0.12.0 // indirect
6970
google.golang.org/appengine v1.6.7 // indirect
7071
google.golang.org/protobuf v1.33.0 // indirect
7172
gopkg.in/inf.v0 v0.9.1 // indirect

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,8 @@ golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
239239
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
240240
golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
241241
golang.org/x/mod v0.5.1/go.mod h1:5OXOZSfqPIIbmVBIIKWRFfZjPR0E5r58TLhUjH0a2Ro=
242+
golang.org/x/mod v0.12.0 h1:rmsUpXtvNzj340zd98LZ4KntptpfRHwpFOHG188oHXc=
243+
golang.org/x/mod v0.12.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
242244
golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
243245
golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
244246
golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=

osde2e/Dockerfile

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
FROM registry.ci.openshift.org/openshift/release:rhel-8-release-golang-1.22-openshift-4.17 as builder
2+
WORKDIR /go/src/github.com/openshift/managed-cluster-validating-webhooks
3+
COPY . .
4+
RUN CGO_ENABLED=0 GOFLAGS="-mod=mod" go test ./osde2e -v -c --tags=osde2e -o /harness.test
5+
6+
FROM registry.access.redhat.com/ubi8/ubi-minimal:latest
7+
COPY --from=builder ./harness.test harness.test
8+
ENTRYPOINT [ "/harness.test" ]
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
//go:build osde2e
2+
// +build osde2e
3+
4+
package osde2etests
5+
6+
import (
7+
"os"
8+
"path/filepath"
9+
"testing"
10+
11+
. "github.com/onsi/ginkgo/v2"
12+
. "github.com/onsi/gomega"
13+
)
14+
15+
const (
16+
testResultsDirectory = "/test-run-results"
17+
jUnitOutputFilename = "junit-managed-cluster-validating-webhooks.xml"
18+
)
19+
20+
// Test entrypoint. osde2e runs this as a test suite on test pod.
21+
func TestClusterValidatingWebhooks(t *testing.T) {
22+
RegisterFailHandler(Fail)
23+
suiteConfig, reporterConfig := GinkgoConfiguration()
24+
if _, ok := os.LookupEnv("DISABLE_JUNIT_REPORT"); !ok {
25+
reporterConfig.JUnitReport = filepath.Join(testResultsDirectory, jUnitOutputFilename)
26+
}
27+
RunSpecs(t, "Managed Cluster Validating Webhooks", suiteConfig, reporterConfig)
28+
29+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
//go:build osde2e
2+
// +build osde2e
3+
4+
package osde2etests
5+
6+
import (
7+
"context"
8+
9+
. "github.com/onsi/ginkgo/v2"
10+
)
11+
12+
var _ = Describe("Managed Cluster Validating Webhooks", Ordered, func() {
13+
BeforeAll(func(ctx context.Context) {
14+
})
15+
})

osde2e/project.mk

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Project specific values
2+
OPERATOR_NAME?=$(shell sed -n 's/.*OperatorName .*"\([^"]*\)".*/\1/p' config/config.go)
3+
4+
HARNESS_IMAGE_REGISTRY?=quay.io
5+
HARNESS_IMAGE_REPOSITORY?=app-sre
6+
HARNESS_IMAGE_NAME?=$(OPERATOR_NAME)-test-harness
7+
8+
REGISTRY_USER?=$(QUAY_USER)
9+
REGISTRY_TOKEN?=$(QUAY_TOKEN)
10+
11+
######################
12+
# Targets used by osde2e test harness
13+
######################
14+
15+
# create binary
16+
.PHONY: e2e-harness-build
17+
e2e-harness-build: GOFLAGS_MOD=-mod=mod
18+
e2e-harness-build: GOENV=GOOS=${GOOS} GOARCH=${GOARCH} CGO_ENABLED=0 GOFLAGS="${GOFLAGS_MOD}"
19+
e2e-harness-build:
20+
go mod tidy
21+
${GOENV} go test ./osde2e -v -c --tags=osde2e -o harness.test
22+
23+
# TODO: Push to a known image tag and commit id
24+
# push harness image
25+
# Use current commit as harness image tag
26+
CURRENT_COMMIT=$(shell git rev-parse --short=7 HEAD)
27+
HARNESS_IMAGE_TAG=$(CURRENT_COMMIT)
28+
29+
.PHONY: e2e-image-build-push
30+
e2e-image-build-push:
31+
${CONTAINER_ENGINE} build --pull -f osde2e/Dockerfile -t $(HARNESS_IMAGE_REGISTRY)/$(HARNESS_IMAGE_REPOSITORY)/$(HARNESS_IMAGE_NAME):$(HARNESS_IMAGE_TAG) .
32+
${CONTAINER_ENGINE} tag $(HARNESS_IMAGE_REGISTRY)/$(HARNESS_IMAGE_REPOSITORY)/$(HARNESS_IMAGE_NAME):$(HARNESS_IMAGE_TAG) $(HARNESS_IMAGE_REGISTRY)/$(HARNESS_IMAGE_REPOSITORY)/$(HARNESS_IMAGE_NAME):latest
33+
${CONTAINER_ENGINE} push $(HARNESS_IMAGE_REGISTRY)/$(HARNESS_IMAGE_REPOSITORY)/$(HARNESS_IMAGE_NAME):$(HARNESS_IMAGE_TAG)
34+
${CONTAINER_ENGINE} push $(HARNESS_IMAGE_REGISTRY)/$(HARNESS_IMAGE_REPOSITORY)/$(HARNESS_IMAGE_NAME):latest

osde2e/test-harness-template.yml

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
apiVersion: template.openshift.io/v1
2+
kind: Template
3+
metadata:
4+
name: osde2e-focused-tests
5+
6+
parameters:
7+
- name: OSDE2E_CONFIGS
8+
required: true
9+
- name: TEST_HARNESS_IMAGE
10+
required: true
11+
- name: OCM_TOKEN
12+
required: true
13+
- name: OCM_CCS
14+
required: false
15+
- name: AWS_ACCESS_KEY_ID
16+
required: false
17+
- name: AWS_SECRET_ACCESS_KEY
18+
required: false
19+
- name: CLOUD_PROVIDER_REGION
20+
required: false
21+
- name: GCP_CREDS_JSON
22+
required: false
23+
- name: JOBID
24+
generate: expression
25+
from: "[0-9a-z]{7}"
26+
- name: IMAGE_TAG
27+
value: ''
28+
required: true
29+
- name: LOG_BUCKET
30+
value: 'osde2e-logs'
31+
objects:
32+
- apiVersion: batch/v1
33+
kind: Job
34+
metadata:
35+
name: validation-webhook-${IMAGE_TAG}-${JOBID}
36+
spec:
37+
backoffLimit: 0
38+
template:
39+
spec:
40+
restartPolicy: Never
41+
containers:
42+
- name: osde2e
43+
image: quay.io/redhat-services-prod/osde2e-cicada-tenant/osde2e:latest
44+
command:
45+
- /osde2e
46+
args:
47+
- test
48+
- --configs
49+
- ${OSDE2E_CONFIGS}
50+
securityContext:
51+
runAsNonRoot: true
52+
allowPrivilegeEscalation: false
53+
capabilities:
54+
drop: ["ALL"]
55+
seccompProfile:
56+
type: RuntimeDefault
57+
env:
58+
- name: TEST_HARNESSES
59+
value: ${TEST_HARNESS_IMAGE}:${IMAGE_TAG}
60+
- name: OCM_TOKEN
61+
value: ${OCM_TOKEN}
62+
- name: OCM_CCS
63+
value: ${OCM_CCS}
64+
- name: AWS_ACCESS_KEY_ID
65+
value: ${AWS_ACCESS_KEY_ID}
66+
- name: AWS_SECRET_ACCESS_KEY
67+
value: ${AWS_SECRET_ACCESS_KEY}
68+
- name: CLOUD_PROVIDER_REGION
69+
value: ${CLOUD_PROVIDER_REGION}
70+
- name: GCP_CREDS_JSON
71+
value: ${GCP_CREDS_JSON}
72+
- name: LOG_BUCKET
73+
value: ${LOG_BUCKET}

0 commit comments

Comments
 (0)