Skip to content
Merged
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
7 changes: 4 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ lint: tidy fmt vet golangci-lint ## Run the lint check
pr: lint test yaml ## Run targets required for PR

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

test-daemon:
$(DOCKER) build -t daemon-test:latest -f ./daemon/dockerfiles/Dockerfile.multi-nicd-test .
$(DOCKER) run -i --privileged daemon-test /bin/bash -c "cd /usr/local/build/cni&&make test"
$(DOCKER) run -i --privileged daemon-test /bin/bash -c "cd /usr/local/build/daemon/src&&make test-verbose"
$(DOCKER) build --platform linux/$(ARCH) -t daemon-test:latest -f ./daemon/dockerfiles/Dockerfile.multi-nicd-test .
$(DOCKER) run --platform linux/$(ARCH) -i --rm --privileged daemon-test /bin/bash -c "cd /usr/local/build/cni&&make test"
$(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"

build-push-kbuilder-base:
$(DOCKER) build -t $(IMAGE_TAG_BASE)-kbuilder:v$(VERSION) -f ./daemon/dockerfiles/Dockerfile.kbuilder .
Expand Down
4 changes: 2 additions & 2 deletions daemon/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ DAEMON_IMG ?= $(IMAGE_TAG_BASE)-daemon:v1.2.9
test-verbose:
$(MAKE) -C src test-verbose

test-env:
$(MAKE) -C src test-env
test:
$(MAKE) -C src test

update-cni-local:
ifeq ($(shell uname), Linux)
Expand Down
2 changes: 1 addition & 1 deletion daemon/dockerfiles/Dockerfile.kbuilder
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
FROM ubuntu:20.04

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

# install go
Expand Down
9 changes: 5 additions & 4 deletions daemon/dockerfiles/Dockerfile.multi-nicd-test
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
FROM ghcr.io/foundation-model-stack/multi-nic-cni-kbuilder:v1.2.9

RUN apt-get update \
&& apt-get install -y jq \
&& rm -rf /var/lib/apt/lists/*

RUN mkdir -p /usr/local/app
RUN mkdir -p /host/opt/cni/bin

Expand All @@ -18,12 +22,9 @@ RUN cd cni && go mod tidy && go build -o /usr/local/app/aws-ipvlan ./plugins/mai
RUN cd cni && make ginkgo-set
# build Daemon
COPY daemon daemon
COPY hack daemon/hack
RUN mkdir -p /usr/local/kubebuilder
RUN mkdir -p /usr/local/build/daemon/src/test-bin
RUN curl -sSLo setup-envtest.sh https://raw.githubusercontent.com/kubernetes-sigs/controller-runtime/v0.7.2/hack/setup-envtest.sh
RUN cp setup-envtest.sh /usr/local/build/daemon/src/test-bin/setup-envtest.sh
RUN cd daemon/src && make test-env && cp -r /usr/local/build/daemon/src/test-bin/bin /usr/local/kubebuilder/bin
RUN mkdir -p daemon/src/test-bin
RUN cd daemon/src && go mod tidy
RUN cd daemon/src && go build -o /usr/local/app/daemon
RUN cp /usr/local/app/multi-nic /usr/local/bin \
Expand Down
59 changes: 46 additions & 13 deletions daemon/src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,52 @@
#
all: build

ENVTEST_ASSETS_DIR=$(PWD)/test-bin
export PATH := $(PATH):$(ENVTEST_ASSETS_DIR)

test-env: SHELL := /bin/bash
test-env:
mkdir -p ${ENVTEST_ASSETS_DIR}
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
source ${ENVTEST_ASSETS_DIR}/setup-envtest.sh; fetch_envtest_tools $(ENVTEST_ASSETS_DIR); setup_envtest_env $(ENVTEST_ASSETS_DIR);
cp -r ${ENVTEST_ASSETS_DIR}/bin /usr/local/kubebuilder/bin

test: SHELL := /bin/bash
test: test-env ## Run tests.
go test ./... -coverprofile cover.out
BASE_DIR=$(shell pwd)

##@ Test
TEST_BIN_DIR = $(BASE_DIR)/tools/testbin
TEST_RESULT_DIR = $(BASE_DIR)/testing
ENVTEST ?= $(TEST_BIN_DIR)/setup-envtest
GINKGO ?= $(TEST_BIN_DIR)/ginkgo
ENVTEST_K8S_VERSION ?= 1.28.3

$(TEST_BIN_DIR):
mkdir -p $(TEST_BIN_DIR)

$(TEST_RESULT_DIR):
mkdir -p $(TEST_RESULT_DIR)

# go-get-tool will 'go get' any package $3 and install it to $2 in folder $1.
define go-get-tool
@[ -f $(2) ] || { \
set -e ;\
TMP_DIR=$$(mktemp -d) ;\
cd $$TMP_DIR ;\
go mod init tmp ;\
echo "Downloading $(3)" ;\
GOBIN=$(1) go install $(3) ;\
ls $$TMP_DIR;\
echo $(2);\
rm -rf $$TMP_DIR ;\
}
endef

.PHONY: ginkgo
ginkgo: $(GINKGO) ## Download and install ginkgo locally if necessary.
$(GINKGO): $(TEST_BIN_DIR)
$(call go-get-tool,$(TEST_BIN_DIR),$(GINKGO),github.com/onsi/ginkgo/v2/[email protected])

.PHONY: envtest
envtest: $(ENVTEST) ## Download and install setup-envtest locally if necessary.
$(ENVTEST): $(TEST_BIN_DIR)
$(call go-get-tool,$(TEST_BIN_DIR),$(ENVTEST),sigs.k8s.io/controller-runtime/tools/[email protected])

.PHONY: test
test: $(TEST_RESULT_DIR) ginkgo envtest
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 ./...
@../hack/json-report-to-markdown.sh multi-nicd-unittest-report "Unit Test"
@rm multi-nicd-unittest-report.json
@../hack/coverage-to-markdown.sh multi-nicd-coverage "Multi-NIC Daemon Unit Test Coverage"

build: test
@go build -o ../bin/daemon .
Expand Down
6 changes: 4 additions & 2 deletions daemon/src/allocator/allocator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@
package allocator

import (
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"testing"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"

"time"

"github.com/foundation-model-stack/multi-nic-cni/daemon/backend"
)

Expand Down
4 changes: 2 additions & 2 deletions daemon/src/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ go 1.23
require (
github.com/gorilla/mux v1.8.0
github.com/jaypipes/ghw v0.14.0
github.com/onsi/ginkgo v1.16.5
github.com/onsi/gomega v1.18.1
github.com/onsi/ginkgo/v2 v2.21.0
github.com/onsi/gomega v1.36.1
github.com/vishvananda/netlink v1.1.1-0.20210330154013-f5de75959ad5
k8s.io/api v0.23.3
k8s.io/apiextensions-apiserver v0.23.0
Expand Down
Loading
Loading