Skip to content

Commit f169792

Browse files
committed
cleanup makefile
1 parent 31d56e2 commit f169792

File tree

1 file changed

+1
-244
lines changed

1 file changed

+1
-244
lines changed

Makefile

Lines changed: 1 addition & 244 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,13 @@ MAKEFILES_VERSION=10.2.0
99

1010
include build/make/variables.mk
1111
include build/make/self-update.mk
12-
include build/make/dependencies-gomod.mk
1312
include build/make/build.mk
1413
include build/make/test-common.mk
1514
include build/make/test-unit.mk
1615
include build/make/static-analysis.mk
1716
include build/make/clean.mk
18-
include build/make/digital-signature.mk
19-
include build/make/mocks.mk
2017
include build/make/k8s-controller.mk
21-
include build/make/k8s-crd.mk
18+
include build/make/release.mk
2219

2320
CRD_BACKUP_SOURCE = ${HELM_CRD_SOURCE_DIR}/templates/k8s.cloudogu.com_backups.yaml
2421
CRD_RESTORE_SOURCE = ${HELM_CRD_SOURCE_DIR}/templates/k8s.cloudogu.com_restores.yaml
@@ -32,243 +29,3 @@ crd-add-backup-labels: $(BINARY_YQ)
3229
$(BINARY_YQ) -i e ".metadata.labels.\"k8s.cloudogu.com/part-of\" = \"backup\"" $${file} ;\
3330
done
3431

35-
36-
37-
# Image URL to use all building/pushing image targets
38-
IMG ?= controller:latest
39-
40-
# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
41-
ifeq (,$(shell go env GOBIN))
42-
GOBIN=$(shell go env GOPATH)/bin
43-
else
44-
GOBIN=$(shell go env GOBIN)
45-
endif
46-
47-
# CONTAINER_TOOL defines the container tool to be used for building images.
48-
# Be aware that the target commands are only tested with Docker which is
49-
# scaffolded by default. However, you might want to replace it to use other
50-
# tools. (i.e. podman)
51-
CONTAINER_TOOL ?= docker
52-
53-
# Setting SHELL to bash allows bash commands to be executed by recipes.
54-
# Options are set to exit when a recipe line exits non-zero or a piped command fails.
55-
SHELL = /usr/bin/env bash -o pipefail
56-
.SHELLFLAGS = -ec
57-
58-
.PHONY: all
59-
all: build
60-
61-
##@ General
62-
63-
# The help target prints out all targets with their descriptions organized
64-
# beneath their categories. The categories are represented by '##@' and the
65-
# target descriptions by '##'. The awk command is responsible for reading the
66-
# entire set of makefiles included in this invocation, looking for lines of the
67-
# file as xyz: ## something, and then pretty-format the target and help. Then,
68-
# if there's a line with ##@ something, that gets pretty-printed as a category.
69-
# More info on the usage of ANSI control characters for terminal formatting:
70-
# https://en.wikipedia.org/wiki/ANSI_escape_code#SGR_parameters
71-
# More info on the awk command:
72-
# http://linuxcommand.org/lc3_adv_awk.php
73-
74-
.PHONY: help
75-
help: ## Display this help.
76-
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z_0-9-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)
77-
78-
##@ Development
79-
80-
.PHONY: manifests
81-
manifests: controller-gen ## Generate WebhookConfiguration, ClusterRole and CustomResourceDefinition objects.
82-
$(CONTROLLER_GEN) rbac:roleName=manager-role crd webhook paths="./..." output:crd:artifacts:config=config/crd/bases
83-
84-
.PHONY: generate
85-
generate: controller-gen ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations.
86-
$(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./..."
87-
88-
.PHONY: fmt
89-
fmt: ## Run go fmt against code.
90-
go fmt ./...
91-
92-
.PHONY: vet
93-
vet: ## Run go vet against code.
94-
go vet ./...
95-
96-
.PHONY: test
97-
test: manifests generate fmt vet setup-envtest ## Run tests.
98-
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path)" go test $$(go list ./... | grep -v /e2e) -coverprofile cover.out
99-
100-
# TODO(user): To use a different vendor for e2e tests, modify the setup under 'tests/e2e'.
101-
# The default setup assumes Kind is pre-installed and builds/loads the Manager Docker image locally.
102-
# CertManager is installed by default; skip with:
103-
# - CERT_MANAGER_INSTALL_SKIP=true
104-
KIND_CLUSTER ?= k8s-debug-mode-cr-lib-test-e2e
105-
106-
.PHONY: setup-test-e2e
107-
setup-test-e2e: ## Set up a Kind cluster for e2e tests if it does not exist
108-
@command -v $(KIND) >/dev/null 2>&1 || { \
109-
echo "Kind is not installed. Please install Kind manually."; \
110-
exit 1; \
111-
}
112-
@case "$$($(KIND) get clusters)" in \
113-
*"$(KIND_CLUSTER)"*) \
114-
echo "Kind cluster '$(KIND_CLUSTER)' already exists. Skipping creation." ;; \
115-
*) \
116-
echo "Creating Kind cluster '$(KIND_CLUSTER)'..."; \
117-
$(KIND) create cluster --name $(KIND_CLUSTER) ;; \
118-
esac
119-
120-
.PHONY: test-e2e
121-
test-e2e: setup-test-e2e manifests generate fmt vet ## Run the e2e tests. Expected an isolated environment using Kind.
122-
KIND_CLUSTER=$(KIND_CLUSTER) go test ./test/e2e/ -v -ginkgo.v
123-
$(MAKE) cleanup-test-e2e
124-
125-
.PHONY: cleanup-test-e2e
126-
cleanup-test-e2e: ## Tear down the Kind cluster used for e2e tests
127-
@$(KIND) delete cluster --name $(KIND_CLUSTER)
128-
129-
.PHONY: lint
130-
lint: golangci-lint ## Run golangci-lint linter
131-
$(GOLANGCI_LINT) run
132-
133-
.PHONY: lint-fix
134-
lint-fix: golangci-lint ## Run golangci-lint linter and perform fixes
135-
$(GOLANGCI_LINT) run --fix
136-
137-
.PHONY: lint-config
138-
lint-config: golangci-lint ## Verify golangci-lint linter configuration
139-
$(GOLANGCI_LINT) config verify
140-
141-
##@ Build
142-
143-
.PHONY: build
144-
build: manifests generate fmt vet ## Build manager binary.
145-
go build -o bin/manager cmd/main.go
146-
147-
.PHONY: run
148-
run: manifests generate fmt vet ## Run a controller from your host.
149-
go run ./cmd/main.go
150-
151-
# If you wish to build the manager image targeting other platforms you can use the --platform flag.
152-
# (i.e. docker build --platform linux/arm64). However, you must enable docker buildKit for it.
153-
# More info: https://docs.docker.com/develop/develop-images/build_enhancements/
154-
.PHONY: docker-build
155-
docker-build: ## Build docker image with the manager.
156-
$(CONTAINER_TOOL) build -t ${IMG} .
157-
158-
.PHONY: docker-push
159-
docker-push: ## Push docker image with the manager.
160-
$(CONTAINER_TOOL) push ${IMG}
161-
162-
# PLATFORMS defines the target platforms for the manager image be built to provide support to multiple
163-
# architectures. (i.e. make docker-buildx IMG=myregistry/mypoperator:0.0.1). To use this option you need to:
164-
# - be able to use docker buildx. More info: https://docs.docker.com/build/buildx/
165-
# - have enabled BuildKit. More info: https://docs.docker.com/develop/develop-images/build_enhancements/
166-
# - 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)
167-
# To adequately provide solutions that are compatible with multiple platforms, you should consider using this option.
168-
PLATFORMS ?= linux/arm64,linux/amd64,linux/s390x,linux/ppc64le
169-
.PHONY: docker-buildx
170-
docker-buildx: ## Build and push docker image for the manager for cross-platform support
171-
# copy existing Dockerfile and insert --platform=${BUILDPLATFORM} into Dockerfile.cross, and preserve the original Dockerfile
172-
sed -e '1 s/\(^FROM\)/FROM --platform=\$$\{BUILDPLATFORM\}/; t' -e ' 1,// s//FROM --platform=\$$\{BUILDPLATFORM\}/' Dockerfile > Dockerfile.cross
173-
- $(CONTAINER_TOOL) buildx create --name k8s-debug-mode-cr-lib-builder
174-
$(CONTAINER_TOOL) buildx use k8s-debug-mode-cr-lib-builder
175-
- $(CONTAINER_TOOL) buildx build --push --platform=$(PLATFORMS) --tag ${IMG} -f Dockerfile.cross .
176-
- $(CONTAINER_TOOL) buildx rm k8s-debug-mode-cr-lib-builder
177-
rm Dockerfile.cross
178-
179-
.PHONY: build-installer
180-
build-installer: manifests generate kustomize ## Generate a consolidated YAML with CRDs and deployment.
181-
mkdir -p dist
182-
cd config/manager && $(KUSTOMIZE) edit set image controller=${IMG}
183-
$(KUSTOMIZE) build config/default > dist/install.yaml
184-
185-
##@ Deployment
186-
187-
ifndef ignore-not-found
188-
ignore-not-found = false
189-
endif
190-
191-
.PHONY: install
192-
install: manifests kustomize ## Install CRDs into the K8s cluster specified in ~/.kube/config.
193-
$(KUSTOMIZE) build config/crd | $(KUBECTL) apply -f -
194-
195-
.PHONY: uninstall
196-
uninstall: manifests kustomize ## Uninstall CRDs from the K8s cluster specified in ~/.kube/config. Call with ignore-not-found=true to ignore resource not found errors during deletion.
197-
$(KUSTOMIZE) build config/crd | $(KUBECTL) delete --ignore-not-found=$(ignore-not-found) -f -
198-
199-
.PHONY: deploy
200-
deploy: manifests kustomize ## Deploy controller to the K8s cluster specified in ~/.kube/config.
201-
cd config/manager && $(KUSTOMIZE) edit set image controller=${IMG}
202-
$(KUSTOMIZE) build config/default | $(KUBECTL) apply -f -
203-
204-
.PHONY: undeploy
205-
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.
206-
$(KUSTOMIZE) build config/default | $(KUBECTL) delete --ignore-not-found=$(ignore-not-found) -f -
207-
208-
##@ Dependencies
209-
210-
## Location to install dependencies to
211-
LOCALBIN ?= $(shell pwd)/.bin
212-
$(LOCALBIN):
213-
mkdir -p $(LOCALBIN)
214-
215-
## Tool Binaries
216-
KUBECTL ?= kubectl
217-
KIND ?= kind
218-
KUSTOMIZE ?= $(LOCALBIN)/kustomize
219-
CONTROLLER_GEN ?= $(LOCALBIN)/controller-gen
220-
ENVTEST ?= $(LOCALBIN)/setup-envtest
221-
GOLANGCI_LINT = $(LOCALBIN)/golangci-lint
222-
223-
## Tool Versions
224-
KUSTOMIZE_VERSION ?= v5.6.0
225-
CONTROLLER_TOOLS_VERSION ?= v0.18.0
226-
#ENVTEST_VERSION is the version of controller-runtime release branch to fetch the envtest setup script (i.e. release-0.20)
227-
ENVTEST_VERSION ?= $(shell go list -m -f "{{ .Version }}" sigs.k8s.io/controller-runtime | awk -F'[v.]' '{printf "release-%d.%d", $$2, $$3}')
228-
#ENVTEST_K8S_VERSION is the version of Kubernetes to use for setting up ENVTEST binaries (i.e. 1.31)
229-
ENVTEST_K8S_VERSION ?= $(shell go list -m -f "{{ .Version }}" k8s.io/api | awk -F'[v.]' '{printf "1.%d", $$3}')
230-
GOLANGCI_LINT_VERSION ?= v2.1.6
231-
232-
.PHONY: kustomize
233-
kustomize: $(KUSTOMIZE) ## Download kustomize locally if necessary.
234-
$(KUSTOMIZE): $(LOCALBIN)
235-
$(call go-install-tool,$(KUSTOMIZE),sigs.k8s.io/kustomize/kustomize/v5,$(KUSTOMIZE_VERSION))
236-
237-
.PHONY: controller-gen
238-
controller-gen: $(CONTROLLER_GEN) ## Download controller-gen locally if necessary.
239-
$(CONTROLLER_GEN): $(LOCALBIN)
240-
$(call go-install-tool,$(CONTROLLER_GEN),sigs.k8s.io/controller-tools/cmd/controller-gen,$(CONTROLLER_TOOLS_VERSION))
241-
242-
.PHONY: setup-envtest
243-
setup-envtest: envtest ## Download the binaries required for ENVTEST in the local bin directory.
244-
@echo "Setting up envtest binaries for Kubernetes version $(ENVTEST_K8S_VERSION)..."
245-
@$(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path || { \
246-
echo "Error: Failed to set up envtest binaries for version $(ENVTEST_K8S_VERSION)."; \
247-
exit 1; \
248-
}
249-
250-
.PHONY: envtest
251-
envtest: $(ENVTEST) ## Download setup-envtest locally if necessary.
252-
$(ENVTEST): $(LOCALBIN)
253-
$(call go-install-tool,$(ENVTEST),sigs.k8s.io/controller-runtime/tools/setup-envtest,$(ENVTEST_VERSION))
254-
255-
.PHONY: golangci-lint
256-
golangci-lint: $(GOLANGCI_LINT) ## Download golangci-lint locally if necessary.
257-
$(GOLANGCI_LINT): $(LOCALBIN)
258-
$(call go-install-tool,$(GOLANGCI_LINT),github.com/golangci/golangci-lint/v2/cmd/golangci-lint,$(GOLANGCI_LINT_VERSION))
259-
260-
# go-install-tool will 'go install' any package with custom target and name of binary, if it doesn't exist
261-
# $1 - target path with name of binary
262-
# $2 - package url which can be installed
263-
# $3 - specific version of package
264-
define go-install-tool
265-
@[ -f "$(1)-$(3)" ] || { \
266-
set -e; \
267-
package=$(2)@$(3) ;\
268-
echo "Downloading $${package}" ;\
269-
rm -f $(1) || true ;\
270-
GOBIN=$(LOCALBIN) go install $${package} ;\
271-
mv $(1) $(1)-$(3) ;\
272-
} ;\
273-
ln -sf $(1)-$(3) $(1)
274-
endef

0 commit comments

Comments
 (0)