2020-11-18 09:35:20 +00:00
|
|
|
.PHONY: all test templates yamls
|
2019-05-28 14:13:52 +00:00
|
|
|
.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
|
2020-09-07 16:56:05 +00:00
|
|
|
CONTAINER_RUN_CMD ?= docker run
|
2022-09-07 12:37:12 +00:00
|
|
|
BUILDER_IMAGE ?= golang:1.19-bullseye
|
2022-10-13 12:17:50 +00:00
|
|
|
BASE_IMAGE_FULL ?= debian:bullseye-slim
|
2021-04-20 07:42:33 +00:00
|
|
|
BASE_IMAGE_MINIMAL ?= gcr.io/distroless/base
|
2020-09-07 16:56:05 +00:00
|
|
|
|
|
|
|
# Docker base command for working with html documentation.
|
|
|
|
# Use host networking because 'jekyll serve' is stupid enough to use the
|
|
|
|
# same site url than the "host" it binds to. Thus, all the links will be
|
|
|
|
# broken if we'd bind to 0.0.0.0
|
|
|
|
JEKYLL_VERSION := 3.8
|
2020-10-30 05:51:38 +00:00
|
|
|
JEKYLL_ENV ?= development
|
|
|
|
SITE_BUILD_CMD := $(CONTAINER_RUN_CMD) --rm -i -u "`id -u`:`id -g`" \
|
|
|
|
-e JEKYLL_ENV=$(JEKYLL_ENV) \
|
|
|
|
--volume="$$PWD/docs:/srv/jekyll" \
|
|
|
|
--volume="$$PWD/docs/vendor/bundle:/usr/local/bundle" \
|
|
|
|
--network=host jekyll/jekyll:$(JEKYLL_VERSION)
|
2020-11-02 09:08:49 +00:00
|
|
|
SITE_BASEURL ?=
|
|
|
|
SITE_DESTDIR ?= _site
|
|
|
|
JEKYLL_OPTS := -d '$(SITE_DESTDIR)' $(if $(SITE_BASEURL),-b '$(SITE_BASEURL)',)
|
2018-09-12 13:40:56 +00:00
|
|
|
|
2016-07-19 22:35:42 +00:00
|
|
|
VERSION := $(shell git describe --tags --dirty --always)
|
|
|
|
|
2022-09-12 08:21:12 +00:00
|
|
|
IMAGE_REGISTRY ?= registry.k8s.io/nfd
|
2020-09-06 21:36:41 +00:00
|
|
|
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
|
|
|
|
2021-02-25 15:43:59 +00:00
|
|
|
OPENSHIFT ?=
|
|
|
|
|
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 ?=
|
2020-12-01 18:10:38 +00:00
|
|
|
E2E_PULL_IF_NOT_PRESENT ?= false
|
2018-11-16 12:26:33 +00:00
|
|
|
|
2022-10-06 11:05:11 +00:00
|
|
|
LDFLAGS = -ldflags "-s -w -X sigs.k8s.io/node-feature-discovery/pkg/version.version=$(VERSION) -X sigs.k8s.io/node-feature-discovery/pkg/utils/hostpath.pathPrefix=$(HOSTMOUNT_PREFIX)"
|
2020-05-19 07:32:28 +00:00
|
|
|
|
2021-12-10 12:18:31 +00:00
|
|
|
# multi-arch build with buildx
|
|
|
|
IMAGE_ALL_PLATFORMS ?= linux/amd64,linux/arm64
|
|
|
|
|
|
|
|
# enable buildx
|
|
|
|
ensure-buildx:
|
|
|
|
./hack/init-buildx.sh
|
|
|
|
|
|
|
|
IMAGE_BUILDX_CMD ?= DOCKER_CLI_EXPERIMENTAL=enabled docker buildx build --platform=${IMAGE_ALL_PLATFORMS} --progress=auto --pull
|
|
|
|
|
|
|
|
IMAGE_BUILD_ARGS = --build-arg VERSION=$(VERSION) \
|
2022-06-29 07:10:33 +00:00
|
|
|
--build-arg HOSTMOUNT_PREFIX=$(CONTAINER_HOSTMOUNT_PREFIX) \
|
|
|
|
--build-arg BUILDER_IMAGE=$(BUILDER_IMAGE) \
|
|
|
|
--build-arg BASE_IMAGE_FULL=$(BASE_IMAGE_FULL) \
|
|
|
|
--build-arg BASE_IMAGE_MINIMAL=$(BASE_IMAGE_MINIMAL)
|
2021-12-10 12:18:31 +00:00
|
|
|
|
|
|
|
IMAGE_BUILD_ARGS_FULL = --target full \
|
|
|
|
-t $(IMAGE_TAG) \
|
|
|
|
$(foreach tag,$(IMAGE_EXTRA_TAGS),-t $(tag)) \
|
|
|
|
$(IMAGE_BUILD_EXTRA_OPTS) ./
|
|
|
|
|
|
|
|
IMAGE_BUILD_ARGS_MINIMAL = --target minimal \
|
|
|
|
-t $(IMAGE_TAG)-minimal \
|
|
|
|
$(foreach tag,$(IMAGE_EXTRA_TAGS),-t $(tag)-minimal) \
|
|
|
|
$(IMAGE_BUILD_EXTRA_OPTS) ./
|
|
|
|
|
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
|
2021-12-10 12:18:31 +00:00
|
|
|
$(IMAGE_BUILD_CMD) $(IMAGE_BUILD_ARGS) $(IMAGE_BUILD_ARGS_FULL)
|
|
|
|
$(IMAGE_BUILD_CMD) $(IMAGE_BUILD_ARGS) $(IMAGE_BUILD_ARGS_MINIMAL)
|
|
|
|
|
|
|
|
image-all: ensure-buildx yamls
|
|
|
|
# --load : not implemented yet, see: https://github.com/docker/buildx/issues/59
|
|
|
|
$(IMAGE_BUILDX_CMD) $(IMAGE_BUILD_ARGS) $(IMAGE_BUILD_ARGS_FULL)
|
|
|
|
$(IMAGE_BUILDX_CMD) $(IMAGE_BUILD_ARGS) $(IMAGE_BUILD_ARGS_MINIMAL)
|
|
|
|
|
2018-07-09 10:12:11 +00:00
|
|
|
|
2021-11-23 19:07:34 +00:00
|
|
|
# clean NFD labels on all nodes
|
|
|
|
# devel only
|
|
|
|
deploy-prune:
|
|
|
|
kubectl apply -k deployment/overlays/prune/
|
|
|
|
kubectl wait --for=condition=complete job -l app=nfd -n node-feature-discovery
|
|
|
|
kubectl delete -k deployment/overlays/prune/
|
|
|
|
|
|
|
|
|
2021-08-13 14:35:22 +00:00
|
|
|
yamls:
|
2022-09-06 08:45:46 +00:00
|
|
|
@./hack/kustomize.sh $(K8S_NAMESPACE) $(IMAGE_REPO) $(IMAGE_TAG_NAME)
|
2021-08-13 14:35:22 +00:00
|
|
|
|
2021-11-29 20:11:08 +00:00
|
|
|
deploy: yamls
|
|
|
|
kubectl apply -k .
|
|
|
|
|
2021-08-13 14:35:22 +00:00
|
|
|
templates:
|
2020-11-18 09:35:20 +00:00
|
|
|
@# Need to prepend each line in the sample config with spaces in order to
|
|
|
|
@# fit correctly in the configmap spec.
|
2021-03-11 17:11:08 +00:00
|
|
|
@sed s'/^/ /' deployment/components/worker-config/nfd-worker.conf.example > nfd-worker.conf.tmp
|
2021-02-04 16:17:22 +00:00
|
|
|
@# The sed magic below replaces the block of text between the lines with start and end markers
|
2021-08-13 14:35:22 +00:00
|
|
|
@start=NFD-WORKER-CONF-START-DO-NOT-REMOVE; \
|
|
|
|
end=NFD-WORKER-CONF-END-DO-NOT-REMOVE; \
|
|
|
|
sed -e "/$$start/,/$$end/{ /$$start/{ p; r nfd-worker.conf.tmp" \
|
|
|
|
-e "}; /$$end/p; d }" -i deployment/helm/node-feature-discovery/values.yaml
|
2020-11-18 09:35:20 +00:00
|
|
|
@rm nfd-worker.conf.tmp
|
|
|
|
|
Containerized auto-generation
Run code auto-generation inside a container instead of the host system.
Our auto-generation depends on specific versions of a multitude of tools
(like k8s code-generator, controller-gen, protoc, mockery etc). This
made it really awkward (and error-prone) to run in the host environment,
especially if/when you needed different versions of those tools for
other projects. Making it even more unwieldy, the required versions of
tools were not neatly documented anywhere (except for git commits,
perhaps).
With this patch we have a "fixed environment", as we build a special
auto-generate-builder container which has correct versions of all the
dependencies. Using the container makes auto-generation easy to run
anywhere, independent of the host system, giving reproducibility and
reliability. Also, the patch moves the auto-generation steps out from
the makefile into a separate script, making the makefile cleaner and the
script easier to maintain.
2022-06-14 15:02:23 +00:00
|
|
|
.generator.image.stamp: Dockerfile_generator
|
2022-09-08 09:26:39 +00:00
|
|
|
$(IMAGE_BUILD_CMD) \
|
|
|
|
--build-arg BUILDER_IMAGE=$(BUILDER_IMAGE) \
|
|
|
|
-t nfd-generator \
|
|
|
|
-f Dockerfile_generator .
|
Containerized auto-generation
Run code auto-generation inside a container instead of the host system.
Our auto-generation depends on specific versions of a multitude of tools
(like k8s code-generator, controller-gen, protoc, mockery etc). This
made it really awkward (and error-prone) to run in the host environment,
especially if/when you needed different versions of those tools for
other projects. Making it even more unwieldy, the required versions of
tools were not neatly documented anywhere (except for git commits,
perhaps).
With this patch we have a "fixed environment", as we build a special
auto-generate-builder container which has correct versions of all the
dependencies. Using the container makes auto-generation easy to run
anywhere, independent of the host system, giving reproducibility and
reliability. Also, the patch moves the auto-generation steps out from
the makefile into a separate script, making the makefile cleaner and the
script easier to maintain.
2022-06-14 15:02:23 +00:00
|
|
|
|
|
|
|
generate: .generator.image.stamp
|
|
|
|
$(CONTAINER_RUN_CMD) --rm \
|
|
|
|
-v "`pwd`:/go/node-feature-discovery" \
|
|
|
|
-v "`go env GOCACHE`:/.cache" \
|
|
|
|
-v "`go env GOMODCACHE`:/go/pkg/mod" \
|
|
|
|
--user=`id -u`:`id -g`\
|
|
|
|
nfd-generator \
|
|
|
|
./hack/generate.sh
|
2021-06-10 06:55:22 +00:00
|
|
|
|
2020-05-19 11:19:18 +00:00
|
|
|
gofmt:
|
|
|
|
@$(GO_FMT) -w -l $$(find . -name '*.go')
|
|
|
|
|
|
|
|
gofmt-verify:
|
2021-10-22 09:03:24 +00:00
|
|
|
@out=`$(GO_FMT) -w -l -d $$(find . -name '*.go')`; \
|
2020-05-19 11:19:18 +00:00
|
|
|
if [ -n "$$out" ]; then \
|
|
|
|
echo "$$out"; \
|
|
|
|
exit 1; \
|
|
|
|
fi
|
|
|
|
|
2020-05-19 11:45:52 +00:00
|
|
|
ci-lint:
|
2021-03-02 18:08:58 +00:00
|
|
|
golangci-lint run --timeout 7m0s
|
2020-05-19 11:19:18 +00:00
|
|
|
|
2021-07-07 06:54:01 +00:00
|
|
|
lint:
|
|
|
|
golint -set_exit_status ./...
|
|
|
|
|
2021-02-25 11:44:01 +00:00
|
|
|
mdlint:
|
2022-09-02 13:47:17 +00:00
|
|
|
${CONTAINER_RUN_CMD} \
|
|
|
|
--rm \
|
|
|
|
--volume "${PWD}:/workdir:ro,z" \
|
|
|
|
--workdir /workdir \
|
|
|
|
ruby:slim \
|
|
|
|
/workdir/scripts/test-infra/mdlint.sh
|
2021-02-25 11:44:01 +00:00
|
|
|
|
2021-02-26 04:56:36 +00:00
|
|
|
helm-lint:
|
2021-03-11 16:50:33 +00:00
|
|
|
helm lint --strict deployment/helm/node-feature-discovery/
|
2021-02-26 04:56:36 +00:00
|
|
|
|
2019-01-23 08:15:47 +00:00
|
|
|
test:
|
2021-03-01 07:02:22 +00:00
|
|
|
$(GO_CMD) test ./cmd/... ./pkg/... ./source/...
|
2018-11-16 13:03:46 +00:00
|
|
|
|
2018-11-16 15:08:51 +00:00
|
|
|
e2e-test:
|
2020-11-24 11:47:43 +00:00
|
|
|
@if [ -z ${KUBECONFIG} ]; then echo "[ERR] KUBECONFIG missing, must be defined"; exit 1; fi
|
2021-02-25 15:43:59 +00:00
|
|
|
$(GO_CMD) test -v ./test/e2e/ -args -nfd.repo=$(IMAGE_REPO) -nfd.tag=$(IMAGE_TAG_NAME) \
|
2020-12-01 18:10:38 +00:00
|
|
|
-kubeconfig=$(KUBECONFIG) \
|
|
|
|
-nfd.e2e-config=$(E2E_TEST_CONFIG) \
|
|
|
|
-nfd.pull-if-not-present=$(E2E_PULL_IF_NOT_PRESENT) \
|
|
|
|
-ginkgo.focus="\[kubernetes-sigs\]" \
|
2021-03-09 10:26:40 +00:00
|
|
|
$(if $(OPENSHIFT),-nfd.openshift,)
|
|
|
|
$(GO_CMD) test -v ./test/e2e/ -args -nfd.repo=$(IMAGE_REPO) -nfd.tag=$(IMAGE_TAG_NAME)-minimal \
|
2020-12-01 18:10:38 +00:00
|
|
|
-kubeconfig=$(KUBECONFIG) \
|
|
|
|
-nfd.e2e-config=$(E2E_TEST_CONFIG) \
|
|
|
|
-nfd.pull-if-not-present=$(E2E_PULL_IF_NOT_PRESENT) \
|
|
|
|
-ginkgo.focus="\[kubernetes-sigs\]" \
|
2021-02-25 15:43:59 +00:00
|
|
|
$(if $(OPENSHIFT),-nfd.openshift,)
|
2018-11-16 15:08:51 +00:00
|
|
|
|
2018-11-16 13:03:46 +00:00
|
|
|
push:
|
|
|
|
$(IMAGE_PUSH_CMD) $(IMAGE_TAG)
|
2021-03-09 09:53:52 +00:00
|
|
|
$(IMAGE_PUSH_CMD) $(IMAGE_TAG)-minimal
|
|
|
|
for tag in $(IMAGE_EXTRA_TAGS); do $(IMAGE_PUSH_CMD) $$tag; $(IMAGE_PUSH_CMD) $$tag-minimal; done
|
2020-08-20 16:03:26 +00:00
|
|
|
|
2022-01-20 16:01:54 +00:00
|
|
|
push-all: ensure-buildx yamls
|
2021-12-10 12:18:31 +00:00
|
|
|
$(IMAGE_BUILDX_CMD) --push $(IMAGE_BUILD_ARGS) $(IMAGE_BUILD_ARGS_FULL)
|
|
|
|
$(IMAGE_BUILDX_CMD) --push $(IMAGE_BUILD_ARGS) $(IMAGE_BUILD_ARGS_MINIMAL)
|
|
|
|
|
2021-03-09 10:13:02 +00:00
|
|
|
poll-images:
|
2020-08-20 16:03:26 +00:00
|
|
|
set -e; \
|
2021-03-09 10:13:02 +00:00
|
|
|
tags="$(foreach tag,$(IMAGE_TAG_NAME) $(IMAGE_EXTRA_TAG_NAMES),$(tag) $(tag)-minimal)" \
|
2020-08-20 16:03:26 +00:00
|
|
|
base_url=`echo $(IMAGE_REPO) | sed -e s'!\([^/]*\)!\1/v2!'`; \
|
2021-03-09 10:13:02 +00:00
|
|
|
for tag in $$tags; do \
|
|
|
|
image=$(IMAGE_REPO):$$tag \
|
|
|
|
errors=`curl -fsS -X GET https://$$base_url/manifests/$$tag|jq .errors`; \
|
|
|
|
if [ "$$errors" = "null" ]; then \
|
|
|
|
echo Image $$image found; \
|
|
|
|
else \
|
|
|
|
echo Image $$image not found; \
|
|
|
|
exit 1; \
|
|
|
|
fi; \
|
|
|
|
done
|
2020-09-07 16:56:05 +00:00
|
|
|
|
|
|
|
site-build:
|
|
|
|
@mkdir -p docs/vendor/bundle
|
|
|
|
$(SITE_BUILD_CMD) sh -c "bundle install && jekyll build $(JEKYLL_OPTS)"
|
|
|
|
|
|
|
|
site-serve:
|
|
|
|
@mkdir -p docs/vendor/bundle
|
2020-11-02 09:08:49 +00:00
|
|
|
$(SITE_BUILD_CMD) sh -c "bundle install && jekyll serve $(JEKYLL_OPTS) -H 127.0.0.1"
|