-
Notifications
You must be signed in to change notification settings - Fork 200
/
Makefile
189 lines (155 loc) · 7.16 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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
# include operatorhub/Makefile
MODULE = $(shell env GO111MODULE=on $(GO) list -m)
DATE ?= $(shell date +%FT%T%z)
KO_DATA_PATH = $(shell pwd)/cmd/$(TARGET)/operator/kodata
TARGET = kubernetes
COMPONENT ?= components.yaml
FORCE_FETCH_RELEASE = false
CR = config/basic
PLATFORM := $(if $(PLATFORM),--platform $(PLATFORM))
GOLANGCI_VERSION = v1.57.2
BIN = $(CURDIR)/.bin
GO = go
TIMEOUT_UNIT = 5m
TIMEOUT_E2E = 20m
V = 0
Q = $(if $(filter 1,$V),,@)
M = $(shell printf "\033[34;1m🐱\033[0m")
export GO111MODULE=on
$(BIN):
@mkdir -p $@
$(BIN)/%: | $(BIN) ; $(info $(M) building $(PACKAGE)…)
$Q tmp=$$(mktemp -d); cd $$tmp; \
env GO111MODULE=on GOPATH=$$tmp GOBIN=$(BIN) $(GO) install $(PACKAGE) \
|| ret=$$?; \
env GO111MODULE=on GOPATH=$$tmp GOBIN=$(BIN) $(GO) clean -modcache \
|| ret=$$?; \
cd - ; \
rm -rf $$tmp ; exit $$ret
KO = $(or ${KO_BIN},${KO_BIN},$(BIN)/ko)
$(BIN)/ko: PACKAGE=github.com/google/ko@latest
KUSTOMIZE = $(or ${KUSTOMIZE_BIN},${KUSTOMIZE_BIN},$(BIN)/kustomize)
$(BIN)/kustomize: | $(BIN) ; $(info $(M) getting kustomize)
@curl -sSfL https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh | bash
@mv ./kustomize $(BIN)/kustomize
GOLANGCILINT = $(or ${GOLANGCILINT_BIN},${GOLANGCILINT_BIN},$(BIN)/golangci-lint)
$(BIN)/golangci-lint: | $(BIN) ; $(info $(M) getting golangci-lint $(GOLANGCI_VERSION))
@curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(BIN) $(GOLANGCI_VERSION)
.PHONY: clean-cluster
clean-cluster: | $(KO) $(KUSTOMIZE) clean-cr; $(info $(M) clean $(TARGET)…) @ ## Cleanup cluster
@ ## --load-restrictor LoadRestrictionsNone is needed in kustomize build as files which not in child tree of kustomize base are pulled
@ ## https://github.com/kubernetes-sigs/kustomize/issues/766
-$(KUSTOMIZE) build --load-restrictor LoadRestrictionsNone config/$(TARGET)/overlays/default | $(KO) delete -f -
-kubectl delete ns tekton-pipelines --ignore-not-found
-kubectl delete \
-f $(KO_DATA_PATH)/ \
--ignore-not-found \
--recursive
.PHONY: clean-manifest
clean-manifest:
ifeq ($(TARGET), openshift)
rm -rf ./cmd/$(TARGET)/operator/kodata/tekton-pipeline
rm -rf ./cmd/$(TARGET)/operator/kodata/tekton-trigger
rm -rf ./cmd/$(TARGET)/operator/kodata/tekton-chains
rm -rf ./cmd/$(TARGET)/operator/kodata/tekton-hub
rm -rf ./cmd/$(TARGET)/operator/kodata/tekton-results
rm -rf ./cmd/$(TARGET)/operator/kodata/manual-approval-gate
rm -rf ./cmd/$(TARGET)/operator/kodata/tekton-pruner
rm -rf ./cmd/$(TARGET)/operator/kodata/tekton-addon/pipelines-as-code
rm -rf ./cmd/$(TARGET)/operator/kodata/tekton-addon/addons/06-ecosystem/tasks
rm -rf ./cmd/$(TARGET)/operator/kodata/tekton-addon/addons/06-ecosystem/stepactions
rm -rf ./cmd/$(TARGET)/operator/kodata/tekton-addon/pipelines-as-code-templates/go.yaml
rm -rf ./cmd/$(TARGET)/operator/kodata/tekton-addon/pipelines-as-code-templates/java.yaml
rm -rf ./cmd/$(TARGET)/operator/kodata/tekton-addon/pipelines-as-code-templates/nodejs.yaml
rm -rf ./cmd/$(TARGET)/operator/kodata/tekton-addon/pipelines-as-code-templates/python.yaml
rm -rf ./cmd/$(TARGET)/operator/kodata/tekton-addon/pipelines-as-code-templates/generic.yaml
else
rm -rf ./cmd/$(TARGET)/operator/kodata/tekton*
rm -rf ./cmd/$(TARGET)/operator/kodata/manual-approval-gate
endif
.PHONY: clean-bin
clean-bin:
-rm -rf $(BIN)
-rm -rf bin
-rm -rf test/tests.* test/coverage.*
.PHONY: clean
clean: clean-cluster clean-bin clean-manifest; $(info $(M) clean all) @ ## Cleanup everything
.PHONY: help
help:
@grep -hE '^[ a-zA-Z0-9/_-]+:.*?## .*$$' $(MAKEFILE_LIST) | \
awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-17s\033[0m %s\n", $$1, $$2}'
FORCE:
bin/%: cmd/% FORCE
$Q $(GO) build -mod=vendor $(LDFLAGS) -v -o $@ ./$<
.PHONY: components/bump
components/bump: $(OPERATORTOOL) ## Bump the version of a component and update ClusterServiceVersion (CSV) file
@go run ./cmd/tool bump ${COMPONENT}
.PHONY: components/bump-bugfix
components/bump-bugfix: $(OPERATORTOOL)
@go run ./cmd/tool bump --bugfix ${COMPONENT}
.PHONY: get-releases
get-releases: |
$Q ./hack/fetch-releases.sh $(TARGET) ${COMPONENT} $(FORCE_FETCH_RELEASE) || exit ;
.PHONY: apply
apply: | $(KO) $(KUSTOMIZE) get-releases ; $(info $(M) ko apply on $(TARGET)) @ ## Apply config to the current cluster
@ ## --load-restrictor LoadRestrictionsNone is needed in kustomize build as files which not in child tree of kustomize base are pulled
@ ## https://github.com/kubernetes-sigs/kustomize/issues/766
$Q $(KUSTOMIZE) build --load-restrictor LoadRestrictionsNone config/$(TARGET)/overlays/default | $(KO) apply $(KO_FLAGS) $(PLATFORM) -f -
.PHONY: apply-cr
apply-cr: | ; $(info $(M) apply CRs on $(TARGET)) @ ## Apply the CRs to the current cluster
$Q kubectl apply -f config/crs/$(TARGET)/$(CR)
.PHONY: operator-bundle
operator-bundle:
make -C operatorhub operator-bundle
.PHONY: clean-cr
clean-cr: | ; $(info $(M) clean CRs on $(TARGET)) @ ## Clean the CRs to the current cluster
-$Q kubectl delete -f config/crs/$(TARGET)/$(CR)
.PHONY: resolve
resolve: | $(KO) $(KUSTOMIZE) get-releases ; $(info $(M) ko resolve on $(TARGET)) @ ## Resolve config to the current cluster
@ ## --load-restrictor LoadRestrictionsNone is needed in kustomize build as files which not in child tree of kustomize base are pulled
@ ## https://github.com/kubernetes-sigs/kustomize/issues/766
$Q $(KUSTOMIZE) build --load-restrictor LoadRestrictionsNone config/$(TARGET)/overlays/default | $(KO) resolve --push=false --oci-layout-path=$(BIN)/oci -f -
.PHONY: generated
generated: | vendor ; $(info $(M) update generated files) ## Update generated files
$Q ./hack/update-codegen.sh
.PHONY: vendor
vendor: ; $(info $(M) update vendor folder) ## Update vendor folder
$Q ./hack/update-deps.sh
## Tests
GO = go
TEST_UNIT_TARGETS := test-unit-verbose test-unit-race test-unit-failfast
test-unit-verbose: ARGS=-v
test-unit-failfast: ARGS=-failfast
test-unit-race: ARGS=-race
$(TEST_UNIT_TARGETS): test-unit
test-clean: ## Clean testcache
@echo "Cleaning test cache"
@go clean -testcache
.PHONY: $(TEST_UNIT_TARGETS) test test-unit
test: test-clean test-unit ## Run test-unit
test-unit: ## Run unit tests
@echo "Running unit tests..."
@set -o pipefail ; \
$(GO) test -timeout $(TIMEOUT_UNIT) $(ARGS) ./... | { grep -v 'no test files'; true; }
.PHONY: lint
lint: lint-go lint-yaml ## run all linters
.PHONY: lint-go
lint-go: | $(GOLANGCILINT) ## runs go linter on all go files
@echo "Linting go files..."
@$(GOLANGCILINT) run ./... --modules-download-mode=vendor \
--max-issues-per-linter=0 \
--max-same-issues=0 \
--timeout 5m
YAML_FILES := $(shell find . -type f -regex ".*y[a]ml" -print)
.PHONY: lint-yaml
lint-yaml: ${YAML_FILES} ## runs yamllint on all yaml files
@echo "Linting yaml files..."
@yamllint -c .yamllint $(YAML_FILES)
# Prerequisite: docker [or] podman and kind
# this will deploy a local registry using docker and create a kind cluster
# configuring with the registry
# then does make apply to deploy the operator
# and show the location of kubeconfig at last
.PHONY: dev-setup
dev-setup: # setup kind with local registry for local development
@cd ./hack/dev/kind/;./install.sh