-
Notifications
You must be signed in to change notification settings - Fork 21
/
Makefile
236 lines (188 loc) · 10.7 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
include smoketests/Makefile.variables
.DEFAULT_GOAL := all
MAKEFLAGS += --environment-overrides --warn-undefined-variables # --print-directory --no-builtin-rules --no-builtin-variables
# Add bin to the PATH
export PATH := $(shell pwd)/bin:$(PATH)
export PATH := $(shell go env GOPATH)/bin:${PATH}
VERSION ?= $(shell git describe --tags)
# Image URL to use all building/pushing image targets
IMAGE_TAG ?= dev
MANAGER_IMG ?= kusk-gateway:${IMAGE_TAG}
# ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary.
ENVTEST_K8S_VERSION := 1.22
# 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
LD_FLAGS += -X 'github.com/kubeshop/kusk-gateway/pkg/analytics.TelemetryToken=${TELEMETRY_TOKEN}'
LD_FLAGS += -X 'github.com/kubeshop/kusk-gateway/pkg/build.Version=${VERSION}'
# MBana: Don't strip symbol table and debug info for now.
# # strip DWARF, symbol table and debug info. Expect ~25% binary size decrease
# # https://github.com/kubeshop/kusk-gateway/issues/431
# LD_FLAGS += -s -w
export DOCKER_BUILDKIT ?= 1
.PHONY: all
all: install-deps 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
ifeq ($(shell uname -s),Linux)
DOCS_PREVIEWER := xdg-open
else ifeq ($(shell uname -s),Darwin)
DOCS_PREVIEWER := open
else
$(error unsupported system: $(shell uname -s))
endif
.PHONY: docs-preview
docs-preview: ## Preview the documentation
{ cd docs; npm install; ${DOCS_PREVIEWER} http://localhost:3000; npm start & }; wait
.PHONY: tail-logs
tail-logs: install-deps ## Tail logs of all containers across all namespaces
@type stern >/dev/null 2>&1 || go install github.com/stern/stern@latest
@# Optionally `source <(stern --completion=zsh)` in your `~/.zshrc`.
stern --all-namespaces --selector app.kubernetes.io/name
.PHONY: tail-xds
tail-xds: ## Tail logs of kusk-manager
kubectl logs --follow --namespace kusk-system services/kusk-gateway-manager
.PHONY: tail-envoyfleet
tail-envoyfleet: ## Tail logs of envoy
kubectl logs --follow --namespace kusk-system service/kusk-gateway-envoy-fleet
.PHONY: enable-logging
enable-logging: ## Set some particular logger's level
kubectl port-forward --namespace kusk-system deployments/kusk-gateway-envoy-fleet 19000:19000 & echo $$! > /tmp/kube-port-forward-logging.pid
sleep 2
curl -s -X POST "http://localhost:19000/logging?backtrace=trace" >/dev/null 2>&1
curl -s -X POST "http://localhost:19000/logging?envoy_bug=trace" >/dev/null 2>&1
curl -s -X POST "http://localhost:19000/logging?assert=trace" >/dev/null 2>&1
curl -s -X POST "http://localhost:19000/logging?misc=trace" >/dev/null 2>&1
curl -s -X POST "http://localhost:19000/logging?secret=trace" >/dev/null 2>&1
curl -s -X POST "http://localhost:19000/logging?filter=trace" >/dev/null 2>&1
curl -s -X POST "http://localhost:19000/logging?cache_filter=trace" >/dev/null 2>&1
curl -s -X POST "http://localhost:19000/logging?ext_authz=trace" >/dev/null 2>&1
curl -s -X POST "http://localhost:19000/logging?jwt=trace" >/dev/null 2>&1
curl -s -X POST "http://localhost:19000/logging?oauth2=trace" >/dev/null 2>&1
curl -s -X POST "http://localhost:19000/logging?connection=trace" >/dev/null 2>&1
curl -s -X POST "http://localhost:19000/logging?conn_handler=trace" >/dev/null 2>&1
curl -s -X POST "http://localhost:19000/logging?matcher=trace" >/dev/null 2>&1
curl -s -X POST "http://localhost:19000/logging?router=trace" >/dev/null 2>&1
@# curl -s -X POST "http://localhost:19000/logging?grpc=trace" >/dev/null 2>&1
@# curl -s -X POST "http://localhost:19000/logging?http=trace" >/dev/null 2>&1
@# curl -s -X POST "http://localhost:19000/logging?http2=trace" >/dev/null 2>&1
@# curl -s -X POST "http://localhost:19000/logging?upstream=trace" >/dev/null 2>&1
@# curl -s -X POST "http://localhost:19000/logging?admin=trace" >/dev/null 2>&1
@# bash -c "trap 'pkill -F /tmp/kube-port-forward-logging.pid' SIGINT SIGTERM ERR EXIT"
@echo
@echo "How to stop port forward to the admin port (19000):"
@echo "pkill -F /tmp/kube-port-forward-logging.pid"
@echo
.PHONY: dev-update
dev-update: docker-build update cycle deploy-envoyfleet ## Update cluster with local changes (usually after you have modified the code).
.PHONY: create-env
create-env: ## Spin up a local development cluster with Minikube and install kusk Gateway
./development/cluster/create-env.sh
.PHONY: deploy-envoyfleet
deploy-envoyfleet: ## Deploy k8s resources for the single Envoy Fleet
kubectl apply -f config/samples/gateway_v1_envoyfleet.yaml
.PHONY: delete-env
delete-env: ## Destroy the local development Minikube cluster
minikube delete --profile kgw
.PHONY: manifests
manifests: install-deps ## Generate WebhookConfiguration, ClusterRole and CustomResourceDefinition objects.
controller-gen rbac:roleName=kusk-gateway-manager-role crd webhook paths="./..." output:crd:artifacts:config=config/crd/bases
.PHONY: generate
generate: install-deps ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations.
controller-gen object:headerFile="hack/boilerplate.go.txt" paths="./..."
.PHONY: fmt
fmt: ## Run go fmt against code.
go fmt $(shell go list ./... | grep -v /examples/)
.PHONY: vet
vet: ## Run go vet against code.
go vet $(shell go list ./... | grep -v /examples/)
.PHONY: test
test: manifests fmt vet install-deps ## Run tests.
KUBEBUILDER_ASSETS="$(shell setup-envtest use $(ENVTEST_K8S_VERSION) -p path)" go test $(shell go list ./... | grep -v smoketests | grep -v internal/controllers | grep -v api/v1alpha1) -coverprofile cover.out
.PHONY: testing
testing: ## Run the integration tests from development/testing and then delete testing artifacts if succesfull.
development/testing/runtest.sh all delete
##@ Build
.PHONY: build
build: generate fmt vet ## Build manager binary.
go build -o bin/manager -ldflags="${LD_FLAGS}" cmd/manager/main.go
.PHONY: docker-build
docker-build: ## Build docker image with the manager.
docker build \
--tag ${MANAGER_IMG} \
--tag ttl.sh/kubeshop/kusk-gateway:latest \
--tag ttl.sh/kubeshop/kusk-gateway:$(shell git describe --tags $(shell git rev-list --tags --max-count=1)) \
--tag kusk-gateway:latest \
--tag kubeshop/kusk-gateway:latest \
--tag kubeshop/kusk-gateway:$(shell git describe --tags $(shell git rev-list --tags --max-count=1)) \
--file ./build/manager/Dockerfile \
.
@echo
-minikube image --profile kgw load kubeshop/kusk-gateway:$(shell git describe --tags $(shell git rev-list --tags --max-count=1))
##@ Deployment
ifndef ignore-not-found
ignore-not-found = false
endif
.PHONY: install-local
install-local: manifests install-deps ## Install CRDs and Envoy into the K8s cluster specified in ~/.kube/config.
kustomize build config/local | kubectl apply -f -
kubectl -n kusk-system wait --for condition=established --timeout=60s crd/envoyfleet.gateway.kusk.io
kubectl -n kusk-system apply -f config/samples/gateway_v1_envoyfleet.yaml
.PHONY: uninstall-local
uninstall-local: manifests install-deps ## Uninstall CRDs and Envoy from the K8s cluster specified in ~/.kube/config.
kustomize build config/local | kubectl delete -f -
.PHONY: install
install: manifests install-deps ## Install CRDs into the K8s cluster specified in ~/.kube/config.
kustomize build config/crd | kubectl apply -f -
.PHONY: uninstall
uninstall: manifests install-deps ## 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 -
generate-deployment:
kustomize build config/default > deployment.yaml
.PHONY: deploy
deploy: manifests install-deps ## Deploy controller to the K8s cluster specified in ~/.kube/config.
kustomize build config/default | kubectl apply -f -
.PHONY: undeploy
undeploy: ## Undeploy controller from the K8s cluster specified in ~/.kube/config.
kustomize build config/default | kubectl delete -f -
.PHONY: update
update: docker-build-manager deploy cycle ## Runs deploy, docker build and restarts kusk-gateway-manager deployment to pick up the change
.PHONY: cycle
cycle: ## Triggers kusk-gateway-manager deployment rollout restart to pick up the new container image with the same tag
kubectl rollout restart deployment/kusk-gateway-manager -n kusk-system
@echo "Triggered deployment/kusk-gateway-manager restart, waiting for it to finish"
kubectl rollout status deployment/kusk-gateway-manager -n kusk-system --timeout=60s
.PHONY: cycle-envoy
cycle-envoy: ## Triggers all Envoy pods in the cluster to restart
kubectl rollout restart deployment/kgw-envoy-default -n default
kubectl rollout restart deployment/kgw-envoy-testing -n testing || echo 'rollout restart failed'
.PHONY: $(smoketests)
$(smoketests): install-deps
$(MAKE) -C smoketests $@
check-all: install-deps $(smoketests)
.PHONY: install-deps
install-deps:
@type kustomize >/dev/null 2>&1 || go install sigs.k8s.io/kustomize/kustomize/[email protected]
@type setup-envtest >/dev/null 2>&1 || go install sigs.k8s.io/controller-runtime/tools/[email protected]
@type controller-gen >/dev/null 2>&1 || go install sigs.k8s.io/controller-tools/cmd/[email protected]
@type protoc-gen-go-grpc >/dev/null 2>&1 || echo "[INFO]: Installing protobuf GRPC go generation plugin." && go install google.golang.org/grpc/cmd/[email protected]
@type protoc-gen-go >/dev/null 2>&1 || echo "[INFO]: Installing protobuf go generation plugin." && go install google.golang.org/protobuf/cmd/[email protected]
# `build-goreleaser` is just for local testing.
.PHONY: build-goreleaser
build-goreleaser:
VERSION="${VERSION}" TELEMETRY_TOKEN="${TELEMETRY_TOKEN}" goreleaser release --rm-dist --skip-publish --skip-validate