-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
144 lines (113 loc) · 4.79 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
TEST_COUNT?=1
TEST_PKG?=gtc
K3S_VERSION?=v1.27.3-k3s1
CODE_GENERATOR_VERSION=0.27.3
CONTROLLER_TOOLS_VERSION=0.9.2
LOG_LEVEL?=info
.PHONY: all
all: build
##@ General
.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
.PHONY: test
test: generate gen_protoc fast_test ## Regenerate proto and run tests.
.PHONY: fast_test
fast_test: ## Run tests.
LOG_LEVEL=$(LOG_LEVEL) GRPC_XDS_BOOTSTRAP=$(PWD)/pkg/echoserver/xds-bootstrap.json go test ./$(TEST_PKG) -cover -count=$(TEST_COUNT) -v -run="$(T)"
.PHONY: debug_test
debug_test: generate gen_protoc ## Run tests with delve.
LOG_LEVEL=$(LOG_LEVEL) GRPC_XDS_BOOTSTRAP=$(PWD)/pkg/echoserver/xds-bootstrap.json dlv test ./$(TEST_PKG) -- -test.count=$(TEST_COUNT) -test.v -test.run="$(T)"
.PHONY: ci_test
ci_test: ## Run tests without generation.
GRPC_XDS_BOOTSTRAP=$(PWD)/pkg/echoserver/xds-bootstrap.json go test ./... -cover -count=$(TEST_COUNT) -v
.PHONY: dev
dev: create_cluster deploy install_example
CMD ?= ash
.PHONY: client_shell_0
client_shell_0:
kubectl exec -n echo-client -ti $(shell kubectl -n echo-client get pods -o jsonpath="{.items[0].metadata.name}") -- $(CMD)
.PHONY: client_shell_1
client_shell_1:
kubectl exec -n echo-client -ti $(shell kubectl -n echo-client get pods -o jsonpath="{.items[1].metadata.name}") -- $(CMD)
.PHONY: install_example
install_example: gen_protoc ## install an example in the current cluster
KO_DOCKER_REPO=gtc-registry.localhost:5000 ko apply -f ./example/k8s/echo-server
KO_DOCKER_REPO=gtc-registry.localhost:5000 ko apply -f ./example/k8s/echo-client
.PHONY: create_cluster
create_cluster: ## run a local k3d cluster
k3d cluster create \
--image="rancher/k3s:$(K3S_VERSION)" \
--agents=2\
--k3s-node-label="topology.kubernetes.io/region=local@server:0" \
--k3s-node-label="topology.kubernetes.io/zone=zone-a@server:0" \
--k3s-node-label="failure-domain.beta.kubernetes.io/zone=zone-a@server:0" \
--k3s-node-label="topology.kubernetes.io/region=local@agent:0" \
--k3s-node-label="topology.kubernetes.io/zone=zone-b@agent:0" \
--k3s-node-label="failure-domain.beta.kubernetes.io/zone=zone-b@agent:0" \
--k3s-node-label="topology.kubernetes.io/region=local@agent:1" \
--k3s-node-label="topology.kubernetes.io/zone=zone-c@agent:1" \
--k3s-node-label="failure-domain.beta.kubernetes.io/zone=zone-c@agent:1" \
--registry-create=gtc-registry.localhost:0.0.0.0:5000 \
gtc-dev
.PHONY: delete_cluster
delete_cluster: ## Delete the dev cluster
k3d cluster delete gtc-dev
.PHONY: deploy_crds
deploy_crds: ## Deploy the kudo CRDs in dev cluster
kubectl apply -f ./helm/crds
.PHONY: deploy
deploy: generate deploy_crds
helm template \
--values helm/values.yaml \
--set image.devRef=ko://github.com/jlevesy/grpc-traffic-controller/cmd/controller \
--set logLevel=$(LOG_LEVEL) \
gtc-dev ./helm | KO_DOCKER_REPO=gtc-registry.localhost:5000 ko apply -B -t dev -f -
##@ Docs
.PHONY: serve_docs
serve_docs:
hugo serve --source=./docs
.PHONY: lint_docs
lint_docs:
typos ./docs
##@ Build
.PHONY: build
build: generate ## Build controller binary.
go build -o bin/controller ./cmd/controller
## Location to install dependencies to
LOCALBIN ?= $(shell pwd)/bin
$(LOCALBIN):
mkdir -p $(LOCALBIN)
.PHONY: generate
generate: gen_protoc codegen gen_manifests
.PHONY: gen_protoc
gen_protoc: ## Generate protoc code for the echo server.
protoc \
--go_out=. \
--go_opt=paths=source_relative \
--go-grpc_out=. \
--go-grpc_opt=paths=source_relative \
pkg/echoserver/proto/echo.proto
.PHONY: codegen
codegen: ## Run code generation for CRDs
@bash ${GOPATH}/pkg/mod/k8s.io/code-generator@v$(CODE_GENERATOR_VERSION)/generate-groups.sh \
all \
github.com/jlevesy/grpc-traffic-controller/client \
github.com/jlevesy/grpc-traffic-controller/api \
gtc:v1alpha1 \
--go-header-file ./hack/boilerplate.go.txt
.PHONY: gen_manifests
gen_manifests: ## Generate WebhookConfiguration, ClusterRole and CustomResourceDefinition objects.
$(LOCALBIN)/controller-gen \
rbac:roleName='PLACEHOLDER' \
crd webhook \
paths="./..." \
output:rbac:artifacts:config=helm/templates output:crd:artifacts:config=helm/crds/
sed -i 's/PLACEHOLDER/\{\{ include \"helm.fullname\" \. \}\}-controller/g' helm/templates/role.yaml
.PHONY: install_code_generator
install_code_generator: ## Install code generator
go install k8s.io/code-generator/cmd/...@v$(CODE_GENERATOR_VERSION)
.PHONY: install_controller_tools
install_controller_tools: $(LOCALBIN) ## Install controller-tools
test -s $(LOCALBIN)/controller-gen || GOBIN=$(LOCALBIN) go install sigs.k8s.io/controller-tools/cmd/controller-gen@v$(CONTROLLER_TOOLS_VERSION)