2019-05-28 14:13:52 +00:00
|
|
|
.PHONY: all test yamls
|
|
|
|
.FORCE:
|
2016-07-19 22:35:42 +00:00
|
|
|
|
2020-09-06 21:36:41 +00:00
|
|
|
GO_CMD ?= go
|
|
|
|
GO_FMT ?= gofmt
|
2019-12-16 13:37:53 +00:00
|
|
|
|
2020-09-06 21:36:41 +00:00
|
|
|
IMAGE_BUILD_CMD ?= docker build
|
|
|
|
IMAGE_BUILD_EXTRA_OPTS ?=
|
|
|
|
IMAGE_PUSH_CMD ?= docker push
|
2018-09-12 13:40:56 +00:00
|
|
|
|
2016-07-19 22:35:42 +00:00
|
|
|
VERSION := $(shell git describe --tags --dirty --always)
|
|
|
|
|
2020-09-06 21:36:41 +00:00
|
|
|
IMAGE_REGISTRY ?= k8s.gcr.io/nfd
|
|
|
|
IMAGE_TAG_NAME ?= $(VERSION)
|
|
|
|
IMAGE_EXTRA_TAG_NAMES ?=
|
2020-09-08 13:24:39 +00:00
|
|
|
|
|
|
|
IMAGE_NAME := node-feature-discovery
|
2018-11-16 12:26:33 +00:00
|
|
|
IMAGE_REPO := $(IMAGE_REGISTRY)/$(IMAGE_NAME)
|
|
|
|
IMAGE_TAG := $(IMAGE_REPO):$(IMAGE_TAG_NAME)
|
2020-09-03 09:07:13 +00:00
|
|
|
IMAGE_EXTRA_TAGS := $(foreach tag,$(IMAGE_EXTRA_TAG_NAMES),$(IMAGE_REPO):$(tag))
|
2020-09-08 13:24:39 +00:00
|
|
|
|
2020-10-01 10:52:10 +00:00
|
|
|
K8S_NAMESPACE ?= node-feature-discovery
|
2020-05-19 07:43:14 +00:00
|
|
|
|
|
|
|
# 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
|
2020-09-06 21:36:41 +00:00
|
|
|
HOSTMOUNT_PREFIX ?= /
|
2020-05-19 07:43:14 +00:00
|
|
|
|
2020-09-08 13:24:39 +00:00
|
|
|
KUBECONFIG ?=
|
|
|
|
E2E_TEST_CONFIG ?=
|
2018-11-16 12:26:33 +00:00
|
|
|
|
2020-05-19 07:43:14 +00:00
|
|
|
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)"
|
2020-05-19 07:32:28 +00:00
|
|
|
|
2019-05-28 14:13:52 +00:00
|
|
|
yaml_templates := $(wildcard *.yaml.template)
|
|
|
|
yaml_instances := $(patsubst %.yaml.template,%.yaml,$(yaml_templates))
|
2018-11-16 12:26:33 +00:00
|
|
|
|
2018-09-12 13:40:56 +00:00
|
|
|
all: image
|
2016-07-19 22:35:42 +00:00
|
|
|
|
2020-05-19 07:32:28 +00:00
|
|
|
build:
|
|
|
|
@mkdir -p bin
|
|
|
|
$(GO_CMD) build -v -o bin $(LDFLAGS) ./cmd/...
|
|
|
|
|
2020-05-19 07:39:39 +00:00
|
|
|
install:
|
|
|
|
$(GO_CMD) install -v $(LDFLAGS) ./cmd/...
|
|
|
|
|
2019-05-28 14:13:52 +00:00
|
|
|
image: yamls
|
2020-05-19 09:21:37 +00:00
|
|
|
$(IMAGE_BUILD_CMD) --build-arg VERSION=$(VERSION) \
|
2020-05-19 07:43:14 +00:00
|
|
|
--build-arg HOSTMOUNT_PREFIX=$(CONTAINER_HOSTMOUNT_PREFIX) \
|
2018-11-16 13:32:48 +00:00
|
|
|
-t $(IMAGE_TAG) \
|
2020-09-03 09:07:13 +00:00
|
|
|
$(foreach tag,$(IMAGE_EXTRA_TAGS),-t $(tag)) \
|
2018-11-16 13:32:48 +00:00
|
|
|
$(IMAGE_BUILD_EXTRA_OPTS) ./
|
2018-07-09 10:12:11 +00:00
|
|
|
|
2019-05-28 14:13:52 +00:00
|
|
|
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},' \
|
2020-05-19 07:43:14 +00:00
|
|
|
-e s',^(\s*)mountPath: "/host-,\1mountPath: "${CONTAINER_HOSTMOUNT_PREFIX},' \
|
2019-05-28 14:13:52 +00:00
|
|
|
$< > $@
|
|
|
|
|
2018-07-09 10:12:11 +00:00
|
|
|
mock:
|
|
|
|
mockery --name=FeatureSource --dir=source --inpkg --note="Re-generate by running 'make mock'"
|
2019-01-23 08:15:47 +00:00
|
|
|
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'"
|
|
|
|
|
2020-05-19 11:19:18 +00:00
|
|
|
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
|
|
|
|
|
2020-05-19 11:45:52 +00:00
|
|
|
ci-lint:
|
|
|
|
golangci-lint run --timeout 5m0s
|
2020-05-19 11:19:18 +00:00
|
|
|
|
2019-01-23 08:15:47 +00:00
|
|
|
test:
|
2019-12-16 13:37:53 +00:00
|
|
|
$(GO_CMD) test ./cmd/... ./pkg/...
|
2018-11-16 13:03:46 +00:00
|
|
|
|
2018-11-16 15:08:51 +00:00
|
|
|
e2e-test:
|
2020-02-21 14:16:37 +00:00
|
|
|
$(GO_CMD) test -v ./test/e2e/ -args -nfd.repo=$(IMAGE_REPO) -nfd.tag=$(IMAGE_TAG_NAME) -kubeconfig=$(KUBECONFIG) -nfd.e2e-config=$(E2E_TEST_CONFIG)
|
2018-11-16 15:08:51 +00:00
|
|
|
|
2018-11-16 13:03:46 +00:00
|
|
|
push:
|
|
|
|
$(IMAGE_PUSH_CMD) $(IMAGE_TAG)
|
2020-09-03 09:07:13 +00:00
|
|
|
for tag in $(IMAGE_EXTRA_TAGS); do $(IMAGE_PUSH_CMD) $$tag; done
|
2020-08-20 16:03:26 +00:00
|
|
|
|
|
|
|
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;
|