2727 GOBIN = $(shell go env GOBIN)
2828endif
2929
30+ .PHONY : all
3031all : build
3132
3233# #@ General
@@ -50,6 +51,7 @@ help: ## Display this help.
5051shellcheck :
5152 @find . -type f -name * .sh -exec docker run --rm -v $(shell pwd) :/mnt koalaman/shellcheck:stable {} +
5253
54+ .PHONY : manifests
5355manifests : controller-gen # # Generate WebhookConfiguration, ClusterRole and CustomResourceDefinition objects.
5456 $(CONTROLLER_GEN ) $(CRD_OPTIONS ) rbac:roleName=manager-role webhook paths=" ./apis/fluentbit/..." output:crd:artifacts:config=config/crd/bases
5557 $(CONTROLLER_GEN ) $(CRD_OPTIONS ) rbac:roleName=manager-role webhook paths=" ./apis/fluentd/..." output:crd:artifacts:config=config/crd/bases
@@ -58,13 +60,15 @@ manifests: controller-gen ## Generate WebhookConfiguration, ClusterRole and Cust
5860 kubectl kustomize config/crd/bases/ | sed -e ' /creationTimestamp/d' > manifests/setup/fluent-operator-crd.yaml
5961 kubectl kustomize manifests/setup/ | sed -e ' /creationTimestamp/d' > manifests/setup/setup.yaml
6062
63+ .PHONY : generate
6164generate : controller-gen # # Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations.
6265 $(CONTROLLER_GEN ) object:headerFile=" hack/boilerplate.go.txt" paths=" ./..."
63- ./hack/update-codegen.sh
6466
67+ PHONY : fmt
6568fmt : # # Run go fmt against code.
6669 go fmt ./...
6770
71+ PHONY : vet
6872vet : # # Run go vet against code.
6973 go vet ./...
7074
@@ -81,6 +85,19 @@ setup-envtest: install-setup-envtest ## Download and set up the envtest binary
8185test : manifests generate fmt vet setup-envtest # # Run tests.
8286 go test ./apis/... -coverprofile cover.out
8387
88+ # Utilize Kind or modify the e2e tests to load the image locally, enabling compatibility with other vendors.
89+ .PHONY : test-e2e # Run the e2e tests against a Kind k8s instance that is spun up.
90+ test-e2e :
91+ go test ./test/e2e/ -v -ginkgo.v
92+
93+ .PHONY : lint
94+ lint : golangci-lint # # Run golangci-lint linter
95+ $(GOLANGCI_LINT ) run
96+
97+ .PHONY : lint-fix
98+ lint-fix : golangci-lint # # Run golangci-lint linter and perform fixes
99+ $(GOLANGCI_LINT ) run --fix
100+
84101# #@ Build
85102
86103binary :
@@ -159,39 +176,156 @@ deploy: manifests kustomize ## Deploy controller to the K8s cluster specified in
159176undeploy : # # Undeploy controller from the K8s cluster specified in ~/.kube/config.
160177 kubectl delete -f manifests/setup/setup.yaml
161178
162- CONTROLLER_GEN = $(shell pwd) /bin/controller-gen
163- controller-gen : go-deps # # Download controller-gen locally if necessary.
164- $(call go-get-tool,$(CONTROLLER_GEN ) ,sigs.k8s.io/controller-tools/cmd/[email protected] ) 165-
166- GINKGO = $(shell pwd) /bin/ginkgo
167- ginkgo : go-deps # # Download controller-gen locally if necessary.
168- $(call go-get-tool,$(GINKGO ) ,github.com/onsi/ginkgo/v2/[email protected] ) 169-
170-
171- KUSTOMIZE = $(shell pwd) /bin/kustomize
172- kustomize : go-deps # # Download kustomize locally if necessary.
173- $(call go-get-tool,$(KUSTOMIZE ) ,sigs.k8s.io/kustomize/kustomize/[email protected] ) 174-
175- CODE_GENERATOR =
$(shell go env GOPATH) /pkg/mod/k8s.io/
[email protected] 176- code-generator : go-deps # # Download code-generator locally if necessary
177- $(call go-get-tool,$(CODE_GENERATOR ) ,k8s.io/[email protected] ) 178-
179- # go-get-tool will 'go get' any package $2 and install it to $1.
180- PROJECT_DIR := $(shell dirname $(abspath $(lastword $(MAKEFILE_LIST ) ) ) )
181- define go-get-tool
182- @[ -f $(1 ) ] || { \
183- set -e ;\
184- TMP_DIR=$$(mktemp -d ) ;\
185- cd $$TMP_DIR ;\
186- go mod init tmp ;\
187- echo "Downloading $(2 ) " ;\
188- GOBIN=$(PROJECT_DIR ) /bin go install $(2 ) ;\
189- rm -rf $$TMP_DIR ;\
190- }
179+ # #@ Dependencies
180+
181+ # # Location to install dependencies to
182+ LOCALBIN ?= $(shell pwd) /bin
183+ $(LOCALBIN ) :
184+ mkdir -p $(LOCALBIN )
185+
186+ # # Tool Binaries
187+ KUBECTL ?= kubectl
188+ KUSTOMIZE ?= $(LOCALBIN ) /kustomize
189+ CONTROLLER_GEN ?= $(LOCALBIN ) /controller-gen
190+ ENVTEST ?= $(LOCALBIN ) /setup-envtest
191+ GOLANGCI_LINT = $(LOCALBIN ) /golangci-lint
192+ GINKGO = $(LOCALBIN ) /ginkgo
193+ CODE_GENERATOR = $(LOCALBIN ) /code-generator
194+ KIND = $(LOCALBIN ) /kind
195+
196+ # # Tool Versions
197+ KUSTOMIZE_VERSION ?= v5.6.0
198+ CONTROLLER_TOOLS_VERSION ?= v0.15.0
199+ ENVTEST_VERSION ?= release-0.19
200+ GOLANGCI_LINT_VERSION ?= v1.59.1
201+ GINKGO_VERSION ?= v2.23.4
202+ CODE_GENERATOR_VERSION ?= v0.32.3
203+ KIND_VERSION ?= v0.17.0
204+
205+ .PHONY : kustomize
206+ kustomize : $(KUSTOMIZE ) # # Download kustomize locally if necessary.
207+ $(KUSTOMIZE ) : $(LOCALBIN )
208+ $(call go-install-tool,$(KUSTOMIZE ) ,sigs.k8s.io/kustomize/kustomize/v5,$(KUSTOMIZE_VERSION ) )
209+
210+ .PHONY : controller-gen
211+ controller-gen : $(CONTROLLER_GEN ) # # Download controller-gen locally if necessary.
212+ $(CONTROLLER_GEN ) : $(LOCALBIN )
213+ $(call go-install-tool,$(CONTROLLER_GEN ) ,sigs.k8s.io/controller-tools/cmd/controller-gen,$(CONTROLLER_TOOLS_VERSION ) )
214+
215+ .PHONY : envtest
216+ envtest : $(ENVTEST ) # # Download setup-envtest locally if necessary.
217+ $(ENVTEST ) : $(LOCALBIN )
218+ $(call go-install-tool,$(ENVTEST ) ,sigs.k8s.io/controller-runtime/tools/setup-envtest,$(ENVTEST_VERSION ) )
219+
220+ .PHONY : golangci-lint
221+ golangci-lint : $(GOLANGCI_LINT ) # # Download golangci-lint locally if necessary.
222+ $(GOLANGCI_LINT ) : $(LOCALBIN )
223+ $(call go-install-tool,$(GOLANGCI_LINT ) ,github.com/golangci/golangci-lint/cmd/golangci-lint,$(GOLANGCI_LINT_VERSION ) )
224+
225+ .PHONY : ginkgo
226+ ginkgo : $(GINKGO ) # # Download ginkgo locally if necessary.
227+ $(GINKGO ) : $(LOCALBIN )
228+ $(call go-install-tool,$(GINKGO ) ,github.com/onsi/ginkgo/v2/ginkgo,$(GINKGO_VERSION ) )
229+
230+ .PHONY : code-generator
231+ code-generator : $(CODE_GENERATOR ) # # Download code-generator locally if necessary.
232+ $(CODE_GENERATOR ) : $(LOCALBIN )
233+ $(call go-install-tool,$(CODE_GENERATOR ) ,k8s.io/code-generator,$(CODE_GENERATOR_VERSION ) )
234+
235+ .PHONY : kind
236+ kind : $(KIND ) # # Download code-generator locally if necessary.
237+ $(KIND ) : $(LOCALBIN )
238+ $(call go-install-tool,$(KIND ) ,sigs.k8s.io/kind,$(KIND_VERSION ) )
239+
240+ # go-install-tool will 'go install' any package with custom target and name of binary, if it doesn't exist
241+ # $1 - target path with name of binary
242+ # $2 - package url which can be installed
243+ # $3 - specific version of package
244+ define go-install-tool
245+ @[ -f "$(1 ) -$(3 ) " ] || { \
246+ set -e; \
247+ package=$(2 ) @$(3 ) ;\
248+ echo "Downloading $${package}" ;\
249+ rm -f $(1 ) || true ;\
250+ GOBIN=$(LOCALBIN ) go install $${package} ;\
251+ mv $(1 ) $(1 ) -$(3 ) ;\
252+ } ;\
253+ ln -sf $(1 ) -$(3 ) $(1 )
191254endef
192255
256+ .PHONY : operator-sdk
257+ OPERATOR_SDK ?= $(LOCALBIN ) /operator-sdk
258+ operator-sdk : # # Download operator-sdk locally if necessary.
259+ ifeq (,$(wildcard $(OPERATOR_SDK ) ) )
260+ ifeq (, $(shell which operator-sdk 2>/dev/null) )
261+ @{ \
262+ set -e ;\
263+ mkdir -p $(dir $(OPERATOR_SDK)) ;\
264+ OS=$(shell go env GOOS) && ARCH=$(shell go env GOARCH) && \
265+ curl -sSLo $(OPERATOR_SDK) https://github.com/operator-framework/operator-sdk/releases/download/$(OPERATOR_SDK_VERSION)/operator-sdk_$${OS}_$${ARCH} ;\
266+ chmod +x $(OPERATOR_SDK) ;\
267+ }
268+ else
269+ OPERATOR_SDK = $(shell which operator-sdk)
270+ endif
271+ endif
272+ .PHONY : bundle
273+ bundle : manifests kustomize operator-sdk # # Generate bundle manifests and metadata, then validate generated files.
274+ $(OPERATOR_SDK ) generate kustomize manifests -q
275+ cd config/manager && $(KUSTOMIZE ) edit set image controller=$(IMG )
276+ $(KUSTOMIZE ) build config/manifests | $(OPERATOR_SDK ) generate bundle $(BUNDLE_GEN_FLAGS )
277+ $(OPERATOR_SDK ) bundle validate ./bundle
278+
279+ .PHONY : bundle-build
280+ bundle-build : # # Build the bundle image.
281+ docker build -f bundle.Dockerfile -t $(BUNDLE_IMG ) .
282+
283+ .PHONY : bundle-push
284+ bundle-push : # # Push the bundle image.
285+ $(MAKE ) docker-push IMG=$(BUNDLE_IMG )
286+
287+ .PHONY : opm
288+ OPM = $(LOCALBIN ) /opm
289+ opm : # # Download opm locally if necessary.
290+ ifeq (,$(wildcard $(OPM ) ) )
291+ ifeq (,$(shell which opm 2>/dev/null) )
292+ @{ \
293+ set -e ;\
294+ mkdir -p $(dir $(OPM)) ;\
295+ OS=$(shell go env GOOS) && ARCH=$(shell go env GOARCH) && \
296+ curl -sSLo $(OPM) https://github.com/operator-framework/operator-registry/releases/download/v1.23.0/$${OS}-$${ARCH}-opm ;\
297+ chmod +x $(OPM) ;\
298+ }
299+ else
300+ OPM = $(shell which opm)
301+ endif
302+ endif
303+
304+ # A comma-separated list of bundle images (e.g. make catalog-build BUNDLE_IMGS=example.com/operator-bundle:v0.1.0,example.com/operator-bundle:v0.2.0).
305+ # These images MUST exist in a registry and be pull-able.
306+ BUNDLE_IMGS ?= $(BUNDLE_IMG )
307+
308+ # The image tag given to the resulting catalog image (e.g. make catalog-build CATALOG_IMG=example.com/operator-catalog:v0.2.0).
309+ CATALOG_IMG ?= $(IMAGE_TAG_BASE ) -catalog:v$(VERSION )
310+
311+ # Set CATALOG_BASE_IMG to an existing catalog image tag to add $BUNDLE_IMGS to that image.
312+ ifneq ($(origin CATALOG_BASE_IMG ) , undefined)
313+ FROM_INDEX_OPT := --from-index $(CATALOG_BASE_IMG )
314+ endif
315+
316+ # Build a catalog image by adding bundle images to an empty catalog using the operator package manager tool, 'opm'.
317+ # This recipe invokes 'opm' in 'semver' bundle add mode. For more information on add modes, see:
318+ # https://github.com/operator-framework/community-operators/blob/7f1438c/docs/packaging-operator.md#updating-your-existing-operator
319+ .PHONY : catalog-build
320+ catalog-build : opm # # Build a catalog image.
321+ $(OPM ) index add --container-tool docker --mode semver --tag $(CATALOG_IMG ) --bundles $(BUNDLE_IMGS ) $(FROM_INDEX_OPT )
322+
323+ # Push the catalog image.
324+ .PHONY : catalog-push
325+ catalog-push : # # Push a catalog image.
326+ $(MAKE ) docker-push IMG=$(CATALOG_IMG )
327+
193328go-deps : # download go dependencies
194- 195329 go mod download
196330
197331docs-update : # update api docs
0 commit comments