1
0
Fork 0
mirror of https://github.com/kubernetes-sigs/node-feature-discovery.git synced 2024-12-15 17:50:49 +00:00
node-feature-discovery/Makefile
Markus Lehtonen 05f5d2a88a scripts/test-infra: add script for end-to-end testing
Add a new script for running end-to-end tests. Implement a Makefile rule
for polling the container image. We need this for prow as there is no
other way for syncing the jobs (e2e postsubmit job must wait until the
image-pushing job has built and published the image). This is
implemented in the Makefile as all the image-related variables are also
defined/available there.

Also, adapt the TravisCI config to use the new script.
2020-08-27 14:48:37 +03:00

101 lines
2.9 KiB
Makefile

.PHONY: all test yamls
.FORCE:
GO_CMD := go
GO_FMT := gofmt
IMAGE_BUILD_CMD := docker build
IMAGE_BUILD_EXTRA_OPTS :=
IMAGE_PUSH_CMD := docker push
VERSION := $(shell git describe --tags --dirty --always)
IMAGE_REGISTRY := k8s.gcr.io/nfd
IMAGE_NAME := node-feature-discovery
IMAGE_TAG_NAME := $(VERSION)
IMAGE_REPO := $(IMAGE_REGISTRY)/$(IMAGE_NAME)
IMAGE_TAG := $(IMAGE_REPO):$(IMAGE_TAG_NAME)
K8S_NAMESPACE := kube-system
# We use different mount prefix for local and container builds.
# Take CONTAINER_HOSTMOUNT_PREFIX from HOSTMOUNT_PREFIX if only the latter is specified
ifdef HOSTMOUNT_PREFIX
CONTAINER_HOSTMOUNT_PREFIX := $(HOSTMOUNT_PREFIX)
else
CONTAINER_HOSTMOUNT_PREFIX := /host-
endif
HOSTMOUNT_PREFIX := /
KUBECONFIG :=
E2E_TEST_CONFIG :=
LDFLAGS = -ldflags "-s -w -X sigs.k8s.io/node-feature-discovery/pkg/version.version=$(VERSION) -X sigs.k8s.io/node-feature-discovery/source.pathPrefix=$(HOSTMOUNT_PREFIX)"
yaml_templates := $(wildcard *.yaml.template)
yaml_instances := $(patsubst %.yaml.template,%.yaml,$(yaml_templates))
all: image
build:
@mkdir -p bin
$(GO_CMD) build -v -o bin $(LDFLAGS) ./cmd/...
install:
$(GO_CMD) install -v $(LDFLAGS) ./cmd/...
image: yamls
$(IMAGE_BUILD_CMD) --build-arg VERSION=$(VERSION) \
--build-arg HOSTMOUNT_PREFIX=$(CONTAINER_HOSTMOUNT_PREFIX) \
-t $(IMAGE_TAG) \
$(IMAGE_BUILD_EXTRA_OPTS) ./
yamls: $(yaml_instances)
%.yaml: %.yaml.template .FORCE
@echo "$@: namespace: ${K8S_NAMESPACE}"
@echo "$@: image: ${IMAGE_TAG}"
@sed -E \
-e s',^(\s*)name: node-feature-discovery # NFD namespace,\1name: ${K8S_NAMESPACE},' \
-e s',^(\s*)image:.+$$,\1image: ${IMAGE_TAG},' \
-e s',^(\s*)namespace:.+$$,\1namespace: ${K8S_NAMESPACE},' \
-e s',^(\s*)mountPath: "/host-,\1mountPath: "${CONTAINER_HOSTMOUNT_PREFIX},' \
$< > $@
mock:
mockery --name=FeatureSource --dir=source --inpkg --note="Re-generate by running 'make mock'"
mockery --name=APIHelpers --dir=pkg/apihelper --inpkg --note="Re-generate by running 'make mock'"
mockery --name=LabelerClient --dir=pkg/labeler --inpkg --note="Re-generate by running 'make mock'"
gofmt:
@$(GO_FMT) -w -l $$(find . -name '*.go')
gofmt-verify:
@out=`$(GO_FMT) -l -d $$(find . -name '*.go')`; \
if [ -n "$$out" ]; then \
echo "$$out"; \
exit 1; \
fi
ci-lint:
golangci-lint run --timeout 5m0s
test:
$(GO_CMD) test ./cmd/... ./pkg/...
e2e-test:
$(GO_CMD) test -v ./test/e2e/ -args -nfd.repo=$(IMAGE_REPO) -nfd.tag=$(IMAGE_TAG_NAME) -kubeconfig=$(KUBECONFIG) -nfd.e2e-config=$(E2E_TEST_CONFIG)
push:
$(IMAGE_PUSH_CMD) $(IMAGE_TAG)
poll-image:
set -e; \
image=$(IMAGE_REPO):$(IMAGE_TAG_NAME); \
base_url=`echo $(IMAGE_REPO) | sed -e s'!\([^/]*\)!\1/v2!'`; \
errors=`curl -fsS -X GET https://$$base_url/manifests/$(IMAGE_TAG_NAME)|jq .errors`; \
if [ "$$errors" = "null" ]; then \
echo Image $$image found; \
else \
echo Image $$image not found; \
exit 1; \
fi;