-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
145 lines (112 loc) · 4.08 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
# 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:
PROJECT_ROOT_DIR = .
include Makefile.vars.mk
e2e_make := $(MAKE) -C e2e
go_build ?= CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -v \
-o $(BIN_FILENAME) \
-ldflags "-X main.version=$(VERSION)" \
cmd/crossplane-service-broker/main.go
# Run tests (see https://sdk.operatorframework.io/docs/building-operators/golang/references/envtest-setup)
ENVTEST_ASSETS_DIR=$(shell pwd)/testdata
all: lint test build ## Invokes the lint, test & build targets
.PHONY: test
test: ## Run tests
go test -v ./... -coverprofile cover.out
integration-test: export ENVTEST_K8S_VERSION = 1.28.2
integration-test: export KUBEBUILDER_ATTACH_CONTROL_PLANE_OUTPUT = $(INTEGRATION_TEST_DEBUG_OUTPUT)
integration-test: $(CROSSPLANE_CRDS) ## Run integration tests with envtest
go install sigs.k8s.io/controller-runtime/tools/setup-envtest@latest; \
setup-envtest use -p path 1.25.x!; \
source <(setup-envtest use -i -p env 1.25.x); \
cp $${KUBEBUILDER_ASSETS}/* ${TESTBIN_DIR}; \
go test -tags=integration -v ./... -coverprofile cover.out
.PHONY: build
build: fmt vet $(BIN_FILENAME) ## Build binary
.PHONY: run
run: fmt vet ## Run against the configured Kubernetes cluster in KUBECONFIG
go run cmd/crossplane-service-broker/main.go
.PHONY: fmt
fmt: ## Run go fmt against code
go fmt ./...
.PHONY: vet
vet: ## Run go vet against code
go vet ./...
.PHONY: lint_yaml
lint_yaml: $(YAML_FILES)
$(YAMLLINT_DOCKER) -f parsable -c $(YAMLLINT_CONFIG) $(YAMLLINT_ARGS) -- $?
.PHONY: lint
lint: fmt vet lint_yaml ## Invokes the fmt and vet targets
@echo 'Check for uncommitted changes ...'
git diff --exit-code
.PHONY: docker-build
docker-build: export GOOS = linux
docker-build: $(BIN_FILENAME) ## Build the docker image
docker build . -t $(DOCKER_IMG) -t $(QUAY_IMG) -t $(E2E_IMG)
.PHONY: docker-push
docker-push: ## Push the docker image
docker push $(DOCKER_IMG)
docker push $(QUAY_IMG)
clean: export KUBECONFIG = $(KIND_KUBECONFIG)
clean: e2e-clean kind-clean ## Cleans up the generated resources
rm -r testbin/ dist/ bin/ cover.out $(BIN_FILENAME) || true
.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}'
###
### Assets
###
$(testbin_created):
mkdir -p $(TESTBIN_DIR)
# a marker file must be created, because the date of the
# directory may update when content in it is created/updated,
# which would cause a rebuild / re-initialization of dependants
@touch $(testbin_created)
# Build the binary without running generators
.PHONY: $(BIN_FILENAME)
$(BIN_FILENAME):
$(go_build)
# TODO(mw): something with this target is off, $@ should be used instead of $*.yaml but I can't seem to make it work.
$(TESTDATA_CRD_DIR)/%.yaml: $(testbin_created)
curl -sSLo $@ https://raw.githubusercontent.com/crossplane/crossplane/$(CROSSPLANE_VERSION)/cluster/crds/$*.yaml
###
### KIND
###
.PHONY: kind-setup
kind-setup: ## Creates a kind instance if one does not exist yet.
@$(e2e_make) kind-setup
.PHONY: kind-clean
kind-clean: ## Removes the kind instance if it exists.
@$(e2e_make) kind-clean
.PHONY: kind-run
kind-run: export KUBECONFIG = $(KIND_KUBECONFIG)
kind-run: kind-setup run ## Runs the service broker on the local host but configured for the kind cluster
kind-e2e-image: docker-build
$(e2e_make) kind-e2e-image
###
### E2E Test
###
.PHONY: e2e-test
e2e-test: export KUBECONFIG = $(KIND_KUBECONFIG)
e2e-test: e2e-setup docker-build ## Run the e2e tests
@$(e2e_make) test
.PHONY: e2e-setup
e2e-setup: export KUBECONFIG = $(KIND_KUBECONFIG)
e2e-setup: ## Run the e2e setup
@$(e2e_make) setup
.PHONY: e2e-clean-setup
e2e-clean-setup: export KUBECONFIG = $(KIND_KUBECONFIG)
e2e-clean-setup: ## Clean the e2e setup (e.g. to rerun the e2e-setup)
@$(e2e_make) clean-setup
.PHONY: e2e-clean
e2e-clean: ## Remove all e2e-related resources (incl. all e2e Docker images)
@$(e2e_make) clean
###
### Documentation
###
include ./docs/docs.mk