Skip to content

Commit c8f39b8

Browse files
committed
Export coverage, merge unit-inttests, calicovpp/ctl image
This patch adds coverage exporting for boht unit and integration (with VPP) tests. - It merges 'unit' and 'integration' tests into a single pipeline, always launching VPP if passed the VPP_BINARY envvar - It adds a signal handler for USR2 to export coverage if built as such - It removes the WITH_DGB option and default to always packaging gdb with VPP. - It adds a calicovpp/ctl image to the build pipeline Signed-off-by: Nathan Skrzypczak <[email protected]>
1 parent b5a9922 commit c8f39b8

File tree

22 files changed

+440
-104
lines changed

22 files changed

+440
-104
lines changed

.ci/buildspec.yml

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,18 +29,16 @@ phases:
2929

3030
build:
3131
commands:
32-
- make go-check
33-
- make mdlint
34-
35-
- make -C vpp-manager clean-vpp
32+
- make clean-vpp
3633
- make images
37-
- docker images
3834

39-
- make run-integration-tests
35+
- make mdlint
36+
- make ci-lint
37+
- make ci-test
38+
- make ci-cov
39+
4040
- make push
4141

4242
post_build:
4343
commands:
44-
- echo "Build complete"
45-
4644
- echo Build completed on `date`

Dockerfile.depend

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ ENV UNATTENDED=y
99

1010
RUN apt-get update \
1111
&& DEBIAN_FRONTEND=noninteractive apt-get install -y -qq \
12-
apt-utils wget cmake curl git
12+
apt-utils wget cmake curl git docker.io
1313

1414
ENV GOVERSION=1.24.0
1515
ENV GOROOT="/root/.go"

Makefile

Lines changed: 54 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@ build:
88
$(MAKE) -C calico-vpp-agent $@
99
$(MAKE) -C vpp-manager $@
1010
$(MAKE) -C multinet-monitor $@
11-
@mkdir -p cmd/bin
12-
go build -o cmd/bin/calicovppctl ./cmd/calicovppctl/main.go
11+
$(MAKE) -C cmd/calicovppctl $@
1312

1413
.PHONY: image images
1514
images: image
1615
image:
1716
$(MAKE) -C calico-vpp-agent $@
1817
$(MAKE) -C vpp-manager $@
1918
$(MAKE) -C multinet-monitor $@
19+
$(MAKE) -C cmd/calicovppctl $@
2020

2121
.PHONY: image-kind
2222
image-kind: image
@@ -49,13 +49,18 @@ push:
4949
$(MAKE) -C calico-vpp-agent $@
5050
$(MAKE) -C vpp-manager $@
5151
$(MAKE) -C multinet-monitor $@
52+
$(MAKE) -C cmd/calicovppctl $@
5253

5354
.PHONY: dev
5455
dev:
5556
$(MAKE) -C calico-vpp-agent ALSO_LATEST=y $@
5657
$(MAKE) -C vpp-manager ALSO_LATEST=y $@
5758
$(MAKE) -C multinet-monitor ALSO_LATEST=y $@
5859

60+
.PHONY: clean-vpp
61+
clean-vpp:
62+
$(MAKE) -C vpp-manager clean-vpp
63+
5964
.PHONY: proto
6065
proto:
6166
$(MAKE) -C calico-vpp-agent $@
@@ -284,22 +289,14 @@ lint:
284289
test -d vpp-manager/vpp_build && touch vpp-manager/vpp_build/go.mod || true
285290
golangci-lint run --color=never
286291

287-
.PHONY: test
288-
test: go-lint
289-
rm -rf .coverage/unit
290-
mkdir -p .coverage/unit
291-
go test -cover -covermode=atomic ./... \
292-
-args \
293-
-test.gocoverdir=$(shell pwd)/.coverage/unit
294-
295292
.PHONY: cov-html
296293
cov-html:
297294
go tool covdata percent -i=.coverage/unit
298295
go tool covdata textfmt -i=.coverage/unit -o .coverage/profile
299296
go tool cover -html=.coverage/profile
300297

301298
.PHONY: cov
302-
cov: test
299+
cov:
303300
go tool covdata percent -i=.coverage/unit
304301
@go tool covdata textfmt -i=.coverage/unit -o .coverage/profile
305302
@echo "TOTAL:"
@@ -347,16 +344,55 @@ builder-image: ## Make dependencies image. (Not required normally; is implied in
347344
&& ${PUSH_IMAGE} )
348345
docker tag ${DEPEND_IMAGE} ${DEPEND_BASE}:latest
349346

350-
.PHONY: go-check
351-
go-check: builder-image
352-
@echo Checking go code
347+
# make test - runs the unit & VPP-integration tests
348+
# requiring sudo, this is useful in dev as this caches go deps.
349+
# Altought this requires go, sudo installed
350+
.PHONY: test
351+
test: builder-image
352+
@rm -rf $(shell pwd)/.coverage/unit
353+
@mkdir -p $(shell pwd)/.coverage/unit
354+
$(MAKE) -C vpp-manager image
355+
$(MAKE) -C vpp-manager mock-pod-image
356+
sudo -E env "PATH=$$PATH" VPP_BINARY=/usr/bin/vpp \
357+
VPP_IMAGE=calicovpp/vpp:$(TAG) \
358+
go test ./... \
359+
-cover \
360+
-covermode=atomic \
361+
-test.v \
362+
-test.gocoverdir=$(shell pwd)/.coverage/unit \
363+
364+
# make ci-test - runs the unit & VPP-integration tests
365+
# within a container, with mounted /var/run/docker.sock
366+
# this is portable, but lack go cache
367+
.PHONY: ci-test
368+
ci-test: builder-image
369+
@rm -rf $(shell pwd)/.coverage/unit
370+
@mkdir -p $(shell pwd)/.coverage/unit
371+
$(MAKE) -C vpp-manager image
372+
$(MAKE) -C vpp-manager mock-pod-image
353373
docker run -t --rm \
374+
--privileged \
375+
--pid=host \
376+
-v /proc:/proc \
354377
-v $(CURDIR):/vpp-dataplane \
378+
-v /tmp/cni-tests-vpp:/tmp/cni-tests-vpp \
379+
-v /var/run/docker.sock:/var/run/docker.sock \
380+
--env VPP_BINARY=/usr/bin/vpp \
381+
--env VPP_IMAGE=calicovpp/vpp:$(TAG) \
382+
-w /vpp-dataplane \
355383
${DEPEND_IMAGE} \
356-
make -C /vpp-dataplane cov
357-
358-
.PHONY: go-lint
359-
go-lint: lint
384+
go test ./... \
385+
-cover \
386+
-covermode=atomic \
387+
-test.v \
388+
-test.gocoverdir=/vpp-dataplane/.coverage/unit
389+
390+
.PHONY: ci-%
391+
ci-%: builder-image
392+
docker run -t --rm \
393+
-v $(CURDIR):/vpp-dataplane \
394+
${DEPEND_IMAGE} \
395+
make -C /vpp-dataplane $*
360396

361397
.PHONY: depend-image-hash
362398
depend-image-hash:

calico-vpp-agent/Makefile

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,24 @@
11
include ../common.mk
22

3-
.PHONY: all build gobgp image push proto
4-
53
TAG ?= latest # Tag images with :$(TAG)
64
ALSO_LATEST ?= n # If 'y' also tag images with :latest
75
GENERATE_LOG_FILE=../vpplink/generated/generate.log
86
VERSION_FILE=version
97

10-
all: build gobgp image
8+
.PHONY: all
9+
all: image
1110

1211
bin:
1312
mkdir -p bin
1413

15-
.PHONY: felix-api-proxy
16-
felix-api-proxy: bin
17-
${DOCKER_RUN} go build -o ./bin/felix-api-proxy ./cmd/api-proxy
18-
19-
build: felix-api-proxy bin
20-
${DOCKER_RUN} go build -o ./bin/calico-vpp-agent ./cmd
21-
22-
gobgp: bin
14+
.PHONY: build
15+
build: bin
16+
${DOCKER_RUN} go build $(COVER_OPTS) -o ./bin/felix-api-proxy ./cmd/api-proxy
17+
${DOCKER_RUN} go build $(COVER_OPTS) -o ./bin/calico-vpp-agent ./cmd
2318
${DOCKER_RUN} go build -o ./bin/gobgp github.com/osrg/gobgp/v3/cmd/gobgp/
2419

25-
image: build gobgp
20+
.PHONY: image
21+
image: build
2622
@echo "Image tag : $(TAG)" > $(VERSION_FILE)
2723
@echo "VPP-dataplane version : $(shell git log -1 --oneline)" >> $(VERSION_FILE)
2824
@cat $(GENERATE_LOG_FILE) >> $(VERSION_FILE)
@@ -32,6 +28,14 @@ image: build gobgp
3228
docker tag calicovpp/agent:$(TAG) calicovpp/agent:prerelease; \
3329
fi
3430

31+
.PHONY: image-cov
32+
image-cov: build-cov
33+
@echo "Image tag : $(TAG)" > $(VERSION_FILE)
34+
@echo "VPP-dataplane version : $(shell git log -1 --oneline)" >> $(VERSION_FILE)
35+
@cat $(GENERATE_LOG_FILE) >> $(VERSION_FILE)
36+
docker build --pull -t calicovpp/agent:$(TAG) .
37+
38+
.PHONY: push
3539
push: ${PUSH_DEP}
3640
set -e; for registry in ${REGISTRIES}; do \
3741
docker tag calicovpp/agent:$(TAG) $${registry}calicovpp/agent:$(TAG); \
@@ -42,7 +46,9 @@ push: ${PUSH_DEP}
4246
docker push --all-tags $${registry}calicovpp/agent; \
4347
done
4448

49+
.PHONY: dev
4550
dev: image
4651

52+
.PHONY: proto
4753
proto:
4854
$(MAKE) -C proto $@

calico-vpp-agent/cmd/calico_vpp_dataplane.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,10 @@ func main() {
228228
syscall.SIGUSR2,
229229
)
230230

231+
ctx, cancel := context.WithCancel(context.Background())
232+
defer cancel()
233+
config.HandleUsr2Signal(ctx, log.WithFields(logrus.Fields{"component": "sighdlr"}))
234+
231235
select {
232236
case sig := <-sigChan:
233237
switch sig {

calico-vpp-agent/cni/cni_node_test.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,16 +47,15 @@ import (
4747

4848
// Names of integration tests arguments
4949
const (
50-
IntegrationTestEnableArgName = "INTEGRATION_TEST"
51-
VppImageArgName = "VPP_IMAGE"
52-
VppBinaryArgName = "VPP_BINARY"
53-
VppContainerExtraArgsName = "VPP_CONTAINER_EXTRA_ARGS"
50+
VppImageArgName = "VPP_IMAGE"
51+
VppBinaryArgName = "VPP_BINARY"
52+
VppContainerExtraArgsName = "VPP_CONTAINER_EXTRA_ARGS"
5453
)
5554

5655
// TestCniIntegration runs all the ginkgo integration test inside CNI package
5756
func TestCniIntegration(t *testing.T) {
5857
// skip test if test run is not integration test run (prevent accidental run of integration tests using go test ./...)
59-
_, isIntegrationTestRun := os.LookupEnv(IntegrationTestEnableArgName)
58+
_, isIntegrationTestRun := os.LookupEnv(VppImageArgName)
6059
if !isIntegrationTestRun {
6160
t.Skip("skipping CNI integration tests (set INTEGRATION_TEST env variable to run these tests)")
6261
}

cmd/calicovppctl/Dockerfile

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
FROM --platform=${BUILDPLATFORM} golang:1.24 AS builder
2+
3+
WORKDIR /src
4+
COPY go.mod go.sum /src
5+
RUN go mod download
6+
7+
COPY *.go /src
8+
9+
ARG TARGETOS
10+
ARG TARGETARCH
11+
12+
RUN CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} \
13+
go build \
14+
-ldflags="-s -w" -o /cmd/calicovppctl
15+
16+
FROM scratch
17+
WORKDIR /
18+
COPY --from=builder /cmd/calicovppctl /calicovppctl
19+
20+
CMD ["./calicovppctl"]

cmd/calicovppctl/Makefile

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
include ../../common.mk
2+
3+
BIN_DIR = $(VPP_DATAPLANE_DIR)/bin
4+
5+
.PHONY: bin
6+
bin:
7+
@mkdir -p $(BIN_DIR)
8+
9+
.PHONY: build
10+
build: bin
11+
${DOCKER_RUN} go build -o $(BIN_DIR)/calicovppctl .
12+
13+
.PHONY: image
14+
image:
15+
ifndef CI_BUILD
16+
docker build --network=host --build-arg http_proxy=${DOCKER_BUILD_PROXY} \
17+
--platform linux/arm64,linux/amd64 \
18+
-t calicovpp/ctl:$(TAG) .
19+
endif
20+
21+
.PHONY: push
22+
push: ${PUSH_DEP}
23+
docker buildx create \
24+
--name vppctlbuilder \
25+
--driver docker-container \
26+
--use
27+
docker buildx build \
28+
--network=host \
29+
--build-arg http_proxy=${DOCKER_BUILD_PROXY} \
30+
--platform linux/arm64,linux/amd64 \
31+
--push \
32+
$(foreach registry,$(REGISTRIES),-t $(registry)calicovpp/ctl:$(TAG)) \
33+
$(if $(ALSO_LATEST),$(foreach registry,$(REGISTRIES),-t $(registry)calicovpp/ctl:latest)) \
34+
.
35+
docker buildx rm vppctlbuilder

cmd/calicovppctl/go.mod

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
module github.com/projectcalico/vpp-dataplane/cmd/calicovppctl/v3
2+
3+
go 1.24.4
4+
5+
require (
6+
github.com/gookit/color v1.5.4
7+
github.com/onsi/gomega v1.36.2 // indirect
8+
github.com/pkg/errors v0.9.1 // indirect
9+
golang.org/x/net v0.41.0 // indirect
10+
golang.org/x/sys v0.33.0 // indirect
11+
google.golang.org/protobuf v1.36.5 // indirect
12+
k8s.io/api v0.32.5
13+
k8s.io/apimachinery v0.32.5
14+
k8s.io/client-go v0.32.5
15+
sigs.k8s.io/yaml v1.4.0
16+
)
17+
18+
require (
19+
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
20+
github.com/emicklei/go-restful/v3 v3.11.0 // indirect
21+
github.com/fxamacker/cbor/v2 v2.7.0 // indirect
22+
github.com/go-logr/logr v1.4.2 // indirect
23+
github.com/go-openapi/jsonpointer v0.21.0 // indirect
24+
github.com/go-openapi/jsonreference v0.20.2 // indirect
25+
github.com/go-openapi/swag v0.23.0 // indirect
26+
github.com/gogo/protobuf v1.3.2 // indirect
27+
github.com/golang/protobuf v1.5.4 // indirect
28+
github.com/google/gnostic-models v0.6.9-0.20230804172637-c7be7c783f49 // indirect
29+
github.com/google/go-cmp v0.7.0 // indirect
30+
github.com/google/gofuzz v1.2.0 // indirect
31+
github.com/google/uuid v1.6.0 // indirect
32+
github.com/josharian/intern v1.0.0 // indirect
33+
github.com/json-iterator/go v1.1.12 // indirect
34+
github.com/mailru/easyjson v0.7.7 // indirect
35+
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
36+
github.com/modern-go/reflect2 v1.0.2 // indirect
37+
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
38+
github.com/onsi/ginkgo/v2 v2.22.2 // indirect
39+
github.com/spf13/pflag v1.0.6 // indirect
40+
github.com/stretchr/testify v1.10.0 // indirect
41+
github.com/x448/float16 v0.8.4 // indirect
42+
github.com/xo/terminfo v0.0.0-20210125001918-ca9a967f8778 // indirect
43+
golang.org/x/oauth2 v0.28.0 // indirect
44+
golang.org/x/term v0.32.0 // indirect
45+
golang.org/x/text v0.26.0 // indirect
46+
golang.org/x/time v0.11.0 // indirect
47+
gopkg.in/evanphx/json-patch.v4 v4.12.0 // indirect
48+
gopkg.in/inf.v0 v0.9.1 // indirect
49+
gopkg.in/yaml.v3 v3.0.1 // indirect
50+
k8s.io/klog/v2 v2.130.1 // indirect
51+
k8s.io/kube-openapi v0.0.0-20241105132330-32ad38e42d3f // indirect
52+
k8s.io/utils v0.0.0-20241104100929-3ea5e8cea738 // indirect
53+
sigs.k8s.io/json v0.0.0-20241010143419-9aa6b5e7a4b3 // indirect
54+
sigs.k8s.io/structured-merge-diff/v4 v4.4.2 // indirect
55+
)

0 commit comments

Comments
 (0)