Makefile 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. MAKEFLAGS += --warn-undefined-variables
  2. SHELL := /bin/bash
  3. .SHELLFLAGS := -euo pipefail -c
  4. .DEFAULT_GOAL := all
  5. # Image URL to use all building/pushing image targets
  6. IMG ?= controller:latest
  7. # Produce CRDs that work back to Kubernetes 1.11 (no version conversion)
  8. CRD_OPTIONS ?= "crd:trivialVersions=true"
  9. HELM_DIR ?= deploy/charts/external-secrets
  10. CRD_DIR ?= config/crd/bases
  11. # Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
  12. ifeq (,$(shell go env GOBIN))
  13. GOBIN=$(shell go env GOPATH)/bin
  14. else
  15. GOBIN=$(shell go env GOBIN)
  16. endif
  17. all: build
  18. .PHONY: test
  19. test: generate manifests ## Run tests
  20. go test ./... -coverprofile cover.out
  21. .PHONY: build
  22. build: generate fmt ## Build binary
  23. go build -o bin/manager main.go
  24. # Run against the configured Kubernetes cluster in ~/.kube/config
  25. run: generate fmt manifests
  26. go run ./main.go
  27. # Install CRDs into a cluster
  28. install: manifests
  29. kustomize build config/crd | kubectl apply -f -
  30. # Uninstall CRDs from a cluster
  31. uninstall: manifests
  32. kustomize build config/crd | kubectl delete -f -
  33. .PHONY: deploy
  34. deploy: manifests ## Deploy controller in the Kubernetes cluster of current context
  35. cd config/manager && kustomize edit set image controller=${IMG}
  36. kustomize build config/default | kubectl apply -f -
  37. manifests: controller-gen ## Generate manifests e.g. CRD, RBAC etc.
  38. $(CONTROLLER_GEN) $(CRD_OPTIONS) rbac:roleName=manager-role webhook paths="./..." output:crd:artifacts:config=config/crd/bases
  39. lint/check: # Check install of golanci-lint
  40. @if ! golangci-lint --version > /dev/null 2>&1; then \
  41. echo -e "\033[0;33mgolangci-lint is not installed: run \`\033[0;32mmake lint-install\033[0m\033[0;33m\` or install it from https://golangci-lint.run\033[0m"; \
  42. exit 1; \
  43. fi
  44. lint-install: # installs golangci-lint to the go bin dir
  45. @if ! golangci-lint --version > /dev/null 2>&1; then \
  46. echo "Installing golangci-lint"; \
  47. curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s -- -b $(GOBIN) v1.33.0; \
  48. fi
  49. lint: lint/check ## run golangci-lint
  50. @if ! golangci-lint run; then \
  51. echo -e "\033[0;33mgolangci-lint failed: some checks can be fixed with \`\033[0;32mmake fmt\033[0m\033[0;33m\`\033[0m"; \
  52. exit 1; \
  53. fi
  54. fmt: lint/check ## ensure consistent code style
  55. go mod tidy
  56. go fmt ./...
  57. golangci-lint run --fix > /dev/null 2>&1 || true
  58. generate: controller-gen ## Generate code
  59. $(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./..."
  60. docker-build: test ## Build the docker image
  61. docker build . -t ${IMG}
  62. docker-push: ## Push the docker image
  63. docker push ${IMG}
  64. helm-docs: ## Generate helm docs
  65. cd $(HELM_DIR); \
  66. docker run --rm -v $(shell pwd)/$(HELM_DIR):/helm-docs -u $(shell id -u) jnorwood/helm-docs:latest
  67. crds-to-chart: # Copy crds to helm chart directory
  68. cp $(CRD_DIR)/*.yaml $(HELM_DIR)/templates/crds/; \
  69. for i in $(HELM_DIR)/templates/crds/*.yaml; do \
  70. sed -i '1s/.*/{{- if .Values.installCRDs }}/;$$a{{- end }}' $$i; \
  71. done
  72. # find or download controller-gen
  73. # download controller-gen if necessary
  74. controller-gen:
  75. ifeq (, $(shell which controller-gen))
  76. @{ \
  77. set -e ;\
  78. CONTROLLER_GEN_TMP_DIR=$$(mktemp -d) ;\
  79. cd $$CONTROLLER_GEN_TMP_DIR ;\
  80. go mod init tmp ;\
  81. go get sigs.k8s.io/controller-tools/cmd/controller-gen@v0.4.1 ;\
  82. rm -rf $$CONTROLLER_GEN_TMP_DIR ;\
  83. }
  84. CONTROLLER_GEN=$(GOBIN)/controller-gen
  85. else
  86. CONTROLLER_GEN=$(shell which controller-gen)
  87. endif
  88. help: ## displays this help message
  89. @awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z_\/-]+:.*?## / {printf "\033[34m%-18s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST) | \
  90. sort | \
  91. grep -v '#'