@@ -15,15 +15,13 @@ KUBECTL_VERSION=$(shell go list -m all | grep k8s.io/client-go| cut -d' ' -f2)
15
15
LOCALBIN ?= ${CURRENT_DIR}/bin
16
16
$(LOCALBIN ) :
17
17
mkdir -p $(LOCALBIN )
18
- ENVTEST ?= $(LOCALBIN ) /setup-envtest
19
- ENVTEST_K8S_VERSION = 1.23.5
20
18
21
19
# Use kind cluster for testing
22
20
CONTAINER_REGISTRY_URL? ="repo"
23
21
CONTAINER_REGISTRY_SPACE? ="edp"
24
22
START_KIND_CLUSTER? =true
25
23
KIND_CLUSTER_NAME? ="keycloak-operator"
26
- KUBE_VERSION? =1.26
24
+ KUBE_VERSION? =1.31
27
25
KIND_CONFIG? =./hack/kind-$(KUBE_VERSION ) .yaml
28
26
29
27
E2E_IMAGE_REPOSITORY? ="keycloak-image"
44
42
override GCFLAGS +=all=-trimpath=${CURRENT_DIR}
45
43
46
44
# Image URL to use all building/pushing image targets
47
- IMG? =docker.io/epamedp/keycloak-operator:$(VERSION )
45
+ IMG ?= docker.io/epamedp/keycloak-operator:$(VERSION )
46
+
47
+ # IMAGE_TAG_BASE defines the docker.io namespace and part of the image name for remote images.
48
+ # This variable is used to construct full image tags for bundle and catalog images.
49
+ #
50
+ # For example, running 'make bundle-build bundle-push catalog-build catalog-push' will build and push both
51
+ # epamedp/keycloak-operator-bundle:$VERSION and epamedp/keycloak-operator-operator-catalog:$VERSION.
52
+ IMAGE_TAG_BASE ?= epamedp/keycloak-operator
53
+
54
+ # BUNDLE_IMG defines the image:tag used for the bundle.
55
+ # You can use it as an arg. (E.g make bundle-build BUNDLE_IMG=<some-registry>/<project-name-bundle>:<tag>)
56
+ BUNDLE_IMG ?= $(IMAGE_TAG_BASE ) -bundle:v$(VERSION )
48
57
49
58
# BUNDLE_GEN_FLAGS are the flags passed to the operator-sdk generate bundle command
50
59
BUNDLE_GEN_FLAGS ?= -q --overwrite --version $(VERSION ) $(BUNDLE_METADATA_OPTS )
@@ -108,12 +117,13 @@ fmt: ## Run go fmt
108
117
vet : # # Run go vet
109
118
go vet ./...
110
119
120
+ .PHONY : lint
111
121
lint : golangci-lint # # Run go lint
112
- ${GOLANGCILINT } run
122
+ ${GOLANGCI_LINT } run -v -c .golangci.yaml ./...
113
123
114
124
.PHONY : build
115
125
build : clean # # build operator's binary
116
- CGO_ENABLED=0 GOOS=${HOST_OS} GOARCH=${HOST_ARCH} go build -v -ldflags ' ${LDFLAGS}' -o ${DIST_DIR} /${BIN_NAME} -gcflags ' ${GCFLAGS}' .
126
+ CGO_ENABLED=0 GOOS=${HOST_OS} GOARCH=${HOST_ARCH} go build -v -ldflags ' ${LDFLAGS}' -o ${DIST_DIR} /${BIN_NAME} -gcflags ' ${GCFLAGS}' ./cmd
117
127
118
128
.PHONY : clean
119
129
clean : # # clean up
@@ -136,75 +146,83 @@ api-docs: crdoc ## generate CRD docs
136
146
helm-docs : helmdocs # # generate helm docs
137
147
$(HELMDOCS )
138
148
139
- GOLANGCILINT = ${CURRENT_DIR}/bin/golangci-lint
149
+ GOLANGCI_LINT = ${CURRENT_DIR}/bin/golangci-lint
140
150
.PHONY : golangci-lint
141
151
golangci-lint : # # Download golangci-lint locally if necessary.
142
- $(call go-get -tool,$(GOLANGCILINT ) ,github.com/golangci/golangci-lint/cmd/golangci-lint,v1.62.0 )
152
+ $(call go-install -tool,$(GOLANGCI_LINT ) ,github.com/golangci/golangci-lint/cmd/golangci-lint,$( GOLANGCI_LINT_VERSION ) )
143
153
144
154
.PHONY : install
145
155
install : manifests kustomize # # Install CRDs into the K8s cluster specified in ~/.kube/config.
146
156
$(KUSTOMIZE ) build config/crd | kubectl apply -f -
147
157
148
158
# #@ Build Dependencies
149
159
150
- # # Tool Binaries
151
- KUSTOMIZE ?= $(LOCALBIN ) /kustomize
152
-
153
160
# # Tool Versions
154
- KUSTOMIZE_VERSION ?= v4.5.5
161
+ KUSTOMIZE_VERSION ?= v5.4.3
162
+ CONTROLLER_TOOLS_VERSION ?= v0.16.5
163
+ ENVTEST_VERSION ?= release-0.19
164
+ GOLANGCI_LINT_VERSION ?= v1.64.7
165
+ MOCKERY_VERSION ?= v2.53.2
166
+ HELMDOCS_VERSION ?= v1.14.2
167
+ GITCHGLOG_VERSION ?= v0.15.4
168
+ CRDOC_VERSION ?= v0.6.4
169
+ ENVTEST_K8S_VERSION = 1.31.0
170
+ OPERATOR_SDK_VERSION ?= v1.39.2
155
171
156
- KUSTOMIZE_INSTALL_SCRIPT ?= "https://raw.githubusercontent.com/kubernetes-sigs/ kustomize/master/hack/install_kustomize.sh"
172
+ KUSTOMIZE ?= $( LOCALBIN ) / kustomize
157
173
.PHONY : kustomize
158
174
kustomize : $(KUSTOMIZE ) # # Download kustomize locally if necessary.
159
175
$(KUSTOMIZE ) : $(LOCALBIN )
160
- curl -s $( KUSTOMIZE_INSTALL_SCRIPT ) | bash -s -- $( subst v, ,$(KUSTOMIZE_VERSION ) ) $( LOCALBIN )
176
+ $( call go-install-tool, $( KUSTOMIZE ) ,sigs.k8s.io/kustomize/kustomize/v5 ,$(KUSTOMIZE_VERSION ) )
161
177
162
178
HELMDOCS = $(LOCALBIN ) /helm-docs
163
179
.PHONY : helmdocs
164
180
helmdocs : # # Download helm-docs locally if necessary.
165
- $(call go-get -tool,$(HELMDOCS ) ,github.com/norwoodj/helm-docs/cmd/helm-docs,v1.11.0 )
181
+ $(call go-install -tool,$(HELMDOCS ) ,github.com/norwoodj/helm-docs/cmd/helm-docs,$( HELMDOCS_VERSION ) )
166
182
167
183
GITCHGLOG = $(LOCALBIN ) /git-chglog
168
184
.PHONY : git-chglog
169
185
git-chglog : # # Download git-chglog locally if necessary.
170
- $(call go-get -tool,$(GITCHGLOG ) ,github.com/git-chglog/git-chglog/cmd/git-chglog,v0.15.4 )
186
+ $(call go-install -tool,$(GITCHGLOG ) ,github.com/git-chglog/git-chglog/cmd/git-chglog,$( GITCHGLOG_VERSION ) )
171
187
172
188
CRDOC = $(LOCALBIN ) /crdoc
173
189
.PHONY : crdoc
174
190
crdoc : # # Download crdoc locally if necessary.
175
- $(call go-get -tool,$(CRDOC ) ,fybrik.io/crdoc,v0.6.4 )
191
+ $(call go-install -tool,$(CRDOC ) ,fybrik.io/crdoc,$( CRDOC_VERSION ) )
176
192
177
193
CONTROLLER_GEN = $(LOCALBIN ) /controller-gen
178
194
.PHONY : controller-gen
179
195
controller-gen : # # Download controller-gen locally if necessary.
180
- $(call go-get-tool,$(CONTROLLER_GEN ) ,sigs.k8s.io/controller-tools/cmd/controller-gen,v0.15.0)
181
- # go-get-tool will 'go get' any package $2 and install it to $1.
182
- PROJECT_DIR := $(shell dirname $(abspath $(lastword $(MAKEFILE_LIST ) ) ) )
183
- define go-get-tool
184
- @[ -f $(1 ) ] || { \
185
- set -e ;\
186
- TMP_DIR=$$(mktemp -d ) ;\
187
- cd $$TMP_DIR ;\
188
- go mod init tmp ;\
189
- echo "Downloading $(2 ) " ;\
190
- go get -d $(2 ) @$(3 ) ;\
191
- GOBIN=$(PROJECT_DIR ) /bin go install $(2 ) ;\
192
- rm -rf $$TMP_DIR ;\
193
- }
196
+ $(call go-install-tool,$(CONTROLLER_GEN ) ,sigs.k8s.io/controller-tools/cmd/controller-gen,$(CONTROLLER_TOOLS_VERSION ) )
197
+
198
+ # go-install-tool will 'go install' any package with custom target and name of binary, if it doesn't exist
199
+ # $1 - target path with name of binary
200
+ # $2 - package url which can be installed
201
+ # $3 - specific version of package
202
+ define go-install-tool
203
+ @[ -f "$(1 ) -$(3 ) " ] || { \
204
+ set -e; \
205
+ package=$(2 ) @$(3 ) ;\
206
+ echo "Downloading $${package}" ;\
207
+ rm -f $(1 ) || true ;\
208
+ GOBIN=$(LOCALBIN ) go install $${package} ;\
209
+ mv $(1 ) $(1 ) -$(3 ) ;\
210
+ } ;\
211
+ ln -sf $(1 ) -$(3 ) $(1 )
194
212
endef
195
213
196
214
.PHONY : bundle
197
- bundle : manifests kustomize # # Generate bundle manifests and metadata, then validate generated files.
198
- operator-sdk generate kustomize manifests -q
215
+ bundle : manifests kustomize operator-sdk # # Generate bundle manifests and metadata, then validate generated files.
216
+ $( OPERATOR_SDK ) generate kustomize manifests -q
199
217
cd config/manager && $(KUSTOMIZE ) edit set image controller=$(IMG )
200
- $(KUSTOMIZE ) build config/manifests | operator-sdk generate bundle $(BUNDLE_GEN_FLAGS )
201
- operator-sdk bundle validate ./bundle
218
+ $(KUSTOMIZE ) build config/manifests | $( OPERATOR_SDK ) generate bundle $(BUNDLE_GEN_FLAGS )
219
+ $( OPERATOR_SDK ) bundle validate ./bundle
202
220
203
221
ENVTEST =$(LOCALBIN ) /setup-envtest
204
222
.PHONY : envtest
205
223
envtest : $(ENVTEST ) # # Download envtest-setup locally if necessary.
206
224
$(ENVTEST ) : $(LOCALBIN )
207
- $(call go-get -tool,$(ENVTEST ) ,sigs.k8s.io/controller-runtime/tools/setup-envtest,release-0.16 )
225
+ $(call go-install -tool,$(ENVTEST ) ,sigs.k8s.io/controller-runtime/tools/setup-envtest,$( ENVTEST_VERSION ) )
208
226
209
227
.PHONY : start-kind
210
228
start-kind : # # Start kind cluster
@@ -218,4 +236,33 @@ mocks: mockery
218
236
MOCKERY = $(LOCALBIN ) /mockery
219
237
.PHONY : mockery
220
238
mockery : # # Download mockery locally if necessary.
221
- $(call go-get-tool,$(MOCKERY ) ,github.com/vektra/mockery/v2,v2.46.3)
239
+ $(call go-install-tool,$(MOCKERY ) ,github.com/vektra/mockery/v2,$(MOCKERY_VERSION ) )
240
+
241
+ .PHONY : operator-sdk
242
+ OPERATOR_SDK ?= $(LOCALBIN ) /operator-sdk
243
+ operator-sdk : # # Download operator-sdk locally if necessary.
244
+ ifeq (,$(wildcard $(OPERATOR_SDK ) ) )
245
+ ifeq (, $(shell which operator-sdk 2>/dev/null) )
246
+ @{ \
247
+ set -e ;\
248
+ mkdir -p $(dir $(OPERATOR_SDK)) ;\
249
+ OS=$(shell go env GOOS) && ARCH=$(shell go env GOARCH) && \
250
+ curl -sSLo $(OPERATOR_SDK) https://github.com/operator-framework/operator-sdk/releases/download/$(OPERATOR_SDK_VERSION)/operator-sdk_$${OS}_$${ARCH} ;\
251
+ chmod +x $(OPERATOR_SDK) ;\
252
+ }
253
+ else
254
+ OPERATOR_SDK = $(shell which operator-sdk)
255
+ endif
256
+ endif
257
+
258
+ .PHONY : bundle-build
259
+ bundle-build : # # Build the bundle image.
260
+ docker build -f bundle.Dockerfile -t $(BUNDLE_IMG ) .
261
+
262
+ .PHONY : bundle-push
263
+ bundle-push : # # Push the bundle image.
264
+ $(MAKE ) docker-push IMG=$(BUNDLE_IMG )
265
+
266
+ .PHONY : docker-push
267
+ docker-push : # # Push docker image with the manager.
268
+ docker push ${IMG}
0 commit comments