forked from Kong/kubernetes-ingress-controller
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMakefile
256 lines (208 loc) · 8.74 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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
# ------------------------------------------------------------------------------
# Configuration
# ------------------------------------------------------------------------------
TAG?=2.0.4
REGISTRY?=kong
REPO_INFO=$(shell git config --get remote.origin.url)
REPO_URL=github.com/kong/kubernetes-ingress-controller
IMGNAME?=kubernetes-ingress-controller
IMAGE = $(REGISTRY)/$(IMGNAME)
IMG ?= controller:latest
NCPU ?= $(shell getconf _NPROCESSORS_ONLN)
# ------------------------------------------------------------------------------
# Setup
# ------------------------------------------------------------------------------
REPO_INFO=$(shell git config --get remote.origin.url)
ifndef COMMIT
COMMIT := $(shell git rev-parse --short HEAD)
endif
export GO111MODULE=on
CONTROLLER_GEN = $(shell pwd)/bin/controller-gen
controller-gen: ## Download controller-gen locally if necessary.
$(call go-get-tool,$(CONTROLLER_GEN),sigs.k8s.io/controller-tools/cmd/[email protected])
KUSTOMIZE = $(shell pwd)/bin/kustomize
kustomize: ## Download kustomize locally if necessary.
$(call go-get-tool,$(KUSTOMIZE),sigs.k8s.io/kustomize/kustomize/[email protected])
CLIENT_GEN = $(shell pwd)/bin/client-gen
client-gen: ## Download client-gen locally if necessary.
$(call go-get-tool,$(CLIENT_GEN),k8s.io/code-generator/cmd/[email protected])
# go-get-tool will 'go get' any package $2 and install it to $1.
PROJECT_DIR := $(shell dirname $(abspath $(lastword $(MAKEFILE_LIST))))
define go-get-tool
@[ -f $(1) ] || { \
set -e ;\
TMP_DIR=$$(mktemp -d) ;\
cd $$TMP_DIR ;\
go mod init tmp ;\
echo "Downloading $(2)" ;\
GOBIN=$(PROJECT_DIR)/bin go get $(2) ;\
rm -rf $$TMP_DIR ;\
}
endef
# ------------------------------------------------------------------------------
# Build
# ------------------------------------------------------------------------------
CRD_OPTIONS ?= "crd:trivialVersions=true,preserveUnknownFields=false,allowDangerousTypes=true"
# 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
all: build
.PHONY: clean
clean:
@rm -rf build/
@rm -rf testbin/
@rm -rf bin/*
@rm -f coverage*.out
.PHONY: build
build: generate fmt vet lint
go build -a -o bin/manager -ldflags "-s -w \
-X github.com/kong/kubernetes-ingress-controller/v2/internal/metadata.Release=$(TAG) \
-X github.com/kong/kubernetes-ingress-controller/v2/internal/metadata.Commit=$(COMMIT) \
-X github.com/kong/kubernetes-ingress-controller/v2/internal/metadata.Repo=$(REPO_INFO)" internal/cmd/main.go
.PHONY: imports
imports:
@find ./ -type f -name '*.go' -exec goimports -local $(REPO_URL) -w {} \;
.PHONY: fmt
fmt:
go fmt ./...
.PHONY: vet
vet:
go vet ./...
.PHONY: lint
lint: verify.tidy
golangci-lint run ./...
.PHONY: verify.tidy
verify.tidy:
./hack/verify-tidy.sh
.PHONY: verify.repo
verify.repo:
./hack/verify-repo.sh
.PHONY: verify.diff
verify.diff:
./hack/verify-diff.sh
.PHONY: verify.manifests
verify.manifests: verify.repo manifests manifests.single verify.diff
.PHONY: verify.generators
verify.generators: verify.repo generate verify.diff
# ------------------------------------------------------------------------------
# Build - Manifests
# ------------------------------------------------------------------------------
.PHONY: manifests
manifests: manifests.crds manifests.single
.PHONY: manifests.crds
manifests.crds: controller-gen ## Generate WebhookConfiguration, ClusterRole and CustomResourceDefinition objects.
$(CONTROLLER_GEN) $(CRD_OPTIONS) rbac:roleName=kong-ingress webhook paths="./..." output:crd:artifacts:config=build/config/crd/bases
go run hack/generators/manifests/main.go --input-directory build/config/crd/bases/ --output-directory config/crd/bases
.PHONY: manifests.single
manifests.single: kustomize ## Compose single-file deployment manifests from building blocks
./hack/deploy/build-single-manifests.sh
# ------------------------------------------------------------------------------
# Build - Generators
# ------------------------------------------------------------------------------
.PHONY: generate
generate: generate.controllers generate.clientsets
.PHONY: generate.controllers
generate.controllers: controller-gen
$(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./..."
go generate ./...
# this will generate the custom typed clients needed for end-users implementing logic in Go to use our API types.
# TODO: we're hacking around client-gen for now to enable it for enabled go modules, should probably contribute upstream to improve this.
# See: https://github.com/Kong/kubernetes-ingress-controller/issues/1254
.PHONY: generate.clientsets
generate.clientsets: client-gen
@$(CLIENT_GEN) --go-header-file ./hack/boilerplate.go.txt \
--clientset-name clientset \
--input-base github.com/kong/kubernetes-ingress-controller/v2/pkg/apis/ \
--input configuration/v1,configuration/v1beta1 \
--input-dirs github.com/kong/kubernetes-ingress-controller/pkg/apis/configuration/v1beta1/,github.com/kong/kubernetes-ingress-controller/pkg/apis/configuration/v1/ \
--output-base client-gen-tmp/ \
--output-package github.com/kong/kubernetes-ingress-controller/v2/pkg/
@rm -rf pkg/clientset/
@mv client-gen-tmp/github.com/kong/kubernetes-ingress-controller/v2/pkg/clientset pkg/
@rm -rf client-gen-tmp/
# ------------------------------------------------------------------------------
# Build Images
# ------------------------------------------------------------------------------
.PHONY: container
container:
docker build \
-f Dockerfile \
--build-arg TAG=${TAG} --build-arg COMMIT=${COMMIT} \
--build-arg REPO_INFO=${REPO_INFO} \
-t ${IMAGE}:${TAG} .
# ------------------------------------------------------------------------------
# Test
# ------------------------------------------------------------------------------
PKG_LIST = ./pkg/...,./internal/...
KIND_CLUSTER_NAME ?= "integration-tests"
.PHONY: test.all
test.all: test test.integration
.PHONY: test.integration
test.integration: test.integration.enterprise.postgres test.integration.dbless test.integration.postgres
.PHONY: test
test:
@go test -v -race \
-covermode=atomic \
-coverpkg=$(PKG_LIST) \
-coverprofile=coverage.unit.out \
./...
.PHONY: test.integration.dbless
test.integration.dbless:
@./scripts/check-container-environment.sh
@TEST_DATABASE_MODE="off" GOFLAGS="-tags=integration_tests" go test -v -race \
-timeout 15m \
-parallel $(NCPU) \
-covermode=atomic \
-coverpkg=$(PKG_LIST) \
-coverprofile=coverage.dbless.out \
./test/integration
# TODO: race checking has been temporarily turned off because of race conditions found with deck. This will be resolved in an upcoming Alpha release of KIC 2.0.
# See: https://github.com/Kong/kubernetes-ingress-controller/issues/1324
.PHONY: test.integration.postgres
test.integration.postgres:
@./scripts/check-container-environment.sh
@TEST_DATABASE_MODE="postgres" GOFLAGS="-tags=integration_tests" go test -v \
-timeout 15m \
-parallel $(NCPU) \
-covermode=atomic \
-coverpkg=$(PKG_LIST) \
-coverprofile=coverage.postgres.out \
./test/integration
# TODO: ditto above https://github.com/Kong/kubernetes-ingress-controller/issues/1324
.PHONY: test.integration.enterprise.postgres
test.integration.enterprise.postgres:
@./scripts/check-container-environment.sh
@TEST_DATABASE_MODE="postgres" TEST_KONG_ENTERPRISE="true" GOFLAGS="-tags=integration_tests" go test -v \
-timeout 15m \
-parallel $(NCPU) \
-covermode=atomic \
-coverpkg=$(PKG_LIST) \
-coverprofile=coverage.enterprisepostgres.out \
./test/integration
.PHONY: test.integration.legacy
test.integration.legacy: container
KIC_IMAGE="${IMAGE}:${TAG}" KUBE_VERSION=${KUBE_VERSION} ./hack/legacy/test/test.sh
.PHONY: test.e2e
test.e2e:
GOFLAGS="-tags=e2e_tests" go test -v \
-race \
-parallel $(NCPU) \
-timeout 30m \
./test/e2e/...
# ------------------------------------------------------------------------------
# Operations
# ------------------------------------------------------------------------------
run: manifests generate fmt vet ## Run a controller from your host.
go run ./internal/cmd/main.go
install: manifests kustomize ## Install CRDs into the K8s cluster specified in ~/.kube/config.
$(KUSTOMIZE) build config/crd | kubectl apply -f -
uninstall: manifests kustomize ## Uninstall CRDs from the K8s cluster specified in ~/.kube/config.
$(KUSTOMIZE) build config/crd | kubectl delete -f -
deploy: manifests kustomize ## Deploy controller to the K8s cluster specified in ~/.kube/config.
cd config/manager && $(KUSTOMIZE) edit set image controller=${IMG}
$(KUSTOMIZE) build config/default | kubectl apply -f -
undeploy: ## Undeploy controller from the K8s cluster specified in ~/.kube/config.
$(KUSTOMIZE) build config/default | kubectl delete -f -