This repository has been archived by the owner on Oct 23, 2024. It is now read-only.
forked from kserve/kserve
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
292 lines (234 loc) · 14 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
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
HAS_LINT := $(shell command -v golint;)
# Image URL to use all building/pushing image targets
IMG ?= kserve-controller:latest
AGENT_IMG ?= agent:latest
ROUTER_IMG ?= router:latest
SKLEARN_IMG ?= sklearnserver
XGB_IMG ?= xgbserver
LGB_IMG ?= lgbserver
PYTORCH_IMG ?= pytorchserver
PMML_IMG ?= pmmlserver
PADDLE_IMG ?= paddleserver
ALIBI_IMG ?= alibi-explainer
AIX_IMG ?= aix-explainer
STORAGE_INIT_IMG ?= storage-initializer
CRD_OPTIONS ?= "crd:maxDescLen=0"
KSERVE_ENABLE_SELF_SIGNED_CA ?= false
# ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary.
ENVTEST_K8S_VERSION = 1.22
# CPU/Memory limits for controller-manager
KSERVE_CONTROLLER_CPU_LIMIT ?= 100m
KSERVE_CONTROLLER_MEMORY_LIMIT ?= 300Mi
$(shell perl -pi -e 's/cpu:.*/cpu: $(KSERVE_CONTROLLER_CPU_LIMIT)/' config/default/manager_resources_patch.yaml)
$(shell perl -pi -e 's/memory:.*/memory: $(KSERVE_CONTROLLER_MEMORY_LIMIT)/' config/default/manager_resources_patch.yaml)
all: test manager agent router
# Run tests
test: fmt vet manifests envtest
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) -p path)" go test $$(go list ./pkg/...) ./cmd/... -coverprofile coverage.out
# Build manager binary
manager: generate fmt vet lint
go build -o bin/manager ./cmd/manager
# Build agent binary
agent: fmt vet
go build -o bin/agent ./cmd/agent
# Build router binary
router: fmt vet
go build -o bin/router ./cmd/router
# Run against the configured Kubernetes cluster in ~/.kube/config
run: generate fmt vet lint
go run ./cmd/manager/main.go
# Deploy controller in the configured Kubernetes cluster in ~/.kube/config
deploy: manifests
# Remove the certmanager certificate if KSERVE_ENABLE_SELF_SIGNED_CA is not false
cd config/default && if [ ${KSERVE_ENABLE_SELF_SIGNED_CA} != false ]; then \
kustomize edit remove resource certmanager/certificate.yaml; \
else kustomize edit add resource certmanager/certificate.yaml; fi;
kustomize build config/default | kubectl apply -f -
if [ ${KSERVE_ENABLE_SELF_SIGNED_CA} != false ]; then ./hack/self-signed-ca.sh; fi;
deploy-dev: manifests
./hack/image_patch_dev.sh development
# Remove the certmanager certificate if KSERVE_ENABLE_SELF_SIGNED_CA is not false
cd config/default && if [ ${KSERVE_ENABLE_SELF_SIGNED_CA} != false ]; then \
kustomize edit remove resource certmanager/certificate.yaml; \
else kustomize edit add resource certmanager/certificate.yaml; fi;
kustomize build config/overlays/development | kubectl apply -f -
# TODO: Add runtimes as part of default deployment
kubectl wait --for=condition=ready pod -l control-plane=kserve-controller-manager -n kserve --timeout=300s
kustomize build config/runtimes | kubectl apply -f -
if [ ${KSERVE_ENABLE_SELF_SIGNED_CA} != false ]; then ./hack/self-signed-ca.sh; fi;
deploy-dev-sklearn: docker-push-sklearn
./hack/model_server_patch_dev.sh sklearn ${KO_DOCKER_REPO}/${SKLEARN_IMG}
kustomize build config/overlays/dev-image-config | kubectl apply -f -
deploy-dev-xgb: docker-push-xgb
./hack/model_server_patch_dev.sh xgboost ${KO_DOCKER_REPO}/${XGB_IMG}
kustomize build config/overlays/dev-image-config | kubectl apply -f -
deploy-dev-lgb: docker-push-lgb
./hack/model_server_patch_dev.sh lightgbm ${KO_DOCKER_REPO}/${LGB_IMG}
kustomize build config/overlays/dev-image-config | kubectl apply -f -
deploy-dev-pytorch: docker-push-pytorch
./hack/model_server_patch_dev.sh pytorch ${KO_DOCKER_REPO}/${PYTORCH_IMG}
kustomize build config/overlays/dev-image-config | kubectl apply -f -
deploy-dev-pmml : docker-push-pmml
./hack/model_server_patch_dev.sh sklearn ${KO_DOCKER_REPO}/${PMML_IMG}
kustomize build config/overlays/dev-image-config | kubectl apply -f -
deploy-dev-paddle: docker-push-paddle
./hack/model_server_patch_dev.sh paddle ${KO_DOCKER_REPO}/${PADDLE_IMG}
kustomize build config/overlays/dev-image-config | kubectl apply -f -
deploy-dev-alibi: docker-push-alibi
./hack/alibi_patch_dev.sh ${KO_DOCKER_REPO}/${ALIBI_IMG}
kustomize build config/overlays/dev-image-config | kubectl apply -f -
deploy-dev-aix: docker-push-aix
./hack/aix_patch_dev.sh ${KO_DOCKER_REPO}/${AIX_IMG}
kustomize build config/overlays/dev-image-config | kubectl apply -f -
deploy-dev-storageInitializer: docker-push-storageInitializer
./hack/storageInitializer_patch_dev.sh ${KO_DOCKER_REPO}/${STORAGE_INIT_IMG}
kustomize build config/overlays/dev-image-config | kubectl apply -f -
deploy-ci: manifests
kustomize build config/overlays/test | kubectl apply -f -
# TODO: Add runtimes as part of default deployment
kubectl wait --for=condition=ready pod -l control-plane=kserve-controller-manager -n kserve --timeout=300s
kustomize build config/overlays/test/runtimes | kubectl apply -f -
undeploy:
kustomize build config/default | kubectl delete -f -
kubectl delete validatingwebhookconfigurations.admissionregistration.k8s.io inferenceservice.serving.kserve.io
kubectl delete validatingwebhookconfigurations.admissionregistration.k8s.io trainedmodel.serving.kserve.io
kubectl delete validatingwebhookconfigurations.admissionregistration.k8s.io inferencegraph.serving.kserve.io
kubectl delete mutatingwebhookconfigurations.admissionregistration.k8s.io inferenceservice.serving.kserve.io
undeploy-dev:
kustomize build config/overlays/development | kubectl delete -f -
kubectl delete validatingwebhookconfigurations.admissionregistration.k8s.io inferenceservice.serving.kserve.io
kubectl delete validatingwebhookconfigurations.admissionregistration.k8s.io trainedmodel.serving.kserve.io
kubectl delete validatingwebhookconfigurations.admissionregistration.k8s.io inferencegraph.serving.kserve.io
kubectl delete mutatingwebhookconfigurations.admissionregistration.k8s.io inferenceservice.serving.kserve.io
# Generate manifests e.g. CRD, RBAC etc.
manifests: controller-gen
$(CONTROLLER_GEN) $(CRD_OPTIONS) paths=./pkg/apis/serving/... output:crd:dir=config/crd
$(CONTROLLER_GEN) rbac:roleName=kserve-manager-role paths=./pkg/controller/... output:rbac:artifacts:config=config/rbac
$(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths=./pkg/apis/serving/v1alpha1
$(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths=./pkg/apis/serving/v1beta1
#TODO Remove this until new controller-tools is released
perl -pi -e 's/storedVersions: null/storedVersions: []/g' config/crd/serving.kserve.io_inferenceservices.yaml
perl -pi -e 's/conditions: null/conditions: []/g' config/crd/serving.kserve.io_inferenceservices.yaml
perl -pi -e 's/Any/string/g' config/crd/serving.kserve.io_inferenceservices.yaml
perl -pi -e 's/storedVersions: null/storedVersions: []/g' config/crd/serving.kserve.io_trainedmodels.yaml
perl -pi -e 's/conditions: null/conditions: []/g' config/crd/serving.kserve.io_trainedmodels.yaml
perl -pi -e 's/Any/string/g' config/crd/serving.kserve.io_trainedmodels.yaml
perl -pi -e 's/storedVersions: null/storedVersions: []/g' config/crd/serving.kserve.io_inferencegraphs.yaml
perl -pi -e 's/conditions: null/conditions: []/g' config/crd/serving.kserve.io_inferencegraphs.yaml
perl -pi -e 's/Any/string/g' config/crd/serving.kserve.io_inferencegraphs.yaml
#remove the required property on framework as name field needs to be optional
yq d -i config/crd/serving.kserve.io_inferenceservices.yaml 'spec.versions[0].schema.openAPIV3Schema.properties.spec.properties.*.properties.*.required'
#remove ephemeralContainers properties for compress crd size https://github.com/kubeflow/kfserving/pull/1141#issuecomment-714170602
yq d -i config/crd/serving.kserve.io_inferenceservices.yaml 'spec.versions[0].schema.openAPIV3Schema.properties.spec.properties.*.properties.ephemeralContainers'
yq d -i config/crd/serving.kserve.io_inferenceservices.yaml 'spec.versions[0].schema.openAPIV3Schema.properties.spec.properties.*.properties.initContainers'
#knative does not allow setting port on liveness or readiness probe
yq d -i config/crd/serving.kserve.io_inferenceservices.yaml 'spec.versions[0].schema.openAPIV3Schema.properties.spec.properties.*.properties.*.properties.readinessProbe.properties.httpGet.required'
yq d -i config/crd/serving.kserve.io_inferenceservices.yaml 'spec.versions[0].schema.openAPIV3Schema.properties.spec.properties.*.properties.*.properties.livenessProbe.properties.httpGet.required'
yq d -i config/crd/serving.kserve.io_inferenceservices.yaml 'spec.versions[0].schema.openAPIV3Schema.properties.spec.properties.*.properties.*.properties.readinessProbe.properties.tcpSocket.required'
yq d -i config/crd/serving.kserve.io_inferenceservices.yaml 'spec.versions[0].schema.openAPIV3Schema.properties.spec.properties.*.properties.*.properties.livenessProbe.properties.tcpSocket.required'
yq d -i config/crd/serving.kserve.io_inferenceservices.yaml 'spec.versions[0].schema.openAPIV3Schema.properties.spec.properties.*.properties.containers.items.properties.livenessProbe.properties.httpGet.required'
yq d -i config/crd/serving.kserve.io_inferenceservices.yaml 'spec.versions[0].schema.openAPIV3Schema.properties.spec.properties.*.properties.containers.items.properties.readinessProbe.properties.httpGet.required'
#With v1 and newer kubernetes protocol requires default
yq read config/crd/serving.kserve.io_inferenceservices.yaml spec.versions[0].schema.openAPIV3Schema.properties.spec.properties.**.protocol -p p | awk '{print $$0".default"}' | xargs -n1 -I{} yq w -i config/crd/serving.kserve.io_inferenceservices.yaml {} TCP
yq read config/crd/serving.kserve.io_clusterservingruntimes.yaml spec.versions[0].schema.openAPIV3Schema.properties.spec.properties.**.protocol -p p | awk '{print $$0".default"}' | xargs -n1 -I{} yq w -i config/crd/serving.kserve.io_clusterservingruntimes.yaml {} TCP
yq read config/crd/serving.kserve.io_servingruntimes.yaml spec.versions[0].schema.openAPIV3Schema.properties.spec.properties.**.protocol -p p | awk '{print $$0".default"}' | xargs -n1 -I{} yq w -i config/crd/serving.kserve.io_servingruntimes.yaml {} TCP
kustomize build config/crd > test/crds/serving.kserve.io_inferenceservices.yaml
# Run go fmt against code
fmt:
go fmt ./pkg/... ./cmd/...
# Run go vet against code
vet:
go vet ./pkg/... ./cmd/...
lint:
ifndef HAS_LINT
go get -u golang.org/x/lint/golint
echo "installing golint"
endif
hack/verify-golint.sh
# Generate code
generate: controller-gen
go env -w GOFLAGS=-mod=mod
$(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths=./pkg/apis/serving/v1alpha1
$(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths=./pkg/apis/serving/v1beta1
#TODO update-codegen.sh is not used and requires vendor
#hack/update-codegen.sh
hack/update-openapigen.sh
# Build the docker image
docker-build: test
docker build . -t ${IMG}
@echo "updating kustomize image patch file for manager resource"
# Use perl instead of sed to avoid OSX/Linux compatibility issue:
# https://stackoverflow.com/questions/34533893/sed-command-creating-unwanted-duplicates-of-file-with-e-extension
perl -pi -e 's@image: .*@image: '"${IMG}"'@' ./config/default/manager_image_patch.yaml
# Push the docker image
docker-push:
docker push ${IMG}
docker-build-agent:
docker build -f agent.Dockerfile . -t ${KO_DOCKER_REPO}/${AGENT_IMG}
docker-build-router:
docker build -f router.Dockerfile . -t ${KO_DOCKER_REPO}/${ROUTER_IMG}
docker-push-agent:
docker push ${KO_DOCKER_REPO}/${AGENT_IMG}
docker-push-router:
docker push ${KO_DOCKER_REPO}/${ROUTER_IMG}
docker-build-sklearn:
cd python && docker build -t ${KO_DOCKER_REPO}/${SKLEARN_IMG} -f sklearn.Dockerfile .
docker-push-sklearn: docker-build-sklearn
docker push ${KO_DOCKER_REPO}/${SKLEARN_IMG}
docker-build-xgb:
cd python && docker build -t ${KO_DOCKER_REPO}/${XGB_IMG} -f xgb.Dockerfile .
docker-push-xgb: docker-build-xgb
docker push ${KO_DOCKER_REPO}/${XGB_IMG}
docker-build-lgb:
cd python && docker build -t ${KO_DOCKER_REPO}/${LGB_IMG} -f lgb.Dockerfile .
docker-push-lgb: docker-build-lgb
docker push ${KO_DOCKER_REPO}/${LGB_IMG}
docker-build-pytorch:
cd python && docker build -t ${KO_DOCKER_REPO}/${PYTORCH_IMG} -f pytorch.Dockerfile .
docker-push-pytorch: docker-build-pytorch
docker push ${KO_DOCKER_REPO}/${PYTORCH_IMG}
docker-build-pmml:
cd python && docker build -t ${KO_DOCKER_REPO}/${PMML_IMG} -f pmml.Dockerfile .
docker-push-pmml: docker-build-pmml
docker push ${KO_DOCKER_REPO}/${PMML_IMG}
docker-build-paddle:
cd python && docker build -t ${KO_DOCKER_REPO}/${PADDLE_IMG} -f paddle.Dockerfile .
docker-push-paddle: docker-build-paddle
docker push ${KO_DOCKER_REPO}/${PADDLE_IMG}
docker-build-alibi:
cd python && docker build -t ${KO_DOCKER_REPO}/${ALIBI_IMG} -f alibiexplainer.Dockerfile .
docker-push-alibi: docker-build-alibi
docker push ${KO_DOCKER_REPO}/${ALIBI_IMG}
docker-build-aix:
cd python && docker build -t ${KO_DOCKER_REPO}/${AIX_IMG} -f aixexplainer.Dockerfile .
docker-push-aix: docker-build-aix
docker push ${KO_DOCKER_REPO}/${AIX_IMG}
docker-build-storageInitializer:
cd python && docker build -t ${KO_DOCKER_REPO}/${STORAGE_INIT_IMG} -f storage-initializer.Dockerfile .
docker-push-storageInitializer: docker-build-storageInitializer
docker push ${KO_DOCKER_REPO}/${STORAGE_INIT_IMG}
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])
ENVTEST = $(shell pwd)/bin/setup-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 get $(2) ;\
rm -rf $$TMP_DIR ;\
}
endef
apidocs:
docker build -f docs/apis/Dockerfile --rm -t apidocs-gen . && \
docker run -it --rm -v $(CURDIR)/pkg/apis:/go/src/github.com/kserve/kserve/pkg/apis -v ${PWD}/docs/apis:/go/gen-crd-api-reference-docs/apidocs apidocs-gen