Skip to content
This repository was archived by the owner on Oct 22, 2024. It is now read-only.

Commit 12c65ea

Browse files
committed
test: collect coverage information also for "operator API"
Those tests cover a significant chunk of code, so we want to include that. The problem was that the reference files for "deploy" get modified when enabling coverage collection, which broke the API tests. Now we generate and embed a second set of "nocoverage" files for those tests.
1 parent 6d9fc1f commit 12c65ea

File tree

4 files changed

+37
-14
lines changed

4 files changed

+37
-14
lines changed

Jenkinsfile

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,13 @@ pipeline {
7070
TEST_ETCD_VOLUME_SIZE = "1073741824" // 1GB
7171

7272
// Tests that will get skipped when collecting coverage information.
73-
// The operator tests fail because the reference files get modified.
74-
COVERAGE_SKIP = "[email protected]"
73+
//
74+
// The operator itself installs without enabling coverage collection,
75+
// so running those tests doesn't help us. The relevant test is
76+
// "operator API".
77+
//
78+
// Testing with OLM doesn't add much additional coverage.
79+
COVERAGE_SKIP = "[email protected]@Top.Level..olm"
7580
}
7681

7782
stages {

Makefile

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,9 @@ KUSTOMIZE_INPUT := $(shell [ ! -d deploy/kustomize ] || find deploy/kustomize -t
160160
KUSTOMIZE :=
161161

162162
# Setting this to any non-empty value before "make kustomize" will enable
163-
# collection of coverage profiles in all deployments.
163+
# collection of coverage profiles in all deployments. This also sets up the
164+
# original deployment files under "deploy/nocoverage" for use as reference when
165+
# testing the operator.
164166
KUSTOMIZE_WITH_COVERAGE =
165167
ifneq "$(KUSTOMIZE_WITH_COVERAGE)" ""
166168
KUSTOMIZE_COVERAGE_SUFFIX = -coverage
@@ -206,14 +208,22 @@ KUSTOMIZE_OUTPUT := $(foreach item,$(KUSTOMIZE),$(firstword $(subst =, ,$(item))
206208
# right one.
207209
KUSTOMIZE_LOOKUP_KUSTOMIZATION = $(strip $(foreach item,$(KUSTOMIZE),$(if $(filter $(1)=%,$(item)),$(word 2,$(subst =, ,$(item))))))
208210

211+
# This is a wrapper around KUSTOMIZE_LOOKUP_KUSTOMIZATION which
212+
# removes the -coverage suffix.
213+
KUSTOMIZE_LOOKUP_KUSTOMIZATION_NO_COVERAGE = $(subst -coverage,,$(call KUSTOMIZE_LOOKUP_KUSTOMIZATION,$(1)))
214+
209215
# This function takes the kustomize binary and the name of an output
210216
# file as arguments and returns the command which produces that file
211217
# as stdout.
212-
KUSTOMIZE_INVOCATION = (echo '\# Generated with "make kustomize", do not edit!'; echo; $(1) build --load-restrictor LoadRestrictionsNone $(call KUSTOMIZE_LOOKUP_KUSTOMIZATION,$(2)))
218+
KUSTOMIZE_INVOCATION = (echo '\# Generated with "make kustomize", do not edit!'; echo; $(1) build --load-restrictor LoadRestrictionsNone $(call $(3),$(2)))
213219

214220
$(KUSTOMIZE_OUTPUT): _work/kustomize $(KUSTOMIZE_INPUT)
215221
mkdir -p ${@D}
216-
$(call KUSTOMIZE_INVOCATION,$<,$@) >$@
222+
$(call KUSTOMIZE_INVOCATION,$<,$@,KUSTOMIZE_LOOKUP_KUSTOMIZATION) >$@
223+
ifneq "$(KUSTOMIZE_WITH_COVERAGE)" ""
224+
mkdir -p $(subst deploy/,deploy/nocoverage/,${@D})
225+
$(call KUSTOMIZE_INVOCATION,$<,$@,KUSTOMIZE_LOOKUP_KUSTOMIZATION_NO_COVERAGE) >$(subst deploy/,deploy/nocoverage/,$@)
226+
endif
217227
if echo "$@" | grep '/pmem-csi-' | grep -qv '\-operator'; then \
218228
dir=$$(echo "$@" | tr - / | sed -e 's;kubernetes/;kubernetes-;' -e 's;/alpha/;-alpha/;' -e 's;/distributed/;-distributed/;' -e 's/.yaml//' -e 's;/pmem/csi/;/;') && \
219229
mkdir -p $$dir && \
@@ -222,9 +232,13 @@ $(KUSTOMIZE_OUTPUT): _work/kustomize $(KUSTOMIZE_INPUT)
222232
fi
223233

224234
kustomize: clean_kustomize_output $(KUSTOMIZE_OUTPUT)
235+
ifneq "$(KUSTOMIZE_WITH_COVERAGE)" ""
236+
sed -i -e 's/embed kubernetes-/embed nocoverage kubernetes-/' deploy/yamls.go
237+
endif
225238

226239
clean_kustomize_output:
227-
rm -rf deploy/kubernetes-*
240+
rm -rf deploy/kubernetes-* deploy/nocoverage
241+
sed -i -e 's/embed nocoverage /embed /' deploy/yamls.go
228242
rm -f $(KUSTOMIZE_OUTPUT)
229243

230244
# Always re-generate the output files because "git rebase" might have
@@ -241,7 +255,7 @@ clean-kustomize:
241255
test: test-kustomize
242256
test-kustomize: $(addprefix test-kustomize-,$(KUSTOMIZE_OUTPUT))
243257
$(addprefix test-kustomize-,$(KUSTOMIZE_OUTPUT)): test-kustomize-%: _work/kustomize
244-
@ if ! diff <($(call KUSTOMIZE_INVOCATION,$<,$*)) $*; then echo "$* was modified manually" && false; fi
258+
@ if ! diff <($(call KUSTOMIZE_INVOCATION,$<,$*,KUSTOMIZE_LOOKUP_KUSTOMIZATION)) $*; then echo "$* was modified manually" && false; fi
245259

246260
# Targets in the makefile can depend on check-go-version-<path to go binary>
247261
# to trigger a warning if the x.y version of that binary does not match

deploy/yamls.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import (
1616
"github.com/intel/pmem-csi/pkg/version"
1717
)
1818

19-
//go:embed kubernetes-*/*/pmem-csi.yaml
19+
//go:embed kubernetes-*/pmem-csi-*.yaml
2020
//go:embed kustomize/webhook/webhook.yaml
2121
//go:embed kustomize/scheduler/scheduler-service.yaml
2222
//go:embed kustomize/webhook/webhook-service.yaml
@@ -42,7 +42,7 @@ type YamlFile struct {
4242

4343
var yamls []YamlFile
4444

45-
var re = regexp.MustCompile(`^kubernetes-([0-9\.]*)([^/]*)/([^/]*)$`)
45+
var re = regexp.MustCompile(`^kubernetes-([0-9\.]*)/pmem-csi-(lvm|direct)(.*).yaml$`)
4646

4747
func init() {
4848
deployDir, err := assets.ReadDir(".")
@@ -71,7 +71,7 @@ func init() {
7171
Name: name,
7272
Kubernetes: kubernetes,
7373
Flavor: parts[3],
74-
DeviceMode: api.DeviceMode(parts[3]),
74+
DeviceMode: api.DeviceMode(parts[2]),
7575
})
7676
}
7777
}

pkg/deployments/load.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -361,17 +361,21 @@ func patchPodTemplate(obj *unstructured.Unstructured, deployment api.PmemCSIDepl
361361
}
362362

363363
func yamlPath(kubernetes version.Version, deviceMode api.DeviceMode) string {
364-
return fmt.Sprintf("kubernetes-%s/%s/pmem-csi.yaml", kubernetes, deviceMode)
364+
return fmt.Sprintf("kubernetes-%s/pmem-csi-%s.yaml", kubernetes, deviceMode)
365365
}
366366

367367
func loadYAML(path string,
368368
patchYAML func(yaml *[]byte),
369369
enabled func(obj *unstructured.Unstructured) bool,
370370
patchUnstructured func(obj *unstructured.Unstructured)) ([]unstructured.Unstructured, error) {
371-
// We load the builtin yaml files.
372-
yaml, err := deploy.Asset(path)
371+
// We load the builtin yaml files. If they exist, we prefer
372+
// the version without the patched in coverage support.
373+
yaml, err := deploy.Asset("nocoverage/" + path)
373374
if err != nil {
374-
return nil, fmt.Errorf("read reference yaml file: %w", err)
375+
yaml, err = deploy.Asset(path)
376+
if err != nil {
377+
return nil, fmt.Errorf("read reference yaml file: %w", err)
378+
}
375379
}
376380

377381
// Split at the "---" separator before working on individual

0 commit comments

Comments
 (0)