Makefile 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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=$(CRD_DIR)
  39. # Remove extra header lines in generated CRDs
  40. @for i in $(CRD_DIR)/*.yaml; do \
  41. tail -n +3 <"$$i" >"$$i.bkp" && \
  42. cp "$$i.bkp" "$$i" && \
  43. rm "$$i.bkp"; \
  44. done
  45. lint/check: # Check install of golanci-lint
  46. @if ! golangci-lint --version > /dev/null 2>&1; then \
  47. 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"; \
  48. exit 1; \
  49. fi
  50. lint-install: # installs golangci-lint to the go bin dir
  51. @if ! golangci-lint --version > /dev/null 2>&1; then \
  52. echo "Installing golangci-lint"; \
  53. curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s -- -b $(GOBIN) v1.33.0; \
  54. fi
  55. lint: lint/check ## run golangci-lint
  56. @if ! golangci-lint run; then \
  57. echo -e "\033[0;33mgolangci-lint failed: some checks can be fixed with \`\033[0;32mmake fmt\033[0m\033[0;33m\`\033[0m"; \
  58. exit 1; \
  59. fi
  60. fmt: lint/check ## ensure consistent code style
  61. go mod tidy
  62. go fmt ./...
  63. golangci-lint run --fix > /dev/null 2>&1 || true
  64. generate: controller-gen ## Generate code
  65. $(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./..."
  66. docker-build: test ## Build the docker image
  67. docker build . -t ${IMG}
  68. docker-push: ## Push the docker image
  69. docker push ${IMG}
  70. helm-docs: ## Generate helm docs
  71. cd $(HELM_DIR); \
  72. docker run --rm -v $(shell pwd)/$(HELM_DIR):/helm-docs -u $(shell id -u) jnorwood/helm-docs:latest
  73. crds-to-chart: # Copy crds to helm chart directory
  74. cp $(CRD_DIR)/*.yaml $(HELM_DIR)/templates/crds/
  75. # Add helm chart if statement for installing CRDs
  76. @for i in $(HELM_DIR)/templates/crds/*.yaml; do \
  77. cp "$$i" "$$i.bkp" && \
  78. echo "{{- if .Values.installCRDs }}" > "$$i" && \
  79. cat "$$i.bkp" >> "$$i" && \
  80. echo "{{- end }}" >> "$$i" && \
  81. rm "$$i.bkp"; \
  82. done
  83. # find or download controller-gen
  84. # download controller-gen if necessary
  85. controller-gen:
  86. ifeq (, $(shell which controller-gen))
  87. @{ \
  88. set -e ;\
  89. CONTROLLER_GEN_TMP_DIR=$$(mktemp -d) ;\
  90. cd $$CONTROLLER_GEN_TMP_DIR ;\
  91. go mod init tmp ;\
  92. go get sigs.k8s.io/controller-tools/cmd/controller-gen@v0.4.1 ;\
  93. rm -rf $$CONTROLLER_GEN_TMP_DIR ;\
  94. }
  95. CONTROLLER_GEN=$(GOBIN)/controller-gen
  96. else
  97. CONTROLLER_GEN=$(shell which controller-gen)
  98. endif
  99. help: ## displays this help message
  100. @awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z_\/-]+:.*?## / {printf "\033[34m%-18s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST) | \
  101. sort | \
  102. grep -v '#'