-
Notifications
You must be signed in to change notification settings - Fork 6
/
Makefile
265 lines (228 loc) · 12.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
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
# Image URL to use all building/pushing image targets
VERSION ?= v0.1.0
# 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
# 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
.PHONY: all
all: build test
##@ 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)
.PHONY: manifests
manifests: controller-gen-tool ## Generate WebhookConfiguration, ClusterRole and CustomResourceDefinition objects.
$(CONTROLLER_GEN) rbac:roleName=manager-role crd webhook paths="./pkg/apis/..." output:crd:artifacts:config=config/crd/bases
## Generate code for resources
.PHONY: generate
generate: controller-gen openapi-gen protobuf-gen
## Generate code for rest api resource model, containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations.
.PHONY: controller-gen
controller-gen: code-gen-tool
$(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./pkg/apis/core/..."
## Generate openapi spec for api resource model
PROTOC_GEN_GOGO = $(shell pwd)/bin/protoc-gen-gogo
.PHONY: protobuf-gen
protobuf-gen: code-gen-tool
$(call go-get-tool,$(PROTOC_GEN_GOGO),github.com/gogo/protobuf/[email protected])
# $(GO_TO_PROTOBUF) --go-header-file="./hack/boilerplate.go.txt" --packages="centaurusinfra.io/fornax-serverless/pkg/apis/core/v1" --output-base="protobuf" --proto-import="./vendor" --vendor-output-base="./vendor" --only-idl
$(GO_TO_PROTOBUF) --go-header-file="./hack/boilerplate.go.txt" \
--packages="centaurusinfra.io/fornax-serverless/pkg/apis/core/v1" \
--proto-import="./vendor" --vendor-output-base="./vendor" \
--apimachinery-packages="+k8s.io/apimachinery/pkg/util/intstr,+k8s.io/apimachinery/pkg/api/resource,+k8s.io/apimachinery/pkg/runtime/schema,+k8s.io/apimachinery/pkg/runtime,k8s.io/apimachinery/pkg/apis/meta/v1,k8s.io/apimachinery/pkg/apis/meta/v1beta1,k8s.io/apimachinery/pkg/apis/testapigroup/v1,k8s.io/api/core/v1"
## Generate openapi spec for api resource model
.PHONY: openapi-gen
openapi-gen: code-gen-tool
$(OPENAPI_GEN) --go-header-file="hack/boilerplate.go.txt" --input-dirs="./pkg/apis/core/..." --output-package="centaurusinfra.io/fornax-serverless/pkg/apis/openapi"
## Generate client-go sdk containing clientset, lister, and informer method implementations.
GENERATE_GROUPS = $(shell pwd)/hack/generate-groups.sh
.PHONY: client-gen
client-gen: code-gen-tool
$(GENERATE_GROUPS) "client, lister, informer" centaurusinfra.io/fornax-serverless/pkg/client "centaurusinfra.io/fornax-serverless/pkg/apis" "core:v1" --go-header-file hack/boilerplate.go.txt
.PHONY: fmt
fmt: ## Run go fmt against code.
go fmt ./...
.PHONY: vet
vet: ## Run go vet against code.
go vet ./...
.PHONY: test
test: fmt vet envtest ## Run tests.
go test ./... -coverprofile cover.out
##@ Build
LDFLAGS=-w -s
.PHONY: build
build: fmt vet ## Build binary.
go build ./...
go build -ldflags "$(LDFLAGS)" -o bin/integtestgrpcserver cmd/integtestgrpcserver/main.go
go build -ldflags "$(LDFLAGS)" -o bin/fornaxcore cmd/fornaxcore/main.go
go build -ldflags "$(LDFLAGS)" -o bin/nodeagent cmd/nodeagent/main.go
go build -ldflags "$(LDFLAGS)" -o bin/simulatenode cmd/simulation/node/main.go
go build -ldflags "$(LDFLAGS)" -o bin/fornaxtest cmd/fornaxtest/main.go
APISERVER-BOOT = $(shell pwd)/bin/apiserver-boot
.PHONY: debug-fornaxcore-local
debug-fornaxcore-local: build ## Download apiserver-boot cmd locally if necessary.
# $(call go-get-tool,$(APISERVER-BOOT),sigs.k8s.io/apiserver-builder-alpha/cmd/[email protected])
# $(APISERVER-BOOT) run local --run etcd,fornaxcore
@ulimit -n 8192
@nohup bin/fornaxcore --etcd-servers=http://127.0.0.1:2379 --secure-port=9443 --standalone-debug-mode --bind-address=127.0.0.1 --feature-gates=APIPriorityAndFairness=false > fornax-core.log 2
.PHONY: run
run: generate fmt vet ## Run from your host.
.PHONY: run-nodeagent-local
@sudo ./bin/nodeagent --fornaxcore-ip localhost:18001 --disable-swap=false
APISERVER-BOOT = $(shell pwd)/bin/apiserver-boot
.PHONY: run-fornaxcore-local
run-fornaxcore-local: ## Download apiserver-boot cmd locally if necessary.
# export KUBERNETES_SERVICE_HOST=192.168.0.45
# export KUBERNETES_SERVICE_PORT=9443
# export KUBERNETES_MASTER=192.168.0.45
# @nohup bin/fornaxcore --etcd-servers=http://127.0.0.1:2379 --secure-port=9443 --kubeconfig ./kubeconfig.server --authentication-kubeconfig ./kubeconfig.server --requestheader-client-ca-file /var/lib/fornaxcore/certs/fornax-client.crt --tls-cert-file /var/lib/fornaxcore/certs/fornaxcore-server.crt --tls-private-key-file /var/lib/fornaxcore/certs/fornaxcore-server.key --client-ca-file /var/lib/fornaxcore/certs/fornaxcore.crt > fornax-core.log 2
@nohup bin/fornaxcore --etcd-servers=http://127.0.0.1:2379 --secure-port=9443 --standalone-debug-mode --bind-address=127.0.0.1 --feature-gates=APIPriorityAndFairness=false > fornax-core.log 2
.PHONY: docker-build
docker-build: test ## Build docker image
@sudo docker build -f ./dockerimages/Dockerfile.echoserver -t centaurusinfra.io/fornax-serverless/echoserver:${VERSION} .
@sudo docker build -f ./dockerimages/Dockerfile.sessionwrapper -t centaurusinfra.io/fornax-serverless/session-wrapper:${VERSION} .
@sudo docker build -f ./dockerimages/nodejs-hw/Dockerfile.nodejs-hw -t centaurusinfra.io/fornax-serverless/nodejs-hw:${VERSION} .
.PHONY: docker-push
docker-push: ## Push docker image into docker hub registry
@sudo docker push centaurusinfra.io/fornax-serverless/echoserver:${VERSION}
@sudo docker push centaurusinfra.io/fornax-serverless/session-wrapper:${VERSION}
@sudo docker push centaurusinfra.io/fornax-serverless/nodejs-hw:${VERSION}
## Push docker image into a local containerd for test
.PHONY: containerd-local-push
containerd-local-push: containerd-local-push-session-wrapper containerd-local-push-echoserver containerd-local-push-nodejs-hw
.PHONY: containerd-local-push-session-wrapper
containerd-local-push-session-wrapper:
@sudo docker image save -o /tmp/centaurusinfra.io.fornax-serverless.session-wrapper.img centaurusinfra.io/fornax-serverless/session-wrapper:${VERSION}
@sudo crictl rmi centaurusinfra.io/fornax-serverless/session-wrapper:${VERSION}
@sudo ctr -n=k8s.io image import /tmp/centaurusinfra.io.fornax-serverless.session-wrapper.img
.PHONY: containerd-local-push-echoserver
containerd-local-push-echoserver:
@sudo docker image save -o /tmp/centaurusinfra.io.fornax-serverless.echoserver.img centaurusinfra.io/fornax-serverless/echoserver:${VERSION}
@sudo crictl rmi centaurusinfra.io/fornax-serverless/echoserver:${VERSION}
@sudo ctr -n=k8s.io image import /tmp/centaurusinfra.io.fornax-serverless.echoserver.img
.PHONY: containerd-local-push-nodejs-hw
containerd-local-push-nodejs-hw:
@sudo docker image save -o /tmp/centaurusinfra.io.fornax-serverless.nodejs-hw.img centaurusinfra.io/fornax-serverless/nodejs-hw:${VERSION}
@sudo crictl rmi centaurusinfra.io/fornax-serverless/nodejs-hw:${VERSION}
@sudo ctr -n=k8s.io image import /tmp/centaurusinfra.io.fornax-serverless.nodejs-hw.img
.PHONY: check
check:
@hostname
@cat /etc/os-release
@pwd
@lscpu | grep CPU\(s\)
@free -m
make --version
@echo "check is done"
.PHONY: clean
clean:
@rm -f cover.out
@rm -f bin/fornaxcore
@rm -f bin/nodeagent
@rm -f bin/simulatenode
@rm -f bin/integtestgrpcserver
@rm -f bin/fornaxtest
.PHONY: install
install: install-certs ## Install CRDs into the K8s cluster specified in ~/.kube/config.
.PHONY: install-certs
install-certs:
@sudo mkdir -p /var/lib/fornaxcore/certs/
@sudo openssl genrsa -out /tmp/ca.key 2048
@sudo openssl req -x509 -new -nodes -key /tmp/ca.key -subj "/CN=192.168.0.45" -days 10000 -out /tmp/ca.crt
@sudo openssl genrsa -out /tmp/server.key 2048
@sudo openssl req -new -key /tmp/server.key -out /tmp/server.csr -config ./config/csr.conf
@sudo openssl x509 -req -in /tmp/server.csr -CA /tmp/ca.crt -CAkey /tmp/ca.key \
-CAcreateserial -out /tmp/server.crt -days 10000 \
-extensions v3_ext -extfile ./config/csr.conf
# @sudo openssl req -noout -text -in /tmp/server.csr
@sudo mv /tmp/ca.key /var/lib/fornaxcore/certs/fornaxcore.key
@sudo mv /tmp/ca.crt /var/lib/fornaxcore/certs/fornaxcore.crt
@sudo mv /tmp/server.key /var/lib/fornaxcore/certs/fornaxcore-server.key
@sudo mv /tmp/server.crt /var/lib/fornaxcore/certs/fornaxcore-server.crt
.PHONY: uninstall
uninstall: ## Uninstall CRDs from the K8s cluster specified in ~/.kube/config. Call with ignore-not-found=true to ignore resource not found errors during deletion.
CONTROLLER_GEN = $(shell pwd)/bin/controller-gen
OPENAPI_GEN = $(shell pwd)/bin/openapi-gen
CLIENT_GEN = $(shell pwd)/bin/client-gen ## use it to generate clientset
LISTER_GEN = $(shell pwd)/bin/lister-gen ## use it to generate lister watch
INFORMER_GEN = $(shell pwd)/bin/informer-gen ## use it to generate informer info
GO_TO_PROTOBUF = $(shell pwd)/bin/go-to-protobuf
.PHONY: code-gen-tool
code-gen-tool: ## Download client-genl, lister-gen and informer-gen locally if necessary.
$(call go-get-tool,$(CONTROLLER_GEN),sigs.k8s.io/controller-tools/cmd/[email protected])
$(call go-get-tool,$(CLIENT_GEN),k8s.io/code-generator/cmd/[email protected])
$(call go-get-tool,$(LISTER_GEN),k8s.io/code-generator/cmd/[email protected])
$(call go-get-tool,$(INFORMER_GEN),k8s.io/code-generator/cmd/[email protected])
$(call go-get-tool,$(GO_TO_PROTOBUF),k8s.io/code-generator/cmd/[email protected])
$(call go-get-tool,$(OPENAPI_GEN),k8s.io/kube-openapi/cmd/[email protected])
# generate fornaxcore grpc code
PROTOC_GEN_GO = $(shell pwd)/bin/protoc-gen-go
PROTOC_GEN_GO_GRPC = $(shell pwd)/bin/protoc-gen-go-grpc
PROTOC = $(HOME)/.local/bin/protoc
.PHONY: protoc-gen
protoc-gen: ## Download protc-gen locally if necessary.
$(call go-get-tool,$(PROTOC_GEN_GO),google.golang.org/protobuf/cmd/[email protected])
$(call go-get-tool,$(PROTOC_GEN_GO_GRPC),google.golang.org/grpc/cmd/[email protected])
$(call get-protoc,$(PROTOC))
go mod vendor
$(PROTOC) -I=./ -I=./vendor \
--go_out=../.. \
--go-grpc_out=../../ \
--go_opt=Mk8s.io/api/core/v1/generated.proto=k8s.io/api/core/v1 \
--go_opt=Mk8s.io/apimachinery/pkg/api/resource/generated.proto=k8s.io/apimachinery/pkg/api/resource \
--go_opt=Mk8s.io/apimachinery/pkg/apis/meta/v1/generated.proto=k8s.io/apimachinery/pkg/apis/meta/v1 \
--go_opt=Mk8s.io/apimachinery/pkg/runtime/generated.proto=k8s.io/apimachinery/pkg/runtime \
--go_opt=Mk8s.io/apimachinery/pkg/runtime/schema/generated.proto=k8s.io/apimachinery/pkg/runtime/schema \
--go_opt=Mk8s.io/apimachinery/pkg/util/intstr/generated.proto=k8s.io/apimachinery/pkg/util/intstr \
--go_opt=Mpkg/apis/core/v1/generated.proto=centaurusinfra.io/fornax-serverless/pkg/apis/core/v1 \
pkg/fornaxcore/grpc/fornaxcore.proto
$(PROTOC) -I=./ -I=./vendor \
--go_out=../.. \
--go-grpc_out=../../ \
pkg/nodeagent/sessionservice/grpc/session_service.proto
ENVTEST = $(shell pwd)/bin/setup-envtest
.PHONY: envtest
envtest: ## Download envtest-setup locally if necessary.
$(call go-get-tool,$(ENVTEST),sigs.k8s.io/controller-runtime/tools/setup-envtest@latest)
# 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 install $(2) ;\
rm -rf $$TMP_DIR ;\
}
endef
define get-protoc
@[ -f $(1) ] || { \
set -e ;\
TMP_DIR=$$(mktemp -d) ;\
cd $$TMP_DIR ;\
PB_REL="https://github.com/protocolbuffers/protobuf/releases" ;\
curl -LO $$PB_REL/download/v3.12.1/protoc-3.12.1-linux-x86_64.zip ;\
echo "get protoc" ;\
unzip $$TMP_DIR/protoc-3.12.1-linux-x86_64.zip -d $$HOME/.local ;\
rm -rf $$TMP_DIR ;\
}
endef