forked from k8up-io/k8up
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
157 lines (125 loc) · 5.05 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
# Set Shell to bash, otherwise some targets fail with dash/zsh etc.
SHELL := /bin/bash
# Disable built-in rules
MAKEFLAGS += --no-builtin-rules
MAKEFLAGS += --no-builtin-variables
.SUFFIXES:
.SECONDARY:
.DEFAULT_GOAL := help
.PHONY: help
help: ## Show this help
@grep -E -h '^[^#].+\s##\s' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-20s\033[0m %s\n", $$1, $$2}'
# extensible array of targets. Modules can add target to this variable for the all-in-one target.
clean_targets := build-clean
PROJECT_ROOT_DIR = .
include Makefile.vars.mk
include Makefile.restic-integration.mk envtest/integration.mk
# Chart-related
-include charts/charts.mk
# Documentation
-include ./docs/docs.mk
# KIND
-include e2e/kind.mk
# E2E tests
-include e2e/Makefile
go_build ?= $(GO_EXEC) build -o $(BIN_FILENAME) $(K8UP_MAIN_GO)
.PHONY: test
test: ## Run tests
$(GO_EXEC) test ./... -coverprofile cover.out
.PHONY: build
build: generate fmt vet $(BIN_FILENAME) docs-update-usage ## Build manager binary
.PHONY: run
run: export ARGS := $(ARGS) operator
run: export BACKUP_ENABLE_LEADER_ELECTION = $(ENABLE_LEADER_ELECTION)
run: export K8UP_DEBUG = true
run: export BACKUP_OPERATOR_NAMESPACE = default
run: fmt vet ## Run against the configured Kubernetes cluster in ~/.kube/config. Use ARGS to pass arguments to the command, e.g. `make run ARGS="--help"`
$(GO_EXEC) run $(K8UP_MAIN_GO) $(ARGS) $(CMD) $(CMD_ARGS)
.PHONY: run-operator
run-operator: CMD := operator
run-operator: run ## Run the operator module against the configured Kubernetes cluster in ~/.kube/config. Use ARGS to pass arguments to the command, e.g. `make run-operator ARGS="--debug" CMD_ARGS="--help"`
.PHONY: run-restic
run-restic: CMD := restic
run-restic: run ## Run the restic module. Use ARGS to pass arguments to the command, e.g. `make run-restic ARGS="--debug" CMD_ARGS="--check"`
.PHONY: install
install: export KUBECONFIG = $(KIND_KUBECONFIG)
install: generate kind-setup ## Install CRDs into a cluster
kubectl apply $(KIND_KUBECTL_ARGS) -f $(CRD_ROOT_DIR)/v1 --server-side
.PHONY: uninstall
uninstall: export KUBECONFIG = $(KIND_KUBECONFIG)
uninstall: generate kind-setup ## Uninstall CRDs from a cluster
kubectl delete -f $(CRD_ROOT_DIR)/v1
deploy_args =
.PHONY: deploy
deploy: export KUBECONFIG = $(KIND_KUBECONFIG)
deploy: kind-load-image install ## Deploy controller in the configured Kubernetes cluster in ~/.kube/config
helm upgrade --install k8up ./charts/k8up \
--create-namespace \
--namespace k8up-system \
--set podAnnotations.imagesha="$(shell docker image inspect $(K8UP_E2E_IMG) | jq -r '.[].Id')" \
--set image.pullPolicy=IfNotPresent \
--set image.registry=$(E2E_REGISTRY) \
--set image.repository=$(E2E_REPO) \
--set image.tag=$(E2E_TAG) \
--values ./e2e/definitions/operator/deploy.yaml \
--wait $(deploy_args)
.PHONY: generate
generate: ## Generate manifests e.g. CRD, RBAC etc.
# Generate code
$(GO_EXEC) run sigs.k8s.io/controller-tools/cmd/controller-gen object:headerFile=".github/boilerplate.go.txt" paths="./..."
# Generate CRDs
$(GO_EXEC) run sigs.k8s.io/controller-tools/cmd/controller-gen rbac:roleName=manager-role webhook paths="./..." output:crd:artifacts:config=$(CRD_ROOT_DIR)/v1 crd:crdVersions=v1
.PHONY: crd
crd: generate ## Generate CRD to file
@yq $(CRD_ROOT_DIR)/v1/*.yaml > $(CRD_FILE)
.PHONY: fmt
fmt: ## Run go fmt against code
$(GO_EXEC) fmt ./...
.PHONY: vet
vet: ## Run go vet against code
$(GO_EXEC) vet ./...
.PHONY: lint
lint: fmt vet golangci-lint ## Invokes all linting targets
@echo 'Check for uncommitted changes ...'
git diff --exit-code
.PHONY: golangci-lint
golangci-lint: $(golangci_bin) ## Run golangci linters
$(golangci_bin) run --timeout 5m --out-format colored-line-number ./...
.PHONY: docker-build
docker-build: $(BIN_FILENAME) ## Build the docker image
docker build . \
--tag $(K8UP_QUAY_IMG) \
--tag $(K8UP_GHCR_IMG) \
--tag $(K8UP_E2E_IMG)
.PHONY: docker-push
docker-push: ## Push the docker image
docker push $(K8UP_QUAY_IMG)
docker push $(K8UP_GHCR_IMG)
build-clean:
rm -rf dist/ bin/ cover.out $(BIN_FILENAME) $(WORK_DIR) $(CRD_FILE)
clean: $(clean_targets) ## Cleans up all the locally generated resources
.PHONY: release-prepare
release-prepare: crd ## Prepares artifacts for releases
###
### Assets
###
# Build the binary without running generators
.PHONY: $(BIN_FILENAME)
$(BIN_FILENAME): export CGO_ENABLED = 0
$(BIN_FILENAME): export GOOS = $(K8UP_GOOS)
$(BIN_FILENAME): export GOARCH = $(K8UP_GOARCH)
$(BIN_FILENAME):
$(go_build)
$(integrationtest_dir):
mkdir -p $(integrationtest_dir)
.PHONY: kind-run
kind-run: export KUBECONFIG = $(KIND_KUBECONFIG)
kind-run: kind-setup kind-minio install run-operator ## Runs the operator on the local host but configured for the kind cluster
.PHONY: kind-minio
kind-minio: $(minio_sentinel)
$(minio_sentinel): export KUBECONFIG = $(KIND_KUBECONFIG)
$(minio_sentinel): kind-setup
kubectl apply -f $(SAMPLES_ROOT_DIR)/deployments/minio.yaml
@touch $@
$(golangci_bin): | $(go_bin)
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b "$(go_bin)"