Skip to content

Commit 81ba74c

Browse files
authored
Merge pull request #310 from sunya-ch/upgrade-multi-nicd-ginkgo
2 parents aa1e9d4 + fd8748b commit 81ba74c

File tree

12 files changed

+400
-268
lines changed

12 files changed

+400
-268
lines changed

Makefile

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ lint: tidy fmt vet golangci-lint ## Run the lint check
148148
pr: lint test yaml ## Run targets required for PR
149149

150150
##@ Test
151+
ARCH = $(shell go env GOARCH)
151152
TEST_BIN_DIR = $(BASE_DIR)/tools/testbin
152153
TEST_RESULT_DIR = $(BASE_DIR)/testing
153154
ENVTEST ?= $(TEST_BIN_DIR)/setup-envtest
@@ -307,9 +308,9 @@ catalog-push: ## Push a catalog image.
307308
$(MAKE) docker-push IMG=$(CATALOG_IMG)
308309

309310
test-daemon:
310-
$(DOCKER) build -t daemon-test:latest -f ./daemon/dockerfiles/Dockerfile.multi-nicd-test .
311-
$(DOCKER) run -i --privileged daemon-test /bin/bash -c "cd /usr/local/build/cni&&make test"
312-
$(DOCKER) run -i --privileged daemon-test /bin/bash -c "cd /usr/local/build/daemon/src&&make test-verbose"
311+
$(DOCKER) build --platform linux/$(ARCH) -t daemon-test:latest -f ./daemon/dockerfiles/Dockerfile.multi-nicd-test .
312+
$(DOCKER) run --platform linux/$(ARCH) -i --rm --privileged daemon-test /bin/bash -c "cd /usr/local/build/cni&&make test"
313+
$(DOCKER) run --platform linux/$(ARCH) -i --rm -v ./testing:/usr/local/build/daemon/src/testing --privileged daemon-test /bin/bash -c "cd /usr/local/build/daemon/src&&make test"
313314

314315
build-push-kbuilder-base:
315316
$(DOCKER) build -t $(IMAGE_TAG_BASE)-kbuilder:v$(VERSION) -f ./daemon/dockerfiles/Dockerfile.kbuilder .

daemon/Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ DAEMON_IMG ?= $(IMAGE_TAG_BASE)-daemon:v1.2.9
1212
test-verbose:
1313
$(MAKE) -C src test-verbose
1414

15-
test-env:
16-
$(MAKE) -C src test-env
15+
test:
16+
$(MAKE) -C src test
1717

1818
update-cni-local:
1919
ifeq ($(shell uname), Linux)

daemon/dockerfiles/Dockerfile.kbuilder

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
FROM ubuntu:20.04
22

33
RUN apt-get update \
4-
&& apt-get install -y wget tar build-essential net-tools iproute2 git curl \
4+
&& apt-get install -y wget tar build-essential net-tools iproute2 git curl jq \
55
&& rm -rf /var/lib/apt/lists/*
66

77
# install go

daemon/dockerfiles/Dockerfile.multi-nicd-test

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
FROM ghcr.io/foundation-model-stack/multi-nic-cni-kbuilder:v1.2.9
22

3+
RUN apt-get update \
4+
&& apt-get install -y jq \
5+
&& rm -rf /var/lib/apt/lists/*
6+
37
RUN mkdir -p /usr/local/app
48
RUN mkdir -p /host/opt/cni/bin
59

@@ -18,12 +22,9 @@ RUN cd cni && go mod tidy && go build -o /usr/local/app/aws-ipvlan ./plugins/mai
1822
RUN cd cni && make ginkgo-set
1923
# build Daemon
2024
COPY daemon daemon
25+
COPY hack daemon/hack
2126
RUN mkdir -p /usr/local/kubebuilder
2227
RUN mkdir -p /usr/local/build/daemon/src/test-bin
23-
RUN curl -sSLo setup-envtest.sh https://raw.githubusercontent.com/kubernetes-sigs/controller-runtime/v0.7.2/hack/setup-envtest.sh
24-
RUN cp setup-envtest.sh /usr/local/build/daemon/src/test-bin/setup-envtest.sh
25-
RUN cd daemon/src && make test-env && cp -r /usr/local/build/daemon/src/test-bin/bin /usr/local/kubebuilder/bin
26-
RUN mkdir -p daemon/src/test-bin
2728
RUN cd daemon/src && go mod tidy
2829
RUN cd daemon/src && go build -o /usr/local/app/daemon
2930
RUN cp /usr/local/app/multi-nic /usr/local/bin \

daemon/src/Makefile

Lines changed: 46 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,52 @@
44
#
55
all: build
66

7-
ENVTEST_ASSETS_DIR=$(PWD)/test-bin
8-
export PATH := $(PATH):$(ENVTEST_ASSETS_DIR)
9-
10-
test-env: SHELL := /bin/bash
11-
test-env:
12-
mkdir -p ${ENVTEST_ASSETS_DIR}
13-
test -f ${ENVTEST_ASSETS_DIR}/setup-envtest.sh || curl -sSLo ${ENVTEST_ASSETS_DIR}/setup-envtest.sh https://raw.githubusercontent.com/kubernetes-sigs/controller-runtime/v0.7.2/hack/setup-envtest.sh
14-
source ${ENVTEST_ASSETS_DIR}/setup-envtest.sh; fetch_envtest_tools $(ENVTEST_ASSETS_DIR); setup_envtest_env $(ENVTEST_ASSETS_DIR);
15-
cp -r ${ENVTEST_ASSETS_DIR}/bin /usr/local/kubebuilder/bin
16-
17-
test: SHELL := /bin/bash
18-
test: test-env ## Run tests.
19-
go test ./... -coverprofile cover.out
7+
BASE_DIR=$(shell pwd)
8+
9+
##@ Test
10+
TEST_BIN_DIR = $(BASE_DIR)/tools/testbin
11+
TEST_RESULT_DIR = $(BASE_DIR)/testing
12+
ENVTEST ?= $(TEST_BIN_DIR)/setup-envtest
13+
GINKGO ?= $(TEST_BIN_DIR)/ginkgo
14+
ENVTEST_K8S_VERSION ?= 1.28.3
15+
16+
$(TEST_BIN_DIR):
17+
mkdir -p $(TEST_BIN_DIR)
18+
19+
$(TEST_RESULT_DIR):
20+
mkdir -p $(TEST_RESULT_DIR)
21+
22+
# go-get-tool will 'go get' any package $3 and install it to $2 in folder $1.
23+
define go-get-tool
24+
@[ -f $(2) ] || { \
25+
set -e ;\
26+
TMP_DIR=$$(mktemp -d) ;\
27+
cd $$TMP_DIR ;\
28+
go mod init tmp ;\
29+
echo "Downloading $(3)" ;\
30+
GOBIN=$(1) go install $(3) ;\
31+
ls $$TMP_DIR;\
32+
echo $(2);\
33+
rm -rf $$TMP_DIR ;\
34+
}
35+
endef
36+
37+
.PHONY: ginkgo
38+
ginkgo: $(GINKGO) ## Download and install ginkgo locally if necessary.
39+
$(GINKGO): $(TEST_BIN_DIR)
40+
$(call go-get-tool,$(TEST_BIN_DIR),$(GINKGO),github.com/onsi/ginkgo/v2/ginkgo@v2.21.0)
41+
42+
.PHONY: envtest
43+
envtest: $(ENVTEST) ## Download and install setup-envtest locally if necessary.
44+
$(ENVTEST): $(TEST_BIN_DIR)
45+
$(call go-get-tool,$(TEST_BIN_DIR),$(ENVTEST),sigs.k8s.io/controller-runtime/tools/setup-envtest@v0.0.0-20240624150636-162a113134de)
46+
47+
.PHONY: test
48+
test: $(TEST_RESULT_DIR) ginkgo envtest
49+
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) -p path)" $(TEST_BIN_DIR)/ginkgo run --cover --coverprofile=multi-nicd-coverage --json-report multi-nicd-unittest-report.json ./...
50+
@../hack/json-report-to-markdown.sh multi-nicd-unittest-report "Unit Test"
51+
@rm multi-nicd-unittest-report.json
52+
@../hack/coverage-to-markdown.sh multi-nicd-coverage "Multi-NIC Daemon Unit Test Coverage"
2053

2154
build: test
2255
@go build -o ../bin/daemon .

daemon/src/allocator/allocator_test.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,13 @@
66
package allocator
77

88
import (
9-
. "github.com/onsi/ginkgo"
10-
. "github.com/onsi/gomega"
119
"testing"
1210

11+
. "github.com/onsi/ginkgo/v2"
12+
. "github.com/onsi/gomega"
13+
1314
"time"
15+
1416
"github.com/foundation-model-stack/multi-nic-cni/daemon/backend"
1517
)
1618

daemon/src/go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ go 1.23
55
require (
66
github.com/gorilla/mux v1.8.0
77
github.com/jaypipes/ghw v0.14.0
8-
github.com/onsi/ginkgo v1.16.5
9-
github.com/onsi/gomega v1.18.1
8+
github.com/onsi/ginkgo/v2 v2.21.0
9+
github.com/onsi/gomega v1.36.1
1010
github.com/vishvananda/netlink v1.1.1-0.20210330154013-f5de75959ad5
1111
k8s.io/api v0.23.3
1212
k8s.io/apiextensions-apiserver v0.23.0

0 commit comments

Comments
 (0)