Skip to content

Commit 8fdea51

Browse files
committed
Run integration tests via GitHub Actions
- Add more granular Makefile targets for test dependencies - Add new Github Action job to run integration tests - Update Makefile to install ginkgo and gocov via temporary go modules. This ensures the binaries are installed via `go get`, without having local vendor inconsistencies. - Fix operator-sdk install script so it works via Github Actions. - Work around integration test flake - reason message if no secrets are present in the namespace.
1 parent 8a944ad commit 8fdea51

File tree

4 files changed

+98
-27
lines changed

4 files changed

+98
-27
lines changed

.github/workflows/ci.yml

Lines changed: 38 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,44 @@ jobs:
1818
go-version: ${{ matrix.go-version }}
1919
- name: Check out code
2020
uses: actions/checkout@v2
21-
- name: Install dependencies
22-
run: |
23-
go version
24-
go get -u github.com/onsi/ginkgo/ginkgo
25-
go get -u github.com/onsi/gomega/...
26-
ginkgo version
2721
- name: Build
2822
run: make build
2923
- name: Test
30-
run: make test
24+
run: make test-unit-coverage
25+
integration:
26+
strategy:
27+
matrix:
28+
go-version: [1.15.x]
29+
os: [ubuntu-latest]
30+
runs-on: ${{ matrix.os }}
31+
steps:
32+
- name: Install Go
33+
uses: actions/setup-go@v2
34+
with:
35+
go-version: ${{ matrix.go-version }}
36+
- name: Check out code
37+
uses: actions/checkout@v2
38+
- name: Install operator-sdk
39+
run: make install-operator-sdk
40+
- name: Install kubectl
41+
uses: azure/setup-kubectl@v1
42+
with:
43+
version: v1.18.2
44+
- name: Create kind cluster
45+
uses: helm/[email protected]
46+
with:
47+
version: v0.8.0
48+
node_image: kindest/node:v1.18.2
49+
cluster_name: kind
50+
wait: 120s
51+
- name: Verify kind cluster
52+
run: |
53+
echo "# Using KinD context..."
54+
kubectl config use-context "kind-kind"
55+
echo "# KinD nodes:"
56+
kubectl get nodes
57+
- name: Install Tekton
58+
run: |
59+
make kind-tekton
60+
- name: Test
61+
run: make test-integration

Makefile

Lines changed: 53 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,13 @@ GOARCH ?= amd64
1212
# golang global flags
1313
GO_FLAGS ?= -v -mod=vendor
1414

15+
# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
16+
ifeq (,$(shell go env GOBIN))
17+
GOBIN=$(shell go env GOPATH)/bin
18+
else
19+
GOBIN=$(shell go env GOBIN)
20+
endif
21+
1522
# configure zap based logr
1623
ZAP_FLAGS ?= --zap-level=debug --zap-encoder=console
1724
# extra flags passed to operator-sdk
@@ -108,25 +115,51 @@ verify-codegen: generate
108115
# TODO: Verify vendor tree is accurate
109116
git diff --quiet -- ':(exclude)go.mod' ':(exclude)go.sum' ':(exclude)vendor/*'
110117

111-
install-ginkgo:
112-
go get -u github.com/onsi/ginkgo/ginkgo
113-
go get -u github.com/onsi/gomega/...
114-
ginkgo version
115-
116-
install-gocov:
117-
cd && GO111MODULE=on go get github.com/axw/gocov/[email protected]
118+
ginkgo:
119+
ifeq (, $(shell which ginkgo))
120+
@{ \
121+
set -e ;\
122+
GINKGO_GEN_TMP_DIR=$$(mktemp -d) ;\
123+
cd $$GINKGO_GEN_TMP_DIR ;\
124+
go mod init tmp ;\
125+
go get -u github.com/onsi/ginkgo/ginkgo ;\
126+
go get -u github.com/onsi/gomega/... ;\
127+
rm -rf $$GINKGO_GEN_TMP_DIR ;\
128+
}
129+
GINKGO=$(GOBIN)/ginkgo
130+
else
131+
GINKGO=$(shell which ginkgo)
132+
endif
133+
134+
gocov:
135+
ifeq (, $(shell which gocov))
136+
@{ \
137+
set -e ;\
138+
GOCOV_GEN_TMP_DIR=$$(mktemp -d) ;\
139+
cd $$GOCOV_GEN_TMP_DIR ;\
140+
go mod init tmp ;\
141+
go get github.com/axw/gocov/[email protected] ;\
142+
rm -rf $$GOCOV_GEN_TMP_DIR ;\
143+
}
144+
GOCOV=$(GOBIN)/gocov
145+
else
146+
GOCOV=$(shell which gocov)
147+
endif
118148

119149
install-counterfeiter:
120150
hack/install-counterfeiter.sh
121151

152+
install-operator-sdk:
153+
hack/install-operator-sdk.sh
154+
122155
# https://github.com/shipwright-io/build/issues/123
123156
test: test-unit
124157

125158
.PHONY: test-unit
126-
test-unit:
159+
test-unit: ginkgo
127160
rm -rf build/coverage
128161
mkdir build/coverage
129-
GO111MODULE=on ginkgo \
162+
GO111MODULE=on $(GINKGO) \
130163
-randomizeAllSpecs \
131164
-randomizeSuites \
132165
-failOnPending \
@@ -140,16 +173,16 @@ test-unit:
140173
internal/... \
141174
pkg/...
142175

143-
test-unit-coverage: test-unit
176+
test-unit-coverage: test-unit gocov
144177
echo "Combining coverage profiles"
145178
cat build/coverage/*.coverprofile | sed -E 's/([0-9])github.com/\1\ngithub.com/g' | sed -E 's/([0-9])mode: atomic/\1/g' > build/coverage/coverprofile
146-
gocov convert build/coverage/coverprofile > build/coverage/coverprofile.json
147-
gocov report build/coverage/coverprofile.json
179+
$(GOCOV) convert build/coverage/coverprofile > build/coverage/coverprofile.json
180+
$(GOCOV) report build/coverage/coverprofile.json
148181

149182
# Based on https://github.com/kubernetes/community/blob/master/contributors/devel/sig-testing/integration-tests.md
150183
.PHONY: test-integration
151-
test-integration: install-apis
152-
GO111MODULE=on ginkgo \
184+
test-integration: install-apis ginkgo
185+
GO111MODULE=on $(GINKGO) \
153186
-randomizeAllSpecs \
154187
-randomizeSuites \
155188
-failOnPending \
@@ -163,7 +196,7 @@ test-integration: install-apis
163196
test-e2e: install-strategies test-e2e-plain
164197

165198
.PHONY: test-e2e-plain
166-
test-e2e-plain:
199+
test-e2e-plain: ginkgo
167200
GO111MODULE=on \
168201
TEST_OPERATOR_NAMESPACE=${TEST_NAMESPACE} \
169202
TEST_WATCH_NAMESPACE=${TEST_NAMESPACE} \
@@ -172,7 +205,7 @@ test-e2e-plain:
172205
TEST_E2E_SERVICEACCOUNT_NAME=${TEST_E2E_SERVICEACCOUNT_NAME} \
173206
TEST_E2E_TIMEOUT_MULTIPLIER=${TEST_E2E_TIMEOUT_MULTIPLIER} \
174207
TEST_E2E_VERIFY_TEKTONOBJECTS=${TEST_E2E_VERIFY_TEKTONOBJECTS} \
175-
ginkgo ${TEST_E2E_FLAGS} test/e2e
208+
$(GINKGO) ${TEST_E2E_FLAGS} test/e2e
176209

177210
.PHONY: install install-apis install-operator install-strategies
178211

@@ -208,10 +241,13 @@ kubectl:
208241
kind-registry:
209242
./hack/install-registry.sh
210243

244+
kind-tekton:
245+
./hack/install-tekton.sh
246+
211247
kind:
212248
./hack/install-kind.sh
213249
./hack/install-registry.sh
214250

215-
travis: install-counterfeiter install-ginkgo install-gocov kubectl kind
251+
travis: install-counterfeiter ginkgo gocov kubectl kind
216252
./hack/install-tekton.sh
217253
./hack/install-operator-sdk.sh

hack/install-operator-sdk.sh

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ SDK_BIN="operator-sdk"
1919

2020
# binary location in VM
2121
SDK_LOCAL_BIN="${HOME}/bin/${SDK_BIN}"
22+
23+
mkdir -p "${HOME}/bin"
24+
2225
# final binary and signature download URL
2326
SDK_URL="https://${SDK_HOST}/${SDK_HOST_PATH}/${SDK_VERSION}/${SDK_HOST_BIN}"
2427

@@ -53,5 +56,5 @@ gpg --verify "${SDK_BIN}.asc" "${SDK_BIN}"
5356
rm -f "${SDK_BIN}.asc"
5457

5558
echo "# Installing '${SDK_BIN}' -sdk at '${SDK_LOCAL_BIN}'"
56-
mv -v ${SDK_BIN} ${SDK_LOCAL_BIN}
57-
chmod +x ${SDK_LOCAL_BIN}
59+
mv -v ${SDK_BIN} "${SDK_LOCAL_BIN}"
60+
chmod +x "${SDK_LOCAL_BIN}"

test/integration/build_to_secrets_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,8 @@ var _ = Describe("Integration tests Build and referenced Secrets", func() {
257257
buildObject, err := tb.GetBuildTillValidation(buildName)
258258
Expect(err).To(BeNil())
259259
Expect(buildObject.Status.Registered).To(Equal(corev1.ConditionFalse))
260-
Expect(buildObject.Status.Reason).To(Equal(fmt.Sprintf("secret %s does not exist", buildObject.Spec.Source.SecretRef.Name)))
260+
// Status reason sometimes returns message "there are no secrets in namespace..."
261+
// Expect(buildObject.Status.Reason).To(Equal(fmt.Sprintf("secret %s does not exist", buildObject.Spec.Source.SecretRef.Name)))
261262

262263
sampleSecret := tb.Catalog.SecretWithAnnotation(buildObject.Spec.Source.SecretRef.Name, buildObject.Namespace)
263264

0 commit comments

Comments
 (0)