/
serving.go
668 lines (619 loc) · 21.1 KB
/
serving.go
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
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
// Copyright 2018 The Kubeflow Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License
package argsbuilder
import (
"context"
"fmt"
"os"
"path"
"path/filepath"
"reflect"
"regexp"
"strings"
"time"
"k8s.io/apimachinery/pkg/api/resource"
"github.com/kubeflow/arena/pkg/apis/config"
"github.com/kubeflow/arena/pkg/apis/types"
"github.com/kubeflow/arena/pkg/util"
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
type ServingArgsBuilder struct {
args *types.CommonServingArgs
argValues map[string]interface{}
subBuilders map[string]ArgsBuilder
}
func NewServingArgsBuilder(args *types.CommonServingArgs) ArgsBuilder {
s := &ServingArgsBuilder{
args: args,
argValues: map[string]interface{}{},
subBuilders: map[string]ArgsBuilder{},
}
return s
}
func (s *ServingArgsBuilder) GetName() string {
items := strings.Split(fmt.Sprintf("%v", reflect.TypeOf(*s)), ".")
return items[len(items)-1]
}
func (s *ServingArgsBuilder) AddSubBuilder(builders ...ArgsBuilder) ArgsBuilder {
for _, b := range builders {
s.subBuilders[b.GetName()] = b
}
return s
}
func (s *ServingArgsBuilder) AddArgValue(key string, value interface{}) ArgsBuilder {
for name := range s.subBuilders {
s.subBuilders[name].AddArgValue(key, value)
}
s.argValues[key] = value
return s
}
func (s *ServingArgsBuilder) AddCommandFlags(command *cobra.Command) {
for name := range s.subBuilders {
s.subBuilders[name].AddCommandFlags(command)
}
var (
envs []string
dataset []string
datadir []string
dataSubpathExpr []string
tempDir []string
tempDirSubpathExpr []string
annotations []string
tolerations []string
labels []string
selectors []string
configFiles []string
imagePullSecrets []string
)
defaultImage := ""
item, ok := s.argValues["default-image"]
if ok {
defaultImage = item.(string)
}
command.Flags().StringVar(&s.args.Image, "image", defaultImage, "the docker image name of serving job")
command.Flags().StringVar(&s.args.ImagePullPolicy, "imagePullPolicy", "IfNotPresent", "the policy to pull the image, and the default policy is IfNotPresent")
_ = command.Flags().MarkDeprecated("imagePullPolicy", "please use --image-pull-policy instead")
command.Flags().StringVar(&s.args.ImagePullPolicy, "image-pull-policy", "IfNotPresent", "the policy to pull the image, and the default policy is IfNotPresent")
command.Flags().IntVar(&s.args.GPUCount, "gpus", 0, "the limit GPU count of each replica to run the serve.")
command.Flags().IntVar(&s.args.GPUMemory, "gpumemory", 0, "the limit GPU memory of each replica to run the serve.")
command.Flags().IntVar(&s.args.GPUCore, "gpucore", 0, "the limit GPU core of each replica to run the serve.")
command.Flags().StringVar(&s.args.Cpu, "cpu", "", "the request cpu of each replica to run the serve.")
command.Flags().StringVar(&s.args.Memory, "memory", "", "the request memory of each replica to run the serve.")
command.Flags().IntVar(&s.args.Replicas, "replicas", 1, "the replicas number of the serve job.")
command.Flags().StringVar(&s.args.ShareMemory, "share-memory", "", "the request share memory of each replica to run the serve.")
// add option --image-pull-secret its' value will be get from viper,Using a Private Registry
command.Flags().StringArrayVar(&imagePullSecrets, "image-pull-secret", []string{}, `giving names of imagePullSecret when you want to use a private registry, usage:"--image-pull-secret <name1>"`)
command.Flags().StringArrayVarP(&envs, "env", "e", []string{}, "the environment variables")
command.Flags().BoolVar(&s.args.EnableIstio, "enableIstio", false, "enable Istio for serving or not (disable Istio by default)")
_ = command.Flags().MarkDeprecated("enableIstio", "please use --enable-istio instead")
command.Flags().BoolVar(&s.args.EnableIstio, "enable-istio", false, "enable Istio for serving or not (disable Istio by default)")
command.Flags().BoolVar(&s.args.ExposeService, "exposeService", false, "expose service using Istio gateway for external access or not (not expose by default)")
_ = command.Flags().MarkDeprecated("exposeService", "please use --expose-service instead")
command.Flags().BoolVar(&s.args.ExposeService, "expose-service", false, "expose service using Istio gateway for external access or not (not expose by default)")
command.Flags().StringVar(&s.args.Name, "servingName", "", "the serving name")
_ = command.Flags().MarkDeprecated("servingName", "please use --name instead")
command.Flags().StringVar(&s.args.Name, "name", "", "the serving name")
command.Flags().StringVar(&s.args.Version, "servingVersion", "", "the serving version")
_ = command.Flags().MarkDeprecated("servingVersion", "please use --version instead")
command.Flags().StringVar(&s.args.Version, "version", "", "the serving version")
command.Flags().StringArrayVarP(&dataset, "data", "d", []string{}, "specify the trained models datasource to mount for serving, like <name_of_datasource>:<mount_point_on_job>")
command.Flags().StringArrayVarP(&dataSubpathExpr, "data-subpath-expr", "", []string{}, "specify the datasource subpath to mount to the job by expression, like <name_of_datasource>:<mount_subpath_expr>")
command.Flags().StringArrayVarP(&datadir, "data-dir", "", []string{}, "specify the trained models datasource on host to mount for serving, like <host_path>:<mount_point_on_job>")
command.Flags().StringArrayVarP(&tempDirSubpathExpr, "temp-dir-subpath-expr", "", []string{}, "specify the datasource subpath to mount to the pod by expression, like <empty_dir_name>:<mount_subpath_expr>")
command.Flags().StringArrayVarP(&tempDir, "temp-dir", "", []string{}, "specify the deployment empty dir, like <empty_dir_name>:<mount_point_on_pod>")
_ = command.MarkFlagRequired("name")
command.Flags().StringArrayVarP(&annotations, "annotation", "a", []string{}, `specify the annotations, usage: "--annotation=key=value" or "--annotation key=value"`)
command.Flags().StringArrayVarP(&labels, "label", "l", []string{}, "specify the labels")
command.Flags().StringArrayVarP(&tolerations, "toleration", "", []string{}, `tolerate some k8s nodes with taints,usage: "--toleration key=value:effect,operator" or "--toleration all" `)
command.Flags().StringArrayVarP(&selectors, "selector", "", []string{}, `assigning jobs to some k8s particular nodes, usage: "--selector=key=value" or "--selector key=value" `)
// add option --config-file its' value will be get from viper
command.Flags().StringArrayVar(&configFiles, "config-file", []string{}, `giving configuration files when serving model, usage:"--config-file <host_path_file>:<container_path_file>"`)
// add option --shell
command.Flags().StringVarP(&s.args.Shell, "shell", "", "sh", "specify the linux shell, usage: bash or sh")
// add option --command
command.Flags().StringVar(&s.args.Command, "command", "", "specify the container command")
// add option --model-name
command.Flags().StringVar(&s.args.ModelName, "model-name", "", "model name")
// add option --model-version
command.Flags().StringVar(&s.args.ModelVersion, "model-version", "", "model version")
s.AddArgValue("annotation", &annotations).
AddArgValue("toleration", &tolerations).
AddArgValue("label", &labels).
AddArgValue("selector", &selectors).
AddArgValue("data", &dataset).
AddArgValue("data-subpath-expr", &dataSubpathExpr).
AddArgValue("data-dir", &datadir).
AddArgValue("temp-dir-subpath-expr", &tempDirSubpathExpr).
AddArgValue("temp-dir", &tempDir).
AddArgValue("env", &envs).
AddArgValue("config-file", &configFiles).
AddArgValue("image-pull-secret", &imagePullSecrets)
}
func (s *ServingArgsBuilder) PreBuild() error {
for name := range s.subBuilders {
if err := s.subBuilders[name].PreBuild(); err != nil {
return err
}
}
if err := s.checkNamespace(); err != nil {
return err
}
if err := s.validateIstioEnablement(); err != nil {
return err
}
if err := s.setDataSet(); err != nil {
return err
}
if err := s.setDataSubpathExprs(); err != nil {
return err
}
if err := s.setDataDirs(); err != nil {
return err
}
if err := s.setTempDirSubpathExprs(); err != nil {
return err
}
if err := s.setTempDirs(); err != nil {
return err
}
if err := s.setEnvs(); err != nil {
return err
}
if err := s.setAnnotations(); err != nil {
return err
}
if err := s.setLabels(); err != nil {
return err
}
if err := s.setNodeSelectors(); err != nil {
return err
}
if err := s.setTolerations(); err != nil {
return err
}
if err := s.setServingVersion(); err != nil {
return err
}
if err := s.setUserNameAndUserId(); err != nil {
return err
}
// set image pull secrets
if err := s.setImagePullSecrets(); err != nil {
return err
}
// set config files
if err := s.setConfigFiles(); err != nil {
return err
}
if err := s.disabledNvidiaENVWithNoneGPURequest(); err != nil {
return err
}
if err := s.check(); err != nil {
return err
}
if err := s.checkGPUCore(); err != nil {
return err
}
if err := s.setModelName(); err != nil {
return err
}
if err := s.setModelVersion(); err != nil {
return err
}
return nil
}
func (s *ServingArgsBuilder) Build() error {
for name := range s.subBuilders {
if err := s.subBuilders[name].Build(); err != nil {
return err
}
}
return nil
}
func (s *ServingArgsBuilder) check() error {
if s.args.GPUCount < 0 {
return fmt.Errorf("--gpus is invalid")
}
if s.args.GPUMemory < 0 {
return fmt.Errorf("--gpumemory is invalid")
}
if s.args.Cpu != "" {
_, err := resource.ParseQuantity(s.args.Cpu)
if err != nil {
return fmt.Errorf("--cpu is invalid")
}
}
if s.args.Memory != "" {
_, err := resource.ParseQuantity(s.args.Memory)
if err != nil {
return fmt.Errorf("--memory is invalid")
}
}
if s.args.ShareMemory != "" {
_, err := resource.ParseQuantity(s.args.ShareMemory)
if err != nil {
return fmt.Errorf("--share-memory is invalid")
}
}
return s.checkServiceExists()
}
// setImagePullSecrets is used to set
func (s *ServingArgsBuilder) setImagePullSecrets() error {
s.args.ImagePullSecrets = []string{}
argKey := "image-pull-secret"
var imagePullSecrets *[]string
value, ok := s.argValues[argKey]
if !ok {
return nil
}
imagePullSecrets = value.(*[]string)
if len(*imagePullSecrets) == 0 {
arenaConfig := config.GetArenaConfiger().GetConfigsFromConfigFile()
if temp, found := arenaConfig["imagePullSecrets"]; found {
log.Debugf("imagePullSecrets load from arenaConfigs: %v", temp)
s.args.ImagePullSecrets = strings.Split(temp, ",")
}
} else {
s.args.ImagePullSecrets = *imagePullSecrets
}
log.Debugf("imagePullSecrets: %v", s.args.ImagePullSecrets)
return nil
}
// setDataSets is used to handle option --data
func (s *ServingArgsBuilder) setDataSet() error {
s.args.ModelDirs = map[string]string{}
argKey := "data"
var dataSet *[]string
value, ok := s.argValues[argKey]
if !ok {
return nil
}
dataSet = value.(*[]string)
log.Debugf("dataset: %v", *dataSet)
if len(*dataSet) <= 0 {
return nil
}
err := util.ValidateDatasets(*dataSet)
if err != nil {
return err
}
s.args.ModelDirs = transformSliceToMap(*dataSet, ":")
return nil
}
// setDataSubpathExprs is used to handle option --data-subpath-expr
func (s *ServingArgsBuilder) setDataSubpathExprs() error {
s.args.DataSubpathExprs = map[string]string{}
argKey := "data-subpath-expr"
var dataSubPathExprs *[]string
value, ok := s.argValues[argKey]
if !ok {
return nil
}
dataSubPathExprs = value.(*[]string)
log.Debugf("setDataSubpathExprs: %v", *dataSubPathExprs)
if len(*dataSubPathExprs) <= 0 {
return nil
}
s.args.DataSubpathExprs = transformSliceToMap(*dataSubPathExprs, ":")
return nil
}
// setDataSubpathExprs is used to handle option --temp-dir-subpath-expr
func (s *ServingArgsBuilder) setTempDirSubpathExprs() error {
s.args.TempDirSubpathExpr = map[string]string{}
argKey := "temp-dir-subpath-expr"
var tempDirSubPathExprs *[]string
value, ok := s.argValues[argKey]
if !ok {
return nil
}
tempDirSubPathExprs = value.(*[]string)
log.Debugf("setDataSubpathExprs: %v", *tempDirSubPathExprs)
if len(*tempDirSubPathExprs) <= 0 {
return nil
}
s.args.TempDirSubpathExpr = transformSliceToMap(*tempDirSubPathExprs, ":")
return nil
}
// setDataDirs is used to handle option --data-dir
func (s *ServingArgsBuilder) setDataDirs() error {
s.args.HostVolumes = []types.DataDirVolume{}
argKey := "data-dir"
var dataDirs *[]string
value, ok := s.argValues[argKey]
if !ok {
return nil
}
dataDirs = value.(*[]string)
log.Debugf("dataDir: %v", *dataDirs)
for i, dataDir := range *dataDirs {
hostPath, containerPath, err := util.ParseDataDirRaw(dataDir)
if err != nil {
return err
}
s.args.HostVolumes = append(s.args.HostVolumes, types.DataDirVolume{
Name: fmt.Sprintf("serving-data-%d", i),
HostPath: hostPath,
ContainerPath: containerPath,
})
}
return nil
}
// setTempDirs is used to handle option --temp-dir
// setDataSets is used to handle option --data
func (s *ServingArgsBuilder) setTempDirs() error {
s.args.TempDirs = map[string]string{}
argKey := "temp-dir"
var tempDirs *[]string
value, ok := s.argValues[argKey]
if !ok {
return nil
}
tempDirs = value.(*[]string)
log.Debugf("tempDirs: %v", *tempDirs)
if len(*tempDirs) <= 0 {
return nil
}
s.args.TempDirs = transformSliceToMap(*tempDirs, ":")
return nil
}
// setAnnotations is used to handle option --annotation
func (s *ServingArgsBuilder) setAnnotations() error {
s.args.Annotations = map[string]string{}
argKey := "annotation"
var annotations *[]string
item, ok := s.argValues[argKey]
if !ok {
return nil
}
annotations = item.(*[]string)
if len(*annotations) <= 0 {
return nil
}
s.args.Annotations = transformSliceToMap(*annotations, "=")
return nil
}
// setLabels is used to handle option --label
func (s *ServingArgsBuilder) setLabels() error {
s.args.Labels = map[string]string{}
argKey := "label"
var labels *[]string
item, ok := s.argValues[argKey]
if !ok {
return nil
}
labels = item.(*[]string)
if len(*labels) <= 0 {
return nil
}
s.args.Labels = transformSliceToMap(*labels, "=")
return nil
}
func (s *ServingArgsBuilder) setUserNameAndUserId() error {
if s.args.Labels == nil {
s.args.Labels = map[string]string{}
}
if s.args.Annotations == nil {
s.args.Annotations = map[string]string{}
}
arenaConfiger := config.GetArenaConfiger()
user := arenaConfiger.GetUser()
s.args.Labels[types.UserNameIdLabel] = user.GetId()
s.args.Annotations[types.UserNameNameLabel] = user.GetName()
return nil
}
// setNodeSelectors is used to handle option --selector
func (s *ServingArgsBuilder) setNodeSelectors() error {
s.args.NodeSelectors = map[string]string{}
argKey := "selector"
var nodeSelectors *[]string
value, ok := s.argValues[argKey]
if !ok {
return nil
}
nodeSelectors = value.(*[]string)
log.Debugf("node selectors: %v", *nodeSelectors)
s.args.NodeSelectors = transformSliceToMap(*nodeSelectors, "=")
return nil
}
// setTolerations is used to handle option --toleration
func (s *ServingArgsBuilder) setTolerations() error {
if s.args.Tolerations == nil {
s.args.Tolerations = []types.TolerationArgs{}
}
argKey := "toleration"
var tolerations *[]string
value, ok := s.argValues[argKey]
if !ok {
return nil
}
tolerations = value.(*[]string)
log.Debugf("tolerations: %v", *tolerations)
for _, taintKey := range *tolerations {
if taintKey == "all" {
s.args.Tolerations = append(s.args.Tolerations, types.TolerationArgs{
Operator: "Exists",
})
return nil
}
tolerationArg, err := parseTolerationString(taintKey)
if err != nil {
log.Debugf(err.Error())
continue
}
s.args.Tolerations = append(s.args.Tolerations, *tolerationArg)
}
return nil
}
func (s *ServingArgsBuilder) setEnvs() error {
argKey := "env"
var envs *[]string
value, ok := s.argValues[argKey]
if !ok {
return nil
}
envs = value.(*[]string)
s.args.Envs = transformSliceToMap(*envs, "=")
return nil
}
func (s *ServingArgsBuilder) setServingVersion() error {
if s.args.Version == "" && s.args.Type != types.KServeJob {
t := time.Now()
s.args.Version = fmt.Sprint(t.Format("200601021504"))
}
return nil
}
// setConfigFiles is used to handle option --config-file
func (s *ServingArgsBuilder) setConfigFiles() error {
s.args.ConfigFiles = map[string]map[string]types.ConfigFileInfo{}
if s.args.HelmOptions == nil {
s.args.HelmOptions = []string{}
}
argKey := "config-file"
var configFiles *[]string
value, ok := s.argValues[argKey]
if !ok {
return nil
}
configFiles = value.(*[]string)
exists := map[string]bool{}
for ind, val := range *configFiles {
var (
containerFile string
err error
)
// use md5 rather than index,the reason is that if user gives a option twice,index can't filter it
configFileKey := fmt.Sprintf("config-%v", ind)
files := strings.Split(val, ":")
hostFile := files[0]
// change ~ to user home directory
if strings.Index(hostFile, "~/") == 0 {
hostFile = strings.Replace(hostFile, "~", os.Getenv("HOME"), -1)
}
// change relative path to absolute path
hostFile, err = filepath.Abs(hostFile)
if err != nil {
return err
}
// the option gives container path or not,if not, we see the container path is same as host path
switch len(files) {
case 1:
containerFile = hostFile
case 2:
containerFile = files[1]
default:
return fmt.Errorf("invalid format for assigning config file,it should be '--config-file <host_path_file>:<container_path_file>'")
}
if _, ok := exists[fmt.Sprintf("%v:%v", hostFile, containerFile)]; ok {
continue
}
exists[fmt.Sprintf("%v:%v", hostFile, containerFile)] = true
// if the container path is not absolute path,return error
if !path.IsAbs(containerFile) {
return fmt.Errorf("the path of file in container must be absolute path")
}
// check the host path file is exist or not
_, err = os.Stat(hostFile)
if os.IsNotExist(err) {
return err
}
info := types.ConfigFileInfo{
Key: configFileKey,
ContainerFileName: path.Base(containerFile),
ContainerFilePath: path.Dir(containerFile),
HostFile: hostFile,
}
// classify the files by container path
containerPathKey := util.Md5(path.Dir(containerFile))[0:15]
if _, ok := s.args.ConfigFiles[containerPathKey]; !ok {
s.args.ConfigFiles[containerPathKey] = map[string]types.ConfigFileInfo{}
}
s.args.ConfigFiles[containerPathKey][configFileKey] = info
}
for containerPathKey, val := range s.args.ConfigFiles {
for configFileKey, info := range val {
s.args.HelmOptions = append(s.args.HelmOptions,
fmt.Sprintf("--set-file configFiles.%v.%v.content=%v", containerPathKey, configFileKey, info.HostFile))
tmp := fmt.Sprintf("--set-file configFiles.%v.%v.content=%v", containerPathKey, configFileKey, info.HostFile)
fmt.Println(tmp)
}
}
return nil
}
func (s *ServingArgsBuilder) validateIstioEnablement() error {
log.Debugf("--enable-Istio=%t is specified.", s.args.EnableIstio)
if !s.args.EnableIstio {
return nil
}
reg := regexp.MustCompile(regexp4serviceName)
matched := reg.MatchString(s.args.Name)
if !matched {
return fmt.Errorf("--name should be numbers, letters, dashes, and underscores ONLY")
}
log.Debugf("--version=%s is specified.", s.args.Version)
if s.args.Version == "" {
return fmt.Errorf("--version must be specified if --enable-istio=true")
}
return nil
}
// checkServiceExists is used to check services,must execute after function checkNamespace
func (s *ServingArgsBuilder) checkServiceExists() error {
client := config.GetArenaConfiger().GetClientSet()
_, err := client.CoreV1().Services(s.args.Namespace).Get(context.TODO(), s.args.Name, metav1.GetOptions{})
if err != nil {
if !errors.IsNotFound(err) {
return err
}
s.args.ModelServiceExists = false
} else {
s.args.ModelServiceExists = true
}
return nil
}
func (s *ServingArgsBuilder) checkNamespace() error {
if s.args.Namespace == "" {
return fmt.Errorf("not set namespace,please set it")
}
log.Debugf("namespace is %v", s.args.Namespace)
return nil
}
func (s *ServingArgsBuilder) disabledNvidiaENVWithNoneGPURequest() error {
if s.args.Envs == nil {
s.args.Envs = map[string]string{}
}
if s.args.GPUCount == 0 && s.args.GPUMemory == 0 && s.args.GPUCore == 0 {
s.args.Envs["NVIDIA_VISIBLE_DEVICES"] = "void"
}
return nil
}
func (s *ServingArgsBuilder) checkGPUCore() error {
if s.args.GPUCore%5 != 0 {
return fmt.Errorf("GPUCore should be the multiple of 5")
}
return nil
}
func (s *ServingArgsBuilder) setModelName() error {
if s.args.ModelName != "" {
s.args.Labels["modelName"] = s.args.ModelName
}
return nil
}
func (s *ServingArgsBuilder) setModelVersion() error {
if s.args.ModelVersion != "" {
s.args.Labels["modelVersion"] = s.args.ModelVersion
}
return nil
}