Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 14 additions & 8 deletions .ci/buildspec.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,24 @@ phases:

build:
commands:
- make go-check
- make mdlint

- make -C vpp-manager clean-vpp
- make clean-vpp
- make images
- docker images

- make run-integration-tests
# run linting and go tests
- make mdlint
- make ci-lint
- make ci-test
- make ci-cov

# Publish image, even if they are not fine
# as this helps reproducing
- make push

# Run integration tests (kind & e2e)
- make kind
- make test-e2e
- make kind-rm-cluster

post_build:
commands:
- echo "Build complete"

- echo Build completed on `date`
2 changes: 1 addition & 1 deletion Dockerfile.depend
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ ENV UNATTENDED=y

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

ENV GOVERSION=1.24.0
ENV GOROOT="/root/.go"
Expand Down
91 changes: 68 additions & 23 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@ include common.mk
check-%:
@: $(if $(value $*),,$(error $* is undefined))

bin:
@mkdir -p bin

.PHONY: build
build:
build: bin
$(MAKE) -C calico-vpp-agent $@
$(MAKE) -C vpp-manager $@
$(MAKE) -C multinet-monitor $@
@mkdir -p cmd/bin
go build -o cmd/bin/calicovppctl ./cmd/calicovppctl/main.go
${DOCKER_RUN} go build -o bin/calicovppctl ./cmd/calicovppctl/main.go

.PHONY: image images
images: image
Expand Down Expand Up @@ -56,6 +58,10 @@ dev:
$(MAKE) -C vpp-manager ALSO_LATEST=y $@
$(MAKE) -C multinet-monitor ALSO_LATEST=y $@

.PHONY: clean-vpp
clean-vpp:
$(MAKE) -C vpp-manager clean-vpp

.PHONY: proto
proto:
$(MAKE) -C calico-vpp-agent $@
Expand Down Expand Up @@ -175,6 +181,18 @@ restart-calicovpp:
kubectl -n calico-vpp-dataplane rollout restart ds/calico-vpp-node
kubectl -n calico-vpp-dataplane rollout status ds/calico-vpp-node

# Make sure we are running against a kind cluster, as the tests will
# try to break dataplane
.PHONY: validate-kind
validate-kind:
test -n "$(shell kubectl config current-context | grep '^kind-')" || test -n "$(FORCE)"

# test-e2e run repo local end to end test of calico VPP,
# making sure basic connectivity, DNS and services work
# This requires a running cluser. e.g. 'make kind'
.PHONY: test-e2e
test-e2e: validate-kind run-tests run-tests-v6 restart-calicovpp

.PHONY: goapi
export VPP_DIR ?= $(shell pwd)/vpp-manager/vpp_build
goapi:
Expand Down Expand Up @@ -230,10 +248,6 @@ release: check-TAG check-CALICO_TAG
@echo "Calico version \"v3.27.0\", the directory would be \"calico_versioned_docs/version-3.27\". If this is not done,"
@echo "the install docs get broken!!"

.PHONY: run-integration-tests
run-integration-tests:
$(MAKE) -C test/integration-tests $@

.PHONY: test-memif-multinet
test-memif-multinet:
kubectl apply -f test/yaml/multinet/network.yaml
Expand Down Expand Up @@ -284,22 +298,14 @@ lint:
test -d vpp-manager/vpp_build && touch vpp-manager/vpp_build/go.mod || true
golangci-lint run --color=never

.PHONY: test
test: go-lint
rm -rf .coverage/unit
mkdir -p .coverage/unit
go test -cover -covermode=atomic ./... \
-args \
-test.gocoverdir=$(shell pwd)/.coverage/unit

.PHONY: cov-html
cov-html:
go tool covdata percent -i=.coverage/unit
go tool covdata textfmt -i=.coverage/unit -o .coverage/profile
go tool cover -html=.coverage/profile

.PHONY: cov
cov: test
cov:
go tool covdata percent -i=.coverage/unit
@go tool covdata textfmt -i=.coverage/unit -o .coverage/profile
@echo "TOTAL:"
Expand Down Expand Up @@ -347,16 +353,55 @@ builder-image: ## Make dependencies image. (Not required normally; is implied in
&& ${PUSH_IMAGE} )
docker tag ${DEPEND_IMAGE} ${DEPEND_BASE}:latest

.PHONY: go-check
go-check: builder-image
@echo Checking go code
# make test - runs the unit & VPP-integration tests
# requiring sudo, this is useful in dev as this caches go deps.
# Altought this requires go, sudo installed
.PHONY: test
test: builder-image bin
@rm -rf $(shell pwd)/.coverage/unit
@mkdir -p $(shell pwd)/.coverage/unit
$(MAKE) -C vpp-manager image
$(MAKE) -C vpp-manager mock-pod-image
sudo -E env "PATH=$$PATH" VPP_BINARY=/usr/bin/vpp \
VPP_IMAGE=calicovpp/vpp:$(TAG) \
go test ./... \
-cover \
-covermode=atomic \
-test.v \
-test.gocoverdir=$(shell pwd)/.coverage/unit \

# make ci-test - runs the unit & VPP-integration tests
# within a container, with mounted /var/run/docker.sock
# this is portable, but lack go cache
.PHONY: ci-test
ci-test: builder-image bin
@rm -rf $(shell pwd)/.coverage/unit
@mkdir -p $(shell pwd)/.coverage/unit
$(MAKE) -C vpp-manager image
$(MAKE) -C vpp-manager mock-pod-image
docker run -t --rm \
--privileged \
--pid=host \
-v /proc:/proc \
-v $(CURDIR):/vpp-dataplane \
-v /tmp/cni-tests-vpp:/tmp/cni-tests-vpp \
-v /var/run/docker.sock:/var/run/docker.sock \
--env VPP_BINARY=/usr/bin/vpp \
--env VPP_IMAGE=calicovpp/vpp:$(TAG) \
-w /vpp-dataplane \
${DEPEND_IMAGE} \
make -C /vpp-dataplane cov

.PHONY: go-lint
go-lint: lint
go test ./... \
-cover \
-covermode=atomic \
-test.v \
-test.gocoverdir=/vpp-dataplane/.coverage/unit

.PHONY: ci-%
ci-%: builder-image
docker run -t --rm \
-v $(CURDIR):/vpp-dataplane \
${DEPEND_IMAGE} \
make -C /vpp-dataplane $*

.PHONY: depend-image-hash
depend-image-hash:
Expand Down
30 changes: 18 additions & 12 deletions calico-vpp-agent/Makefile
Original file line number Diff line number Diff line change
@@ -1,28 +1,24 @@
include ../common.mk

.PHONY: all build gobgp image push proto

TAG ?= latest # Tag images with :$(TAG)
ALSO_LATEST ?= n # If 'y' also tag images with :latest
GENERATE_LOG_FILE=../vpplink/generated/generate.log
VERSION_FILE=version

all: build gobgp image
.PHONY: all
all: image

bin:
mkdir -p bin

.PHONY: felix-api-proxy
felix-api-proxy: bin
${DOCKER_RUN} go build -o ./bin/felix-api-proxy ./cmd/api-proxy

build: felix-api-proxy bin
${DOCKER_RUN} go build -o ./bin/calico-vpp-agent ./cmd

gobgp: bin
.PHONY: build
build: bin
${DOCKER_RUN} go build $(COVER_OPTS) -o ./bin/felix-api-proxy ./cmd/api-proxy
${DOCKER_RUN} go build $(COVER_OPTS) -o ./bin/calico-vpp-agent ./cmd
${DOCKER_RUN} go build -o ./bin/gobgp github.com/osrg/gobgp/v3/cmd/gobgp/

image: build gobgp
.PHONY: image
image: build
@echo "Image tag : $(TAG)" > $(VERSION_FILE)
@echo "VPP-dataplane version : $(shell git log -1 --oneline)" >> $(VERSION_FILE)
@cat $(GENERATE_LOG_FILE) >> $(VERSION_FILE)
Expand All @@ -32,6 +28,14 @@ image: build gobgp
docker tag calicovpp/agent:$(TAG) calicovpp/agent:prerelease; \
fi

.PHONY: image-cov
image-cov: build-cov
@echo "Image tag : $(TAG)" > $(VERSION_FILE)
@echo "VPP-dataplane version : $(shell git log -1 --oneline)" >> $(VERSION_FILE)
@cat $(GENERATE_LOG_FILE) >> $(VERSION_FILE)
docker build --pull -t calicovpp/agent:$(TAG) .

.PHONY: push
push: ${PUSH_DEP}
set -e; for registry in ${REGISTRIES}; do \
docker tag calicovpp/agent:$(TAG) $${registry}calicovpp/agent:$(TAG); \
Expand All @@ -42,7 +46,9 @@ push: ${PUSH_DEP}
docker push --all-tags $${registry}calicovpp/agent; \
done

.PHONY: dev
dev: image

.PHONY: proto
proto:
$(MAKE) -C proto $@
4 changes: 4 additions & 0 deletions calico-vpp-agent/cmd/calico_vpp_dataplane.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,10 @@ func main() {
syscall.SIGUSR2,
)

ctx, cancel := context.WithCancel(context.Background())
defer cancel()
config.HandleUsr2Signal(ctx, log.WithFields(logrus.Fields{"component": "sighdlr"}))

select {
case sig := <-sigChan:
switch sig {
Expand Down
9 changes: 4 additions & 5 deletions calico-vpp-agent/cni/cni_node_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,15 @@ import (

// Names of integration tests arguments
const (
IntegrationTestEnableArgName = "INTEGRATION_TEST"
VppImageArgName = "VPP_IMAGE"
VppBinaryArgName = "VPP_BINARY"
VppContainerExtraArgsName = "VPP_CONTAINER_EXTRA_ARGS"
VppImageArgName = "VPP_IMAGE"
VppBinaryArgName = "VPP_BINARY"
VppContainerExtraArgsName = "VPP_CONTAINER_EXTRA_ARGS"
)

// TestCniIntegration runs all the ginkgo integration test inside CNI package
func TestCniIntegration(t *testing.T) {
// skip test if test run is not integration test run (prevent accidental run of integration tests using go test ./...)
_, isIntegrationTestRun := os.LookupEnv(IntegrationTestEnableArgName)
_, isIntegrationTestRun := os.LookupEnv(VppImageArgName)
if !isIntegrationTestRun {
t.Skip("skipping CNI integration tests (set INTEGRATION_TEST env variable to run these tests)")
}
Expand Down
8 changes: 7 additions & 1 deletion common.mk
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ DEPEND_BASE = calicovpp/ci-builder

VPP_BUCKET = calico-vpp-ci-artefacts

WITH_GDB ?= yes
export GOOS ?= linux

# Docker option
Expand All @@ -23,6 +22,12 @@ ifdef CODEBUILD_BUILD_NUMBER
CI_BUILD = 1
endif

ifdef COVER
COVER_OPTS = -cover -covermode=atomic
else
COVER_OPTS :=
endif

ifdef CI_BUILD
export CI_BUILD
GOFLAGS := -buildvcs=false
Expand Down Expand Up @@ -51,3 +56,4 @@ ifeq (${CODEBUILD_WEBHOOK_TRIGGER},branch/master)
endif

CLUSTER_NAME ?= kind-$(shell whoami)-$(shell git describe --always --abbrev=4)
KIND ?= go run sigs.k8s.io/[email protected]
42 changes: 42 additions & 0 deletions config/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,15 @@
package config

import (
"context"
"crypto/sha512"
"encoding/base64"
"os"
"os/signal"
"runtime/coverage"
"syscall"

"github.com/sirupsen/logrus"
)

/* 8 base64 character hash */
Expand All @@ -32,3 +39,38 @@ func TruncateStr(text string, size int) string {
}
return text
}

// HandleUsr2Signal implements the USR2 signal
// that outputs the covarge data, provided the binary
// is compiled with -cover and GOCOVERDIR is set.
// This allows us to not require a proper binary
// termination in order to get coverage data.
func HandleUsr2Signal(ctx context.Context, log *logrus.Entry) {
usr2SignalChannel := make(chan os.Signal, 1)
signal.Notify(usr2SignalChannel, syscall.SIGUSR2)
go func() {
for {
select {
case <-usr2SignalChannel:
log.Warnf("Received SIGUSR2, writing coverage to %s", os.Getenv("GOCOVERDIR"))
if os.Getenv("GOCOVERDIR") != "" {
err := os.Mkdir(os.Getenv("GOCOVERDIR"), 0750)
if err != nil && !os.IsExist(err) {
log.WithError(err).Errorf("Could not create dir %s", os.Getenv("GOCOVERDIR"))
continue
}
err = coverage.WriteCountersDir(os.Getenv("GOCOVERDIR"))
if err != nil {
log.WithError(err).Error("Could not write counters dir")
}
err = coverage.WriteMetaDir(os.Getenv("GOCOVERDIR"))
if err != nil {
log.WithError(err).Error("Could not write meta dir")
}
}
case <-ctx.Done():
return
}
}
}()
}
Loading
Loading