Skip to content

Commit 29acbff

Browse files
committed
instrument coverage collection during e2e test; other minor tweaks
Signed-off-by: Joe Lanford <[email protected]>
1 parent 3898a15 commit 29acbff

15 files changed

+144
-60
lines changed

.github/workflows/test.yaml

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,18 @@ jobs:
3434

3535
- name: Run ${{matrix.test}} test
3636
run: |
37-
task test:${{matrix.test}}
37+
task test:${{matrix.test}}
38+
39+
- name: Convert coverage data to Codecov format
40+
if: ${{matrix.test == 'unit' || matrix.test == 'e2e'}}
41+
run: |
42+
go tool covdata textfmt -i=coverage/${{matrix.test}} -o=coverage/${{matrix.test}}.out
43+
44+
- name: Upload coverage data to Codecov
45+
if: ${{matrix.test == 'unit' || matrix.test == 'e2e'}}
46+
uses: codecov/codecov-action@v3
47+
with:
48+
file: coverage/${{matrix.test}}.out
49+
flags: ${{matrix.test}}
50+
fail_ci_if_error: true
51+

.gitignore

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ vendor
1212
*.test
1313

1414
# Output of the go coverage tool, specifically when used with LiteIDE
15-
cover.out
15+
/coverage
1616

1717
# Release output
1818
/dist/**
1919
/install.sh
20-
/operator-controller.yaml
20+
/operator-controller*.yaml
2121

2222
# editor and IDE paraphernalia
2323
.idea

.goreleaser.yml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,22 @@ builds:
1010
- id: operator-controller
1111
main: ./
1212
binary: bin/manager
13-
tags: upstream
13+
tags:
14+
- "{{ .Env.GO_BUILD_TAGS }}"
1415
goos:
1516
- linux
1617
goarch:
1718
- amd64
1819
- arm64
1920
- ppc64le
2021
- s390x
22+
flags:
23+
- -cover={{ .Env.GO_COVER }}
24+
mod_timestamp: "{{ .CommitTimestamp }}"
25+
asmflags:
26+
- all=-trimpath={{ dir .Env.PWD }}
27+
gcflags:
28+
- all=-trimpath={{ dir .Env.PWD }}
2129
ldflags:
2230
- -X main.Version={{ .Version }}
2331
dockers:

.taskfile.build.yaml

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ includes:
77

88
vars:
99
BIN: "{{.ROOT_DIR}}/bin"
10+
KUSTOMIZE_DIR: "config/default"
1011
OPERATOR_CONTROLLER_MANIFEST: ./operator-controller.yaml
1112

1213
OLMV0_VERSION: v0.24.0
@@ -36,9 +37,16 @@ tasks:
3637
By default, the binary is created at ./bin/manager.
3738
3839
To generate the binary for a different OS, set the GOOS task variable accordingly.
40+
41+
The GO_COVER task variable instruments the operator with coverage enabled when set to "true"
42+
or disabled when set to "false". The default is "false".
43+
env:
44+
GOOS: "{{.GOOS}}"
45+
GO_COVER: '{{.GO_COVER | default "false" }}'
46+
GO_BUILD_TAGS: "{{.GO_BUILD_TAGS}}"
3947
cmds:
4048
- mkdir -p {{.BIN}}
41-
- GOOS={{.GOOS}} {{.TOOLSBIN}}/goreleaser build --single-target --snapshot --clean --output {{.BIN}}/manager
49+
- "{{.TOOLSBIN}}/goreleaser build --debug --single-target --snapshot --clean --output {{.BIN}}/manager"
4250
deps: [tools:goreleaser, generate]
4351

4452
docker:
@@ -60,6 +68,7 @@ tasks:
6068
vars:
6169
BIN: "{{.ROOT_DIR}}/bin/linux"
6270
GOOS: linux
71+
GO_COVER: "{{.GO_COVER}}"
6372

6473
manifest:
6574
desc: "Generate the operator manifest"
@@ -70,7 +79,7 @@ tasks:
7079
with the controller image set to the IMAGE_REPO and IMAGE_TAG environment variables.
7180
cmds:
7281
- cd config/manager && {{.TOOLSBIN}}/kustomize edit set image controller=$IMAGE_REPO:$IMAGE_TAG
73-
- "{{.TOOLSBIN}}/kustomize build config/default > ./operator-controller.yaml"
82+
- "{{.TOOLSBIN}}/kustomize build {{.KUSTOMIZE_DIR}} > {{.OPERATOR_CONTROLLER_MANIFEST}}"
7483
deps: [tools:kustomize, generate]
7584

7685
install-script:

.taskfile.deploy.yaml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,17 @@ tasks:
1818
- ./install.sh
1919
deps:
2020
- task: build:docker
21+
vars:
22+
GO_COVER: "{{.GO_COVER}}"
23+
GO_BUILD_TAGS: "{{.GO_BUILD_TAGS}}"
2124
- task: build:manifest
25+
vars:
26+
KUSTOMIZE_DIR: "{{.KUSTOMIZE_DIR}}"
27+
OPERATOR_CONTROLLER_MANIFEST: "{{.OPERATOR_CONTROLLER_MANIFEST}}"
2228
- task: build:install-script
29+
vars:
30+
OPERATOR_CONTROLLER_MANIFEST: "{{.OPERATOR_CONTROLLER_MANIFEST}}"
2331
- task: kind:create
2432
vars:
2533
KIND_CLUSTER_NAME: "{{.KIND_CLUSTER_NAME}}"
26-
desc: "Run the operator in a fresh kind cluster"
34+
KIND_EXTRA_FLAGS: "{{.KIND_EXTRA_FLAGS}}"

.taskfile.kind.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ tasks:
1212
create:
1313
desc: "Create a fresh kind cluster"
1414
cmds:
15-
- "{{.TOOLSBIN}}/kind create cluster --name {{.KIND_CLUSTER_NAME}}"
15+
- "{{.TOOLSBIN}}/kind create cluster --name {{.KIND_CLUSTER_NAME}} {{.KIND_EXTRA_FLAGS}}"
1616
deps:
1717
- tools:kind
1818
- task: delete

.taskfile.test.yaml

Lines changed: 44 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,16 @@ tasks:
4444
4545
The FOCUS variable can be used to filter tests by name.
4646
The PKGS variable can be used to filter tests by package.
47+
vars:
48+
GOCOVERDIR: "./coverage/unit"
4749
cmds:
48-
- eval $({{.TOOLSBIN}}/setup-envtest use -p env {{.ENVTEST_VERSION}}) && {{.TOOLSBIN}}/ginkgo --tags {{.GO_BUILD_TAGS}} {{with .FOCUS}}-focus "{{.}}"{{end}} -coverprofile cover.out {{.PKGS}}
50+
- rm -rf {{.GOCOVERDIR}} && mkdir -p {{.GOCOVERDIR}} && chmod 1777 {{.GOCOVERDIR}}
51+
- defer:
52+
task: rm-file
53+
vars:
54+
FILE: .ginkgo.coverprofile.out
55+
- eval $({{.TOOLSBIN}}/setup-envtest use -p env {{.ENVTEST_VERSION}}) && {{.TOOLSBIN}}/ginkgo --coverprofile=.ginkgo.coverprofile.out --tags {{.GO_BUILD_TAGS}} --progress --trace {{with .FOCUS}}--focus "{{.}}"{{end}} {{.PKGS}} -- -test.gocoverdir="{{.ROOT_DIR}}/{{.GOCOVERDIR}}"
56+
- go tool covdata percent -i={{.GOCOVERDIR}}
4957
deps: [tools:setup-envtest, tools:ginkgo]
5058

5159
e2e:
@@ -54,17 +62,41 @@ tasks:
5462
Run e2e tests.
5563
5664
The FOCUS variable can be used to filter tests by name.
65+
vars:
66+
GOCOVERDIR: "./coverage/e2e"
5767
cmds:
68+
- rm -rf {{.GOCOVERDIR}} && mkdir -p {{.GOCOVERDIR}} && chmod 1777 {{.GOCOVERDIR}}
69+
- |
70+
cat << EOF > ./kind-e2e.yaml
71+
kind: Cluster
72+
apiVersion: kind.x-k8s.io/v1alpha4
73+
nodes:
74+
- role: control-plane
75+
extraMounts:
76+
- hostPath: {{.GOCOVERDIR}}
77+
containerPath: /tmp/coverdata
78+
EOF
5879
- defer:
59-
task: kind:delete
80+
task: rm-file
6081
vars:
61-
KIND_CLUSTER_NAME: "{{.KIND_CLUSTER_NAME}}-e2e"
62-
- "{{.TOOLSBIN}}/ginkgo --tags {{.GO_BUILD_TAGS}} -progress -trace {{with .FOCUS}}-focus '{{.}}'{{end}} ./test/e2e"
63-
deps:
64-
- tools:ginkgo
82+
FILE: "./kind-e2e.yaml"
6583
- task: deploy:kind
6684
vars:
85+
KUSTOMIZE_DIR: "config/e2e"
86+
OPERATOR_CONTROLLER_MANIFEST: "operator-controller-e2e.yaml"
6787
KIND_CLUSTER_NAME: "{{.KIND_CLUSTER_NAME}}-e2e"
88+
KIND_EXTRA_FLAGS: "--config ./kind-e2e.yaml"
89+
GO_COVER: "true"
90+
- defer:
91+
task: kind:delete
92+
vars:
93+
KIND_CLUSTER_NAME: "{{.KIND_CLUSTER_NAME}}-e2e"
94+
- "{{.TOOLSBIN}}/ginkgo --tags {{.GO_BUILD_TAGS}} --progress --trace {{with .FOCUS}}--focus '{{.}}'{{end}} ./test/e2e"
95+
96+
# Delete the operator controller manager pod to write the coverage data to disk.
97+
- kubectl delete --wait pod -n operator-controller-system -l control-plane=controller-manager
98+
- go tool covdata percent -i={{.GOCOVERDIR}}
99+
deps: [tools:ginkgo]
68100

69101
sanity:
70102
desc: "Run sanity checks"
@@ -78,3 +110,9 @@ tasks:
78110
cmds:
79111
- git diff --exit-code
80112
deps: [ style, build:generate ]
113+
114+
rm-file:
115+
cmds:
116+
- rm -f {{.FILE}}
117+
silent: true
118+
internal: true

.taskfile.tools.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ vars:
44
CONTROLLER_GEN_VERSION: v0.11.3
55
GINKGO_VERSION:
66
sh: go list -m -f {{ "{{.Version}}" }} github.com/onsi/ginkgo/v2
7-
GORELEASER_VERSION: main
7+
GORELEASER_VERSION: v1.16.1
88
KIND_VERSION: v0.17.0
99
KUSTOMIZE_VERSION: v4.5.7
1010
SETUP_ENVTEST_VERSION: latest

Taskfile.dist.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ tasks:
5757
GitHub changelog and release pipeline steps. By default, this is set to false.
5858
This should only be set to true when running the release task for a tagged
5959
release.
60+
env:
61+
GO_COVER: false
62+
GO_BUILD_TAGS: "{{.GO_BUILD_TAGS}}"
6063
cmds:
6164
- task: build:manifest
6265
- task: build:install-script

config/default/manager_auth_proxy_patch.yaml

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,6 @@ metadata:
88
spec:
99
template:
1010
spec:
11-
affinity:
12-
nodeAffinity:
13-
requiredDuringSchedulingIgnoredDuringExecution:
14-
nodeSelectorTerms:
15-
- matchExpressions:
16-
- key: kubernetes.io/arch
17-
operator: In
18-
values:
19-
- amd64
20-
- arm64
21-
- ppc64le
22-
- s390x
23-
- key: kubernetes.io/os
24-
operator: In
25-
values:
26-
- linux
2711
containers:
2812
- name: kube-rbac-proxy
2913
securityContext:

0 commit comments

Comments
 (0)