Files
RAGOT DavidandGitHub 2be222eb39 feat(operator): delete, enable, disable (#471)
* Add flag --disable-stack-finalizer, default true
* Stack finalizer drop PG database, ELK document, NATS subjects
2023-10-10 11:40:35 +02:00

179 lines
7.0 KiB
Makefile

# Image URL to use all building/pushing image targets
IMG ?= operator
# ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary.
ENVTEST_K8S_VERSION = 1.24.1
# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
ifeq (,$(shell go env GOBIN))
GOBIN=$(shell go env GOPATH)/bin
else
GOBIN=$(shell go env GOBIN)
endif
# Setting SHELL to bash allows bash commands to be executed by recipes.
# This is a requirement for 'setup-envtest.sh' in the test target.
# Options are set to exit when a recipe line exits non-zero or a piped command fails.
SHELL = /usr/bin/env bash -o pipefail
.SHELLFLAGS = -ec
.PHONY: all
all: build
##@ General
# The help target prints out all targets with their descriptions organized
# beneath their categories. The categories are represented by '##@' and the
# target descriptions by '##'. The awk commands is responsible for reading the
# entire set of makefiles included in this invocation, looking for lines of the
# file as xyz: ## something, and then pretty-format the target and help. Then,
# if there's a line with ##@ something, that gets pretty-printed as a category.
# More info on the usage of ANSI control characters for terminal formatting:
# https://en.wikipedia.org/wiki/ANSI_escape_code#SGR_parameters
# More info on the awk command:
# http://linuxcommand.org/lc3_adv_awk.php
.PHONY: help
help: ## Display this help.
@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)
##@ Development
.PHONY: manifests
manifests: controller-gen ## Generate WebhookConfiguration, ClusterRole and CustomResourceDefinition objects.
$(CONTROLLER_GEN) rbac:roleName=manager-role crd webhook paths="./apis/..." output:crd:artifacts:config=config/crd/bases
$(CONTROLLER_GEN) rbac:roleName=manager-role crd webhook paths="./internal/..." output:crd:artifacts:config=config/crd/bases
.PHONY: generate
generate: controller-gen ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations.
$(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./apis/..."
$(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./internal/..."
.PHONY: fmt
fmt: ## Run go fmt against code.
go fmt ./...
.PHONY: vet
vet: ## Run go vet against code.
go vet ./...
.PHONY: test
test: manifests generate fmt vet envtest ## Run tests.
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) -p path)" go test ./... -coverprofile cover.out
##@ Build
.PHONY: build
build: generate fmt vet ## Build manager binary.
go build -o bin/manager main.go
.PHONY: run
run: manifests generate fmt vet ## Run a controller from your host.
go run ./main.go
.PHONY: docker-build-prod
docker-build-prod: ## Build docker image with go releaser
goreleaser build --skip-validate --clean
mv ./dist/operator_linux_amd64_v1/operator ./
docker build -t ${IMG} -f ./build.Dockerfile ./ --no-cache
.PHONY: docker-build
docker-build: ## Build docker image for development.
docker build -t ${IMG} -f ./Dockerfile ../../ --no-cache
.PHONY: docker-push
docker-push: ## Push docker image with the manager.
docker tag ${IMG} k3d-registry.host.k3d.internal:12345/${IMG}:dev-latest
docker push k3d-registry.host.k3d.internal:12345/${IMG}:dev-latest
##@ Deployment
ifndef ignore-not-found
ignore-not-found = false
endif
.PHONY: install
install: manifests kustomize ## Install CRDs into the K8s cluster specified in ~/.kube/config.
$(KUSTOMIZE) build config/crd | kubectl apply -f -
.PHONY: uninstall
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.
$(KUSTOMIZE) build config/crd | kubectl delete --ignore-not-found=$(ignore-not-found) -f -
.PHONY: deploy
deploy: manifests kustomize ## Deploy controller to the K8s cluster specified in ~/.kube/config.
cd config/manager && $(KUSTOMIZE) edit set image controller=k3d-registry.host.k3d.internal:12345/${IMG}:dev-latest
$(KUSTOMIZE) build config/default | kubectl apply -f -
.PHONY: undeploy
undeploy: ## Undeploy controller from the K8s cluster specified in ~/.kube/config. Call with ignore-not-found=true to ignore resource not found errors during deletion.
$(KUSTOMIZE) build config/default | kubectl delete --ignore-not-found=$(ignore-not-found) -f -
HELM_DIR ?= ./helm/templates/gen
.PHONY: helm-update
helm-update: manifests generate
rm -rf $(HELM_DIR)
mkdir -p $(HELM_DIR)
$(KUSTOMIZE) build config/default --output $(HELM_DIR)
rm -f $(HELM_DIR)/v1_namespace*.yaml
rm -f $(HELM_DIR)/apps_v1_deployment_*.yaml
rm -f $(HELM_DIR)/apiextensions.k8s.io_v1_customresourcedefinition_*.components.formance.com.yaml
.PHONY: helm-debug
helm-debug: helm-update
helm template ./helm --debug
helm install --create-namespace --namespace formance-system -f ./helm/values.yaml formance-operator ./helm --dry-run
.PHONY: helm-install
helm-install: helm-update
helm install --create-namespace --namespace formance-system -f ./helm/values.yaml formance-operator ./helm
.PHONY: helm-local-install
helm-local-install: helm-update
helm install --create-namespace --namespace formance-system -f ./helm/values.yaml --set image.repository="k3d-registry.host.k3d.internal:12345/${IMG}" --set image.tag="dev-latest" formance-operator ./helm
.PHONY: helm-uninstall
helm-uninstall:
helm uninstall formance-operator --namespace formance-system
.PHONY: helm-upgrade
helm-upgrade: helm-update
helm upgrade --namespace formance-system -f ./helm/values.yaml formance-operator ./helm
.PHONY: helm-local-upgrade
helm-local-upgrade: helm-update
helm upgrade --namespace formance-system -f ./helm/values.yaml --set image.repository="k3d-registry.host.k3d.internal:12345/${IMG}" --set image.tag="dev-latest" formance-operator ./helm
##@ Build Dependencies
## Location to install dependencies to
LOCALBIN ?= $(shell pwd)/bin
$(LOCALBIN):
mkdir -p $(LOCALBIN)
## Tool Binaries
KUSTOMIZE ?= $(LOCALBIN)/kustomize
CONTROLLER_GEN ?= $(LOCALBIN)/controller-gen
ENVTEST ?= $(LOCALBIN)/setup-envtest
## Tool Versions
KUSTOMIZE_VERSION ?= v4.5.4
CONTROLLER_TOOLS_VERSION ?= v0.9.2
KUSTOMIZE_INSTALL_SCRIPT ?= "https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh"
.PHONY: kustomize
kustomize: $(KUSTOMIZE) ## Download kustomize locally if necessary.
$(KUSTOMIZE): $(LOCALBIN)
test -f $(LOCALBIN)/kustomize || curl -s $(KUSTOMIZE_INSTALL_SCRIPT) | bash -s -- $(subst v,,$(KUSTOMIZE_VERSION)) $(LOCALBIN)
.PHONY: controller-gen
controller-gen: $(CONTROLLER_GEN) ## Download controller-gen locally if necessary.
$(CONTROLLER_GEN): $(LOCALBIN)
GOBIN=$(LOCALBIN) go install sigs.k8s.io/controller-tools/cmd/controller-gen@$(CONTROLLER_TOOLS_VERSION)
.PHONY: envtest
envtest: $(ENVTEST) ## Download envtest-setup locally if necessary.
$(ENVTEST): $(LOCALBIN)
GOBIN=$(LOCALBIN) go install sigs.k8s.io/controller-runtime/tools/setup-envtest@latest