1
-
2
1
# Image URL to use all building/pushing image targets
3
2
IMG ?= controller:latest
4
3
# ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary.
5
- ENVTEST_K8S_VERSION = 1.27.1
4
+ ENVTEST_K8S_VERSION = 1.29.0
6
5
7
6
# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
8
7
ifeq (,$(shell go env GOBIN) )
@@ -29,7 +28,7 @@ all: build
29
28
30
29
# The help target prints out all targets with their descriptions organized
31
30
# beneath their categories. The categories are represented by '##@' and the
32
- # target descriptions by '##'. The awk commands is responsible for reading the
31
+ # target descriptions by '##'. The awk command is responsible for reading the
33
32
# entire set of makefiles included in this invocation, looking for lines of the
34
33
# file as xyz: ## something, and then pretty-format the target and help. Then,
35
34
# if there's a line with ##@ something, that gets pretty-printed as a category.
@@ -62,7 +61,20 @@ vet: ## Run go vet against code.
62
61
63
62
.PHONY : test
64
63
test : manifests generate fmt vet envtest # # Run tests.
65
- KUBEBUILDER_ASSETS=" $( shell $( ENVTEST) use $( ENVTEST_K8S_VERSION) --bin-dir $( LOCALBIN) -p path) " go test ./... -coverprofile cover.out
64
+ KUBEBUILDER_ASSETS=" $( shell $( ENVTEST) use $( ENVTEST_K8S_VERSION) --bin-dir $( LOCALBIN) -p path) " go test $$(go list ./... | grep -v /e2e ) -coverprofile cover.out
65
+
66
+ # Utilize Kind or modify the e2e tests to load the image locally, enabling compatibility with other vendors.
67
+ .PHONY : test-e2e # Run the e2e tests against a Kind k8s instance that is spun up.
68
+ test-e2e :
69
+ go test ./test/e2e/ -v -ginkgo.v
70
+
71
+ .PHONY : lint
72
+ lint : golangci-lint # # Run golangci-lint linter & yamllint
73
+ $(GOLANGCI_LINT ) run
74
+
75
+ .PHONY : lint-fix
76
+ lint-fix : golangci-lint # # Run golangci-lint linter and perform fixes
77
+ $(GOLANGCI_LINT ) run --fix
66
78
67
79
# #@ Build
68
80
@@ -74,26 +86,26 @@ build: manifests generate fmt vet ## Build manager binary.
74
86
run : manifests generate fmt vet # # Run a controller from your host.
75
87
go run ./cmd/main.go
76
88
77
- # If you wish built the manager image targeting other platforms you can use the --platform flag.
78
- # (i.e. docker build --platform linux/arm64 ). However, you must enable docker buildKit for it.
89
+ # If you wish to build the manager image targeting other platforms you can use the --platform flag.
90
+ # (i.e. docker build --platform linux/arm64). However, you must enable docker buildKit for it.
79
91
# More info: https://docs.docker.com/develop/develop-images/build_enhancements/
80
92
.PHONY : docker-build
81
- docker-build : test # # Build docker image with the manager.
93
+ docker-build : # # Build docker image with the manager.
82
94
$(CONTAINER_TOOL ) build -t ${IMG} .
83
95
84
96
.PHONY : docker-push
85
97
docker-push : # # Push docker image with the manager.
86
98
$(CONTAINER_TOOL ) push ${IMG}
87
99
88
- # PLATFORMS defines the target platforms for the manager image be build to provide support to multiple
100
+ # PLATFORMS defines the target platforms for the manager image be built to provide support to multiple
89
101
# architectures. (i.e. make docker-buildx IMG=myregistry/mypoperator:0.0.1). To use this option you need to:
90
- # - able to use docker buildx . More info: https://docs.docker.com/build/buildx/
91
- # - have enable BuildKit, More info: https://docs.docker.com/develop/develop-images/build_enhancements/
92
- # - be able to push the image for your registry (i.e. if you do not inform a valid value via IMG=<myregistry/image:<tag>> then the export will fail)
93
- # To properly provided solutions that supports more than one platform you should use this option.
102
+ # - be able to use docker buildx. More info: https://docs.docker.com/build/buildx/
103
+ # - have enabled BuildKit. More info: https://docs.docker.com/develop/develop-images/build_enhancements/
104
+ # - be able to push the image to your registry (i.e. if you do not set a valid value via IMG=<myregistry/image:<tag>> then the export will fail)
105
+ # To adequately provide solutions that are compatible with multiple platforms, you should consider using this option.
94
106
PLATFORMS ?= linux/arm64,linux/amd64,linux/s390x,linux/ppc64le
95
107
.PHONY : docker-buildx
96
- docker-buildx : test # # Build and push docker image for the manager for cross-platform support
108
+ docker-buildx : # # Build and push docker image for the manager for cross-platform support
97
109
# copy existing Dockerfile and insert --platform=${BUILDPLATFORM} into Dockerfile.cross, and preserve the original Dockerfile
98
110
sed -e ' 1 s/\(^FROM\)/FROM --platform=\$$\{BUILDPLATFORM\}/; t' -e ' 1,// s//FROM --platform=\$$\{BUILDPLATFORM\}/' Dockerfile > Dockerfile.cross
99
111
- $(CONTAINER_TOOL ) buildx create --name project-v3-builder
@@ -102,6 +114,12 @@ docker-buildx: test ## Build and push docker image for the manager for cross-pla
102
114
- $(CONTAINER_TOOL ) buildx rm project-v3-builder
103
115
rm Dockerfile.cross
104
116
117
+ .PHONY : build-installer
118
+ build-installer : manifests generate kustomize # # Generate a consolidated YAML with CRDs and deployment.
119
+ mkdir -p dist
120
+ cd config/manager && $(KUSTOMIZE ) edit set image controller=${IMG}
121
+ $(KUSTOMIZE ) build config/default > dist/install.yaml
122
+
105
123
# #@ Deployment
106
124
107
125
ifndef ignore-not-found
@@ -122,10 +140,10 @@ deploy: manifests kustomize ## Deploy controller to the K8s cluster specified in
122
140
$(KUSTOMIZE ) build config/default | $(KUBECTL ) apply -f -
123
141
124
142
.PHONY : undeploy
125
- undeploy : # # Undeploy controller from the K8s cluster specified in ~/.kube/config. Call with ignore-not-found=true to ignore resource not found errors during deletion.
143
+ undeploy : kustomize # # Undeploy controller from the K8s cluster specified in ~/.kube/config. Call with ignore-not-found=true to ignore resource not found errors during deletion.
126
144
$(KUSTOMIZE ) build config/default | $(KUBECTL ) delete --ignore-not-found=$(ignore-not-found ) -f -
127
145
128
- # #@ Build Dependencies
146
+ # #@ Dependencies
129
147
130
148
# # Location to install dependencies to
131
149
LOCALBIN ?= $(shell pwd) /bin
@@ -134,30 +152,47 @@ $(LOCALBIN):
134
152
135
153
# # Tool Binaries
136
154
KUBECTL ?= kubectl
137
- KUSTOMIZE ?= $(LOCALBIN ) /kustomize
138
- CONTROLLER_GEN ?= $(LOCALBIN ) /controller-gen
139
- ENVTEST ?= $(LOCALBIN ) /setup-envtest
155
+ KUSTOMIZE ?= $(LOCALBIN ) /kustomize-$(KUSTOMIZE_VERSION )
156
+ CONTROLLER_GEN ?= $(LOCALBIN ) /controller-gen-$(CONTROLLER_TOOLS_VERSION )
157
+ ENVTEST ?= $(LOCALBIN ) /setup-envtest-$(ENVTEST_VERSION )
158
+ GOLANGCI_LINT = $(LOCALBIN ) /golangci-lint-$(GOLANGCI_LINT_VERSION )
140
159
141
160
# # Tool Versions
142
- KUSTOMIZE_VERSION ?= v5.0.1
143
- CONTROLLER_TOOLS_VERSION ?= v0.12.0
161
+ KUSTOMIZE_VERSION ?= v5.3.0
162
+ CONTROLLER_TOOLS_VERSION ?= v0.14.0
163
+ ENVTEST_VERSION ?= release-0.17
164
+ GOLANGCI_LINT_VERSION ?= v1.54.2
144
165
145
166
.PHONY : kustomize
146
- kustomize : $(KUSTOMIZE ) # # Download kustomize locally if necessary. If wrong version is installed, it will be removed before downloading.
167
+ kustomize : $(KUSTOMIZE ) # # Download kustomize locally if necessary.
147
168
$(KUSTOMIZE ) : $(LOCALBIN )
148
- @if test -x $(LOCALBIN ) /kustomize && ! $(LOCALBIN ) /kustomize version | grep -q $(KUSTOMIZE_VERSION ) ; then \
149
- echo " $( LOCALBIN) /kustomize version is not expected $( KUSTOMIZE_VERSION) . Removing it before installing." ; \
150
- rm -rf $(LOCALBIN ) /kustomize; \
151
- fi
152
- test -s $(LOCALBIN ) /kustomize || GOBIN=$(LOCALBIN ) GO111MODULE=on go install sigs.k8s.io/kustomize/kustomize/v5@$(KUSTOMIZE_VERSION )
169
+ $(call go-install-tool,$(KUSTOMIZE ) ,sigs.k8s.io/kustomize/kustomize/v5,$(KUSTOMIZE_VERSION ) )
153
170
154
171
.PHONY : controller-gen
155
- controller-gen : $(CONTROLLER_GEN ) # # Download controller-gen locally if necessary. If wrong version is installed, it will be overwritten.
172
+ controller-gen : $(CONTROLLER_GEN ) # # Download controller-gen locally if necessary.
156
173
$(CONTROLLER_GEN ) : $(LOCALBIN )
157
- test -s $(LOCALBIN ) /controller-gen && $(LOCALBIN ) /controller-gen --version | grep -q $(CONTROLLER_TOOLS_VERSION ) || \
158
- GOBIN=$(LOCALBIN ) go install sigs.k8s.io/controller-tools/cmd/controller-gen@$(CONTROLLER_TOOLS_VERSION )
174
+ $(call go-install-tool,$(CONTROLLER_GEN ) ,sigs.k8s.io/controller-tools/cmd/controller-gen,$(CONTROLLER_TOOLS_VERSION ) )
159
175
160
176
.PHONY : envtest
161
- envtest : $(ENVTEST ) # # Download envtest- setup locally if necessary.
177
+ envtest : $(ENVTEST ) # # Download setup-envtest locally if necessary.
162
178
$(ENVTEST ) : $(LOCALBIN )
163
- test -s $(LOCALBIN ) /setup-envtest || GOBIN=$(LOCALBIN ) go install sigs.k8s.io/controller-runtime/tools/setup-envtest@latest
179
+ $(call go-install-tool,$(ENVTEST ) ,sigs.k8s.io/controller-runtime/tools/setup-envtest,$(ENVTEST_VERSION ) )
180
+
181
+ .PHONY : golangci-lint
182
+ golangci-lint : $(GOLANGCI_LINT ) # # Download golangci-lint locally if necessary.
183
+ $(GOLANGCI_LINT ) : $(LOCALBIN )
184
+ $(call go-install-tool,$(GOLANGCI_LINT ) ,github.com/golangci/golangci-lint/cmd/golangci-lint,${GOLANGCI_LINT_VERSION})
185
+
186
+ # go-install-tool will 'go install' any package with custom target and name of binary, if it doesn't exist
187
+ # $1 - target path with name of binary (ideally with version)
188
+ # $2 - package url which can be installed
189
+ # $3 - specific version of package
190
+ define go-install-tool
191
+ @[ -f $(1 ) ] || { \
192
+ set -e; \
193
+ package=$(2 ) @$(3 ) ;\
194
+ echo "Downloading $${package}" ;\
195
+ GOBIN=$(LOCALBIN ) go install $${package} ;\
196
+ mv "$$(echo "$(1 ) " | sed "s/-$(3 ) $$//" ) " $(1 ) ;\
197
+ }
198
+ endef
0 commit comments