@@ -48,12 +48,11 @@ endif
48
48
49
49
# Set the Operator SDK version to use. By default, what is installed on the system is used.
50
50
# This is useful for CI or a project to utilize a specific version of the operator-sdk toolkit.
51
- OPERATOR_SDK_VERSION ?= v1.33.0
52
-
51
+ OPERATOR_SDK_VERSION ?= v1.39.1
53
52
# Image URL to use all building/pushing image targets
54
53
IMG ?= controller:latest
55
54
# ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary.
56
- ENVTEST_K8S_VERSION = 1.27.1
55
+ ENVTEST_K8S_VERSION = 1.31.0
57
56
58
57
# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
59
58
ifeq (,$(shell go env GOBIN) )
@@ -80,7 +79,7 @@ all: build
80
79
81
80
# The help target prints out all targets with their descriptions organized
82
81
# beneath their categories. The categories are represented by '##@' and the
83
- # target descriptions by '##'. The awk commands is responsible for reading the
82
+ # target descriptions by '##'. The awk command is responsible for reading the
84
83
# entire set of makefiles included in this invocation, looking for lines of the
85
84
# file as xyz: ## something, and then pretty-format the target and help. Then,
86
85
# if there's a line with ##@ something, that gets pretty-printed as a category.
@@ -113,7 +112,20 @@ vet: ## Run go vet against code.
113
112
114
113
.PHONY : test
115
114
test : manifests generate fmt vet envtest # # Run tests.
116
- KUBEBUILDER_ASSETS=" $( shell $( ENVTEST) use $( ENVTEST_K8S_VERSION) --bin-dir $( LOCALBIN) -p path) " go test ./... -coverprofile cover.out
115
+ KUBEBUILDER_ASSETS=" $( shell $( ENVTEST) use $( ENVTEST_K8S_VERSION) --bin-dir $( LOCALBIN) -p path) " go test $$(go list ./... | grep -v /e2e ) -coverprofile cover.out
116
+
117
+ # Utilize Kind or modify the e2e tests to load the image locally, enabling compatibility with other vendors.
118
+ .PHONY : test-e2e # Run the e2e tests against a Kind k8s instance that is spun up.
119
+ test-e2e :
120
+ go test ./test/e2e/ -v -ginkgo.v
121
+
122
+ .PHONY : lint
123
+ lint : golangci-lint # # Run golangci-lint linter
124
+ $(GOLANGCI_LINT ) run
125
+
126
+ .PHONY : lint-fix
127
+ lint-fix : golangci-lint # # Run golangci-lint linter and perform fixes
128
+ $(GOLANGCI_LINT ) run --fix
117
129
118
130
# #@ Build
119
131
@@ -125,34 +137,40 @@ build: manifests generate fmt vet ## Build manager binary.
125
137
run : manifests generate fmt vet # # Run a controller from your host.
126
138
go run ./cmd/main.go
127
139
128
- # If you wish built the manager image targeting other platforms you can use the --platform flag.
129
- # (i.e. docker build --platform linux/arm64 ). However, you must enable docker buildKit for it.
140
+ # If you wish to build the manager image targeting other platforms you can use the --platform flag.
141
+ # (i.e. docker build --platform linux/arm64). However, you must enable docker buildKit for it.
130
142
# More info: https://docs.docker.com/develop/develop-images/build_enhancements/
131
143
.PHONY : docker-build
132
- docker-build : test # # Build docker image with the manager.
144
+ docker-build : # # Build docker image with the manager.
133
145
$(CONTAINER_TOOL ) build -t ${IMG} .
134
146
135
147
.PHONY : docker-push
136
148
docker-push : # # Push docker image with the manager.
137
149
$(CONTAINER_TOOL ) push ${IMG}
138
150
139
- # PLATFORMS defines the target platforms for the manager image be build to provide support to multiple
151
+ # PLATFORMS defines the target platforms for the manager image be built to provide support to multiple
140
152
# architectures. (i.e. make docker-buildx IMG=myregistry/mypoperator:0.0.1). To use this option you need to:
141
- # - able to use docker buildx . More info: https://docs.docker.com/build/buildx/
142
- # - have enable BuildKit, More info: https://docs.docker.com/develop/develop-images/build_enhancements/
143
- # - 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)
144
- # To properly provided solutions that supports more than one platform you should use this option.
153
+ # - be able to use docker buildx. More info: https://docs.docker.com/build/buildx/
154
+ # - have enabled BuildKit. More info: https://docs.docker.com/develop/develop-images/build_enhancements/
155
+ # - 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)
156
+ # To adequately provide solutions that are compatible with multiple platforms, you should consider using this option.
145
157
PLATFORMS ?= linux/arm64,linux/amd64,linux/s390x,linux/ppc64le
146
158
.PHONY : docker-buildx
147
- docker-buildx : test # # Build and push docker image for the manager for cross-platform support
159
+ docker-buildx : # # Build and push docker image for the manager for cross-platform support
148
160
# copy existing Dockerfile and insert --platform=${BUILDPLATFORM} into Dockerfile.cross, and preserve the original Dockerfile
149
161
sed -e ' 1 s/\(^FROM\)/FROM --platform=\$$\{BUILDPLATFORM\}/; t' -e ' 1,// s//FROM --platform=\$$\{BUILDPLATFORM\}/' Dockerfile > Dockerfile.cross
150
- - $(CONTAINER_TOOL ) buildx create --name project-v3 -builder
151
- $(CONTAINER_TOOL ) buildx use project-v3 -builder
162
+ - $(CONTAINER_TOOL ) buildx create --name lms-moodle-operator -builder
163
+ $(CONTAINER_TOOL ) buildx use lms-moodle-operator -builder
152
164
- $(CONTAINER_TOOL ) buildx build --push --platform=$(PLATFORMS ) --tag ${IMG} -f Dockerfile.cross .
153
- - $(CONTAINER_TOOL ) buildx rm project-v3 -builder
165
+ - $(CONTAINER_TOOL ) buildx rm lms-moodle-operator -builder
154
166
rm Dockerfile.cross
155
167
168
+ .PHONY : build-installer
169
+ build-installer : manifests generate kustomize # # Generate a consolidated YAML with CRDs and deployment.
170
+ mkdir -p dist
171
+ cd config/manager && $(KUSTOMIZE ) edit set image controller=${IMG}
172
+ $(KUSTOMIZE ) build config/default > dist/install.yaml
173
+
156
174
# #@ Deployment
157
175
158
176
ifndef ignore-not-found
@@ -173,10 +191,10 @@ deploy: manifests kustomize ## Deploy controller to the K8s cluster specified in
173
191
$(KUSTOMIZE ) build config/default | $(KUBECTL ) apply -f -
174
192
175
193
.PHONY : undeploy
176
- 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.
194
+ 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.
177
195
$(KUSTOMIZE ) build config/default | $(KUBECTL ) delete --ignore-not-found=$(ignore-not-found ) -f -
178
196
179
- # #@ Build Dependencies
197
+ # #@ Dependencies
180
198
181
199
# # Location to install dependencies to
182
200
LOCALBIN ?= $(shell pwd) /bin
@@ -188,30 +206,49 @@ KUBECTL ?= kubectl
188
206
KUSTOMIZE ?= $(LOCALBIN ) /kustomize
189
207
CONTROLLER_GEN ?= $(LOCALBIN ) /controller-gen
190
208
ENVTEST ?= $(LOCALBIN ) /setup-envtest
209
+ GOLANGCI_LINT = $(LOCALBIN ) /golangci-lint
191
210
192
211
# # Tool Versions
193
- KUSTOMIZE_VERSION ?= v5.0.1
194
- CONTROLLER_TOOLS_VERSION := v0.14.0
212
+ KUSTOMIZE_VERSION ?= v5.4.3
213
+ CONTROLLER_TOOLS_VERSION ?= v0.16.1
214
+ ENVTEST_VERSION ?= release-0.19
215
+ GOLANGCI_LINT_VERSION ?= v1.59.1
195
216
196
217
.PHONY : kustomize
197
- kustomize : $(KUSTOMIZE ) # # Download kustomize locally if necessary. If wrong version is installed, it will be removed before downloading.
218
+ kustomize : $(KUSTOMIZE ) # # Download kustomize locally if necessary.
198
219
$(KUSTOMIZE ) : $(LOCALBIN )
199
- @if test -x $(LOCALBIN ) /kustomize && ! $(LOCALBIN ) /kustomize version | grep -q $(KUSTOMIZE_VERSION ) ; then \
200
- echo " $( LOCALBIN) /kustomize version is not expected $( KUSTOMIZE_VERSION) . Removing it before installing." ; \
201
- rm -rf $(LOCALBIN ) /kustomize; \
202
- fi
203
- test -s $(LOCALBIN ) /kustomize || GOBIN=$(LOCALBIN ) GO111MODULE=on go install sigs.k8s.io/kustomize/kustomize/v5@$(KUSTOMIZE_VERSION )
220
+ $(call go-install-tool,$(KUSTOMIZE ) ,sigs.k8s.io/kustomize/kustomize/v5,$(KUSTOMIZE_VERSION ) )
204
221
205
222
.PHONY : controller-gen
206
- controller-gen : $(CONTROLLER_GEN ) # # Download controller-gen locally if necessary. If wrong version is installed, it will be overwritten.
223
+ controller-gen : $(CONTROLLER_GEN ) # # Download controller-gen locally if necessary.
207
224
$(CONTROLLER_GEN ) : $(LOCALBIN )
208
- test -s $(LOCALBIN ) /controller-gen && $(LOCALBIN ) /controller-gen --version | grep -q $(CONTROLLER_TOOLS_VERSION ) || \
209
- GOBIN=$(LOCALBIN ) go install sigs.k8s.io/controller-tools/cmd/controller-gen@$(CONTROLLER_TOOLS_VERSION )
225
+ $(call go-install-tool,$(CONTROLLER_GEN ) ,sigs.k8s.io/controller-tools/cmd/controller-gen,$(CONTROLLER_TOOLS_VERSION ) )
210
226
211
227
.PHONY : envtest
212
- envtest : $(ENVTEST ) # # Download envtest- setup locally if necessary.
228
+ envtest : $(ENVTEST ) # # Download setup-envtest locally if necessary.
213
229
$(ENVTEST ) : $(LOCALBIN )
214
- test -s $(LOCALBIN ) /setup-envtest || GOBIN=$(LOCALBIN ) go install sigs.k8s.io/controller-runtime/tools/setup-envtest@latest
230
+ $(call go-install-tool,$(ENVTEST ) ,sigs.k8s.io/controller-runtime/tools/setup-envtest,$(ENVTEST_VERSION ) )
231
+
232
+ .PHONY : golangci-lint
233
+ golangci-lint : $(GOLANGCI_LINT ) # # Download golangci-lint locally if necessary.
234
+ $(GOLANGCI_LINT ) : $(LOCALBIN )
235
+ $(call go-install-tool,$(GOLANGCI_LINT ) ,github.com/golangci/golangci-lint/cmd/golangci-lint,$(GOLANGCI_LINT_VERSION ) )
236
+
237
+ # go-install-tool will 'go install' any package with custom target and name of binary, if it doesn't exist
238
+ # $1 - target path with name of binary
239
+ # $2 - package url which can be installed
240
+ # $3 - specific version of package
241
+ define go-install-tool
242
+ @[ -f "$(1 ) -$(3 ) " ] || { \
243
+ set -e; \
244
+ package=$(2 ) @$(3 ) ;\
245
+ echo "Downloading $${package}" ;\
246
+ rm -f $(1 ) || true ;\
247
+ GOBIN=$(LOCALBIN ) go install $${package} ;\
248
+ mv $(1 ) $(1 ) -$(3 ) ;\
249
+ } ;\
250
+ ln -sf $(1 ) -$(3 ) $(1 )
251
+ endef
215
252
216
253
.PHONY : operator-sdk
217
254
OPERATOR_SDK ?= $(LOCALBIN ) /operator-sdk
@@ -246,7 +283,7 @@ bundle-push: ## Push the bundle image.
246
283
$(MAKE ) docker-push IMG=$(BUNDLE_IMG )
247
284
248
285
.PHONY : opm
249
- OPM = ./bin /opm
286
+ OPM = $( LOCALBIN ) /opm
250
287
opm : # # Download opm locally if necessary.
251
288
ifeq (,$(wildcard $(OPM ) ) )
252
289
ifeq (,$(shell which opm 2>/dev/null) )
0 commit comments