@@ -20,8 +20,40 @@ SITE_BASEURL ?=
20
20
SITE_DESTDIR ?= _site
21
21
JEKYLL_OPTS := -d '$(SITE_DESTDIR ) ' $(if $(SITE_BASEURL ) ,-b '$(SITE_BASEURL ) ',)
22
22
23
+ # VERSION defines the project version for the bundle.
24
+ # Update this value when you upgrade the version of your project.
25
+ # To re-generate a bundle for another specific version without changing the standard setup, you can:
26
+ # - use the VERSION as arg of the bundle target (e.g make bundle VERSION=0.2.1)
27
+ # - use environment variables to overwrite this value (e.g export VERSION=0.2.1)
23
28
VERSION := $(shell git describe --tags --dirty --always)
24
29
30
+ # CHANNELS define the bundle channels used in the bundle.
31
+ # Add a new line here if you would like to change its default config. (E.g CHANNELS = "preview,fast,stable")
32
+ # To re-generate a bundle for other specific channels without changing the standard setup, you can:
33
+ # - use the CHANNELS as arg of the bundle target (e.g make bundle CHANNELS=preview,fast,stable)
34
+ # - use environment variables to overwrite this value (e.g export CHANNELS="preview,fast,stable")
35
+ ifneq ($(origin CHANNELS ) , undefined)
36
+ BUNDLE_CHANNELS := --channels=$(CHANNELS )
37
+ endif
38
+
39
+ # DEFAULT_CHANNEL defines the default channel used in the bundle.
40
+ # Add a new line here if you would like to change its default config. (E.g DEFAULT_CHANNEL = "stable")
41
+ # To re-generate a bundle for any other default channel without changing the default setup, you can:
42
+ # - use the DEFAULT_CHANNEL as arg of the bundle target (e.g make bundle DEFAULT_CHANNEL=stable)
43
+ # - use environment variables to overwrite this value (e.g export DEFAULT_CHANNEL="stable")
44
+ ifneq ($(origin DEFAULT_CHANNEL ) , undefined)
45
+ BUNDLE_DEFAULT_CHANNEL := --default-channel=$(DEFAULT_CHANNEL )
46
+ endif
47
+ BUNDLE_METADATA_OPTS ?= $(BUNDLE_CHANNELS ) $(BUNDLE_DEFAULT_CHANNEL )
48
+
49
+ # BUNDLE_IMG defines the image:tag used for the bundle.
50
+ # You can use it as an arg. (E.g make bundle-build BUNDLE_IMG=<some-registry>/<project-name-bundle>:<tag>)
51
+ BUNDLE_IMG ?= controller-bundle:$(VERSION )
52
+
53
+ # Image URL to use all building/pushing image targets
54
+ IMAGE_BUILD_CMD ?= docker build
55
+ IMAGE_PUSH_CMD ?= docker push
56
+ IMAGE_BUILD_EXTRA_OPTS ?=
25
57
IMAGE_REGISTRY ?= k8s.gcr.io/nfd
26
58
IMAGE_NAME := node-feature-discovery-operator
27
59
IMAGE_TAG_NAME ?= $(VERSION )
@@ -30,54 +62,69 @@ IMAGE_REPO := $(IMAGE_REGISTRY)/$(IMAGE_NAME)
30
62
IMAGE_TAG := $(IMAGE_REPO ) :$(IMAGE_TAG_NAME )
31
63
IMAGE_EXTRA_TAGS := $(foreach tag,$(IMAGE_EXTRA_TAG_NAMES ) ,$(IMAGE_REPO ) :$(tag ) )
32
64
33
- NAMESPACE := node-feature-discovery-operator
34
- PULLPOLICY ?= Always
35
- TEMPLATE_CMD = sed 's+REPLACE_IMAGE+$(IMAGE_TAG ) +g; s+REPLACE_NAMESPACE+$(NAMESPACE ) +g; s+IfNotPresent+$(PULLPOLICY ) +'
36
- GOFMT_CHECK =$(shell find . -not \( \( -wholename './.* ' -o -wholename '* /vendor/* ' \) -prune \) -name '*.go' | sort -u | xargs gofmt -s -l)
65
+ # Produce CRDs that work back to Kubernetes 1.11 (no version conversion)
66
+ CRD_OPTIONS ?= "crd:trivialVersions=true,preserveUnknownFields=false"
37
67
38
- DEPLOY_OBJECTS = manifests/0100_namespace.yaml manifests/0200_service_account.yaml manifests/0300_cluster_role.yaml manifests/0400_cluster_role_binding.yaml manifests/0600_operator.yaml
39
- DEPLOY_CRDS = manifests/0500_crd.yaml
40
- DEPLOY_CRS = manifests/0700_cr.yaml
68
+ # Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
69
+ ifeq (,$(shell go env GOBIN) )
70
+ GOBIN =$(shell go env GOPATH) /bin
71
+ else
72
+ GOBIN =$(shell go env GOBIN)
73
+ endif
41
74
42
- PACKAGE =github.com/kubernetes-sigs/node-feature-discovery-operator
43
- MAIN_PACKAGE =$(PACKAGE ) /cmd/manager
75
+ GOOS =linux
44
76
77
+ PACKAGE =github.com/kubernetes-sigs/node-feature-discovery-operator
78
+ MAIN_PACKAGE =main.go
45
79
BIN =node-feature-discovery-operator
46
80
47
- DOCKERFILE =Dockerfile
48
-
49
- GOOS =linux
50
-
51
81
all : build
52
82
83
+ # Run tests
84
+ ENVTEST_ASSETS_DIR =$(shell pwd) /testbin
85
+ test : generate fmt vet manifests
86
+ mkdir -p ${ENVTEST_ASSETS_DIR}
87
+ 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.0/hack/setup-envtest.sh
88
+ source ${ENVTEST_ASSETS_DIR} /setup-envtest.sh; fetch_envtest_tools $(ENVTEST_ASSETS_DIR ) ; setup_envtest_env $(ENVTEST_ASSETS_DIR ) ; go test ./... -coverprofile cover.out
53
89
go_mod :
54
90
@go mod download
55
91
92
+ # Build binary
56
93
build : go_mod
57
- @GOOS=$(GOOS ) go build -o $(BIN ) $(MAIN_PACKAGE )
58
-
59
- deploy-crds :
60
- for obj in $( DEPLOY_CRDS) ; do \
61
- $(TEMPLATE_CMD ) $$ obj | kubectl apply -f - ; \
62
- sleep 1; \
63
- done
64
-
65
- deploy-objects : deploy-crds
66
- for obj in $( DEPLOY_OBJECTS) ; do \
67
- $(TEMPLATE_CMD ) $$ obj | kubectl apply -f - ; \
68
- sleep 1; \
69
- done
70
-
71
- deploy : deploy-objects
72
- for obj in $( DEPLOY_CRS) ; do \
73
- $(TEMPLATE_CMD ) $$ obj | kubectl apply -f - ; \
74
- sleep 1; \
75
- done
94
+ @GOOS=$(GOOS ) GO111MODULE=on CGO_ENABLED=0 go build -o $(BIN ) $(MAIN_PACKAGE )
76
95
96
+ # Run against the configured Kubernetes cluster in ~/.kube/config
97
+ run : generate fmt vet manifests
98
+ go run ./main.go
99
+
100
+ # Install CRDs into a cluster
101
+ install : manifests kustomize
102
+ $(KUSTOMIZE ) build config/crd | kubectl apply -f -
103
+
104
+ # Uninstall CRDs from a cluster
105
+ uninstall : manifests kustomize
106
+ $(KUSTOMIZE ) build config/crd | kubectl delete -f -
107
+
108
+ # Deploy controller in the configured Kubernetes cluster in ~/.kube/config
109
+ deploy : kustomize
110
+ cd config/manager && $(KUSTOMIZE ) edit set image controller=${IMAGE_TAG}
111
+ $(KUSTOMIZE ) build config/default | kubectl apply -f -
112
+
113
+ # UnDeploy controller from the configured Kubernetes cluster in ~/.kube/config
77
114
undeploy :
78
- for obj in $( DEPLOY_OBJECTS) $( DEPLOY_CRDS) $( DEPLOY_CRS) ; do \
79
- $(TEMPLATE_CMD ) $$ obj | kubectl delete -f - ; \
80
- done
115
+ $(KUSTOMIZE ) build config/default | kubectl delete -f -
116
+
117
+ # Generate manifests e.g. CRD, RBAC etc.
118
+ manifests : controller-gen
119
+ $(CONTROLLER_GEN ) $(CRD_OPTIONS ) rbac:roleName=manager-role webhook paths=" ./..." output:crd:artifacts:config=config/crd/bases
120
+
121
+ # Run go fmt against code
122
+ fmt :
123
+ go fmt ./...
124
+
125
+ # Run go vet against code
126
+ vet :
127
+ go vet ./...
81
128
82
129
verify : verify-gofmt ci-lint
83
130
@@ -94,17 +141,22 @@ clean:
94
141
go clean
95
142
rm -f $(BIN )
96
143
144
+ # clean NFD labels on all nodes
145
+ # devel only
97
146
clean-labels :
98
147
kubectl get no -o yaml | sed -e ' /^\s*nfd.node.kubernetes.io/d' -e ' /^\s*feature.node.kubernetes.io/d' | kubectl replace -f -
99
148
100
- image :
149
+ # Generate code
150
+ generate : controller-gen
151
+ $(CONTROLLER_GEN ) object:headerFile=" utils/boilerplate.go.txt" paths=" ./..."
152
+
153
+ # Build the docker image
154
+ image :
101
155
$(IMAGE_BUILD_CMD ) -t $(IMAGE_TAG ) \
102
156
$(foreach tag,$(IMAGE_EXTRA_TAGS ) ,-t $(tag ) ) \
103
157
$(IMAGE_BUILD_EXTRA_OPTS ) ./
104
158
105
- test :
106
- go test ./cmd/... ./pkg/... -coverprofile cover.out
107
-
159
+ # Push the docker image
108
160
push :
109
161
$(IMAGE_PUSH_CMD ) $(IMAGE_TAG )
110
162
for tag in $( IMAGE_EXTRA_TAGS) ; do $( IMAGE_PUSH_CMD) $$ tag; done
@@ -119,3 +171,39 @@ site-serve:
119
171
120
172
.PHONY : all build test generate verify verify-gofmt clean deploy-objects deploy-operator deploy-crds push image
121
173
.SILENT : go_mod
174
+ # Download controller-gen locally if necessary
175
+ CONTROLLER_GEN = $(shell pwd) /bin/controller-gen
176
+ controller-gen :
177
+ $(call go-get-tool,$(CONTROLLER_GEN ) ,sigs.k8s.io/controller-tools/cmd/[email protected] )
178
+
179
+ # Download kustomize locally if necessary
180
+ KUSTOMIZE = $(shell pwd) /bin/kustomize
181
+ kustomize :
182
+ $(call go-get-tool,$(KUSTOMIZE ) ,sigs.k8s.io/kustomize/kustomize/[email protected] )
183
+
184
+ # go-get-tool will 'go get' any package $2 and install it to $1.
185
+ PROJECT_DIR := $(shell dirname $(abspath $(lastword $(MAKEFILE_LIST ) ) ) )
186
+ define go-get-tool
187
+ @[ -f $(1 ) ] || { \
188
+ set -e ;\
189
+ TMP_DIR=$$(mktemp -d ) ;\
190
+ cd $$TMP_DIR ;\
191
+ go mod init tmp ;\
192
+ echo "Downloading $(2 ) " ;\
193
+ GOBIN=$(PROJECT_DIR ) /bin go get $(2 ) ;\
194
+ rm -rf $$TMP_DIR ;\
195
+ }
196
+ endef
197
+
198
+ # Generate bundle manifests and metadata, then validate generated files.
199
+ .PHONY : bundle
200
+ bundle : manifests kustomize
201
+ operator-sdk generate kustomize manifests -q
202
+ cd config/manager && $(KUSTOMIZE ) edit set image controller=$(IMAGE_TAG )
203
+ $(KUSTOMIZE ) build config/manifests | operator-sdk generate bundle -q --overwrite --version $(VERSION ) $(BUNDLE_METADATA_OPTS )
204
+ operator-sdk bundle validate ./bundle
205
+
206
+ # Build the bundle image.
207
+ .PHONY : bundle-build
208
+ bundle-build :
209
+ $(IMAGE_BUILD_CMD ) -f bundle.Dockerfile -t $(BUNDLE_IMG ) .
0 commit comments