From 02dc1ae1e9fdf14306430f7aee63f301f0300b25 Mon Sep 17 00:00:00 2001 From: Markus Lehtonen Date: Tue, 19 May 2020 10:32:28 +0300 Subject: [PATCH 1/5] Makefile: add build target --- Makefile | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Makefile b/Makefile index d13b81fd6..2dc4076fc 100644 --- a/Makefile +++ b/Makefile @@ -20,11 +20,17 @@ HOSTMOUNT_PREFIX := /host- KUBECONFIG := E2E_TEST_CONFIG := +LDFLAGS = -ldflags "-s -w -X sigs.k8s.io/node-feature-discovery/pkg/version.version=$(VERSION)" + 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/... + image: yamls $(IMAGE_BUILD_CMD) --build-arg NFD_VERSION=$(VERSION) \ --build-arg HOSTMOUNT_PREFIX=$(HOSTMOUNT_PREFIX) \ From 2b5488299ef31dc991a83f0e7655619d689b5787 Mon Sep 17 00:00:00 2001 From: Markus Lehtonen Date: Tue, 19 May 2020 10:39:39 +0300 Subject: [PATCH 2/5] Makefile: add install target --- Makefile | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Makefile b/Makefile index 2dc4076fc..db28c2ffa 100644 --- a/Makefile +++ b/Makefile @@ -31,6 +31,9 @@ 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 NFD_VERSION=$(VERSION) \ --build-arg HOSTMOUNT_PREFIX=$(HOSTMOUNT_PREFIX) \ From 342c1dfbc621f308dd0b63f9f26beb2c4d3f6700 Mon Sep 17 00:00:00 2001 From: Markus Lehtonen Date: Tue, 19 May 2020 10:43:14 +0300 Subject: [PATCH 3/5] Dockerfile: use make for building Modify Makefile to have separate hostmount prefix settings for local and container builds in order to preserve the current behavior. --- Dockerfile | 9 +++------ Makefile | 17 +++++++++++++---- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/Dockerfile b/Dockerfile index 4627a61f7..f2e6bdb01 100644 --- a/Dockerfile +++ b/Dockerfile @@ -14,10 +14,7 @@ COPY . /go/node-feature-discovery ARG NFD_VERSION ARG HOSTMOUNT_PREFIX -RUN go install \ - -ldflags "-s -w -X sigs.k8s.io/node-feature-discovery/pkg/version.version=$NFD_VERSION -X sigs.k8s.io/node-feature-discovery/source.pathPrefix=$HOSTMOUNT_PREFIX" \ - ./cmd/* -RUN install -D -m644 nfd-worker.conf.example /etc/kubernetes/node-feature-discovery/nfd-worker.conf +RUN make install VERSION=$NFD_VERSION HOSTMOUNT_PREFIX=$HOSTMOUNT_PREFIX RUN make test @@ -31,5 +28,5 @@ USER 65534:65534 # Use more verbose logging of gRPC ENV GRPC_GO_LOG_SEVERITY_LEVEL="INFO" -COPY --from=builder /etc/kubernetes/node-feature-discovery /etc/kubernetes/node-feature-discovery -COPY --from=builder /go/bin/nfd-* /usr/bin/ +COPY --from=builder /go/node-feature-discovery/nfd-worker.conf.example /etc/kubernetes/node-feature-discovery/nfd-worker.conf +COPY --from=builder /go/bin/* /usr/bin/ diff --git a/Makefile b/Makefile index db28c2ffa..4f8738847 100644 --- a/Makefile +++ b/Makefile @@ -16,11 +16,20 @@ IMAGE_TAG_NAME := $(VERSION) IMAGE_REPO := $(IMAGE_REGISTRY)/$(IMAGE_NAME) IMAGE_TAG := $(IMAGE_REPO):$(IMAGE_TAG_NAME) K8S_NAMESPACE := kube-system -HOSTMOUNT_PREFIX := /host- + +# 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)" +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)) @@ -36,7 +45,7 @@ install: image: yamls $(IMAGE_BUILD_CMD) --build-arg NFD_VERSION=$(VERSION) \ - --build-arg HOSTMOUNT_PREFIX=$(HOSTMOUNT_PREFIX) \ + --build-arg HOSTMOUNT_PREFIX=$(CONTAINER_HOSTMOUNT_PREFIX) \ -t $(IMAGE_TAG) \ $(IMAGE_BUILD_EXTRA_OPTS) ./ @@ -49,7 +58,7 @@ yamls: $(yaml_instances) -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: "${HOSTMOUNT_PREFIX},' \ + -e s',^(\s*)mountPath: "/host-,\1mountPath: "${CONTAINER_HOSTMOUNT_PREFIX},' \ $< > $@ mock: From 1f873f0dfc8286df72237005e982af1eecff07f3 Mon Sep 17 00:00:00 2001 From: Markus Lehtonen Date: Tue, 19 May 2020 12:21:37 +0300 Subject: [PATCH 4/5] Dockerfile: rename version ARG Use the same naming across Makefile and Dockerfile. --- Dockerfile | 4 ++-- Makefile | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Dockerfile b/Dockerfile index f2e6bdb01..f98b8deff 100644 --- a/Dockerfile +++ b/Dockerfile @@ -11,10 +11,10 @@ RUN go mod download # Do actual build COPY . /go/node-feature-discovery -ARG NFD_VERSION +ARG VERSION ARG HOSTMOUNT_PREFIX -RUN make install VERSION=$NFD_VERSION HOSTMOUNT_PREFIX=$HOSTMOUNT_PREFIX +RUN make install VERSION=$VERSION HOSTMOUNT_PREFIX=$HOSTMOUNT_PREFIX RUN make test diff --git a/Makefile b/Makefile index 4f8738847..1de4199d7 100644 --- a/Makefile +++ b/Makefile @@ -44,7 +44,7 @@ install: $(GO_CMD) install -v $(LDFLAGS) ./cmd/... image: yamls - $(IMAGE_BUILD_CMD) --build-arg NFD_VERSION=$(VERSION) \ + $(IMAGE_BUILD_CMD) --build-arg VERSION=$(VERSION) \ --build-arg HOSTMOUNT_PREFIX=$(CONTAINER_HOSTMOUNT_PREFIX) \ -t $(IMAGE_TAG) \ $(IMAGE_BUILD_EXTRA_OPTS) ./ From 906b1a075fe865c0cbfdb1d15ab90114e418a001 Mon Sep 17 00:00:00 2001 From: Markus Lehtonen Date: Mon, 25 May 2020 10:22:33 +0300 Subject: [PATCH 5/5] README: document new hostmount prefix Makefile variables --- README.md | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index df3578c18..d512118e0 100644 --- a/README.md +++ b/README.md @@ -877,19 +877,21 @@ attribute in the spec template(s) to the new location There are several Makefile variables that control the build process and the name of the resulting container image. -| Variable | Description | Default value -| ---------------------- | -------------------------------------------- | ----------- | -| IMAGE_BUILD_CMD | Command to build the image | docker build -| IMAGE_BUILD_EXTRA_OPTS | Extra options to pass to build command | *empty* -| IMAGE_PUSH_CMD | Command to push the image to remote registry | docker push -| IMAGE_REGISTRY | Container image registry to use | k8s.gcr.io/nfd -| IMAGE_NAME | Container image name | node-feature-discovery -| IMAGE_TAG_NAME | Container image tag name | <nfd version> -| IMAGE_REPO | Container image repository to use | <IMAGE_REGISTRY>/<IMAGE_NAME> -| IMAGE_TAG | Full image:tag to tag the image with | <IMAGE_REPO>/<IMAGE_NAME> -| K8S_NAMESPACE | nfd-master and nfd-worker namespace | kube-system -| KUBECONFIG | Kubeconfig for running e2e-tests | *empty* -| E2E_TEST_CONFIG | Parameterization file of e2e-tests (see [example](test/e2e/e2e-test-config.exapmle.yaml)) | *empty* +| Variable | Description | Default value +| -------------------------- | ----------------------------------------------------------------- | ----------- | +| HOSTMOUNT_PREFIX | Prefix of system directories for feature discovery (local builds) | / +| CONTAINER_HOSTMOUNT_PREFIX | Prefix of system directories for feature discovery (container builds) | <HOSTMOUNT_PREFIX> (*if specified*) /host- (*otherwise*) +| IMAGE_BUILD_CMD | Command to build the image | docker build +| IMAGE_BUILD_EXTRA_OPTS | Extra options to pass to build command | *empty* +| IMAGE_PUSH_CMD | Command to push the image to remote registry | docker push +| IMAGE_REGISTRY | Container image registry to use | k8s.gcr.io/nfd +| IMAGE_NAME | Container image name | node-feature-discovery +| IMAGE_TAG_NAME | Container image tag name | <nfd version> +| IMAGE_REPO | Container image repository to use | <IMAGE_REGISTRY>/<IMAGE_NAME> +| IMAGE_TAG | Full image:tag to tag the image with | <IMAGE_REPO>/<IMAGE_NAME> +| K8S_NAMESPACE | nfd-master and nfd-worker namespace | kube-system +| KUBECONFIG | Kubeconfig for running e2e-tests | *empty* +| E2E_TEST_CONFIG | Parameterization file of e2e-tests (see [example](test/e2e/e2e-test-config.exapmle.yaml)) | *empty* For example, to use a custom registry: ```