forked from kubeflow/arena
-
Notifications
You must be signed in to change notification settings - Fork 0
/
update_tensorflow_builder.go
166 lines (147 loc) · 4.42 KB
/
update_tensorflow_builder.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
package serving
import (
"fmt"
"strings"
"github.com/kubeflow/arena/pkg/apis/types"
"github.com/kubeflow/arena/pkg/argsbuilder"
)
type UpdateTFServingJobBuilder struct {
args *types.UpdateTensorFlowServingArgs
argValues map[string]interface{}
argsbuilder.ArgsBuilder
}
func NewUpdateTFServingJobBuilder() *UpdateTFServingJobBuilder {
args := &types.UpdateTensorFlowServingArgs{
CommonUpdateServingArgs: types.CommonUpdateServingArgs{
Image: argsbuilder.DefaultTfServingImage,
Replicas: 1,
Namespace: "default",
},
}
return &UpdateTFServingJobBuilder{
args: args,
argValues: map[string]interface{}{},
ArgsBuilder: argsbuilder.NewUpdateTensorflowServingArgsBuilder(args),
}
}
// Name is used to set job name,match option --name
func (b *UpdateTFServingJobBuilder) Name(name string) *UpdateTFServingJobBuilder {
if name != "" {
b.args.Name = name
}
return b
}
// Namespace is used to set job namespace,match option --namespace
func (b *UpdateTFServingJobBuilder) Namespace(namespace string) *UpdateTFServingJobBuilder {
if namespace != "" {
b.args.Namespace = namespace
}
return b
}
// Shell is used to set bash or sh
func (b *UpdateTFServingJobBuilder) Shell(shell string) *UpdateTFServingJobBuilder {
if shell != "" {
b.args.Shell = shell
}
return b
}
// Command is used to set job command
func (b *UpdateTFServingJobBuilder) Command(args []string) *UpdateTFServingJobBuilder {
b.args.Command = strings.Join(args, " ")
return b
}
// Image is used to set job image,match the option --image
func (b *UpdateTFServingJobBuilder) Image(image string) *UpdateTFServingJobBuilder {
if image != "" {
b.args.Image = image
}
return b
}
// Envs is used to set env of job containers,match option --env
func (b *UpdateTFServingJobBuilder) Envs(envs map[string]string) *UpdateTFServingJobBuilder {
if len(envs) != 0 {
envSlice := []string{}
for key, value := range envs {
envSlice = append(envSlice, fmt.Sprintf("%v=%v", key, value))
}
b.argValues["env"] = &envSlice
}
return b
}
// Annotations is used to add annotations for job pods,match option --annotation
func (b *UpdateTFServingJobBuilder) Annotations(annotations map[string]string) *UpdateTFServingJobBuilder {
if len(annotations) != 0 {
s := []string{}
for key, value := range annotations {
s = append(s, fmt.Sprintf("%v=%v", key, value))
}
b.argValues["annotation"] = &s
}
return b
}
// Labels is used to add labels for job
func (b *UpdateTFServingJobBuilder) Labels(labels map[string]string) *UpdateTFServingJobBuilder {
if len(labels) != 0 {
s := []string{}
for key, value := range labels {
s = append(s, fmt.Sprintf("%v=%v", key, value))
}
b.argValues["label"] = &s
}
return b
}
// Replicas is used to set serving job replicas,match the option --replicas
func (b *UpdateTFServingJobBuilder) Replicas(count int) *UpdateTFServingJobBuilder {
if count > 0 {
b.args.Replicas = count
}
return b
}
// Version is used to set serving job version,match the option --version
func (b *UpdateTFServingJobBuilder) Version(version string) *UpdateTFServingJobBuilder {
if version != "" {
b.args.Version = version
}
return b
}
// ModelConfigFile is used to set model config file,match the option --model-config-file
func (b *UpdateTFServingJobBuilder) ModelConfigFile(filePath string) *UpdateTFServingJobBuilder {
if filePath != "" {
b.args.ModelConfigFile = filePath
}
return b
}
// MonitoringConfigFile is used to set monitoring config file,match the option --monitoring-config-file
func (b *UpdateTFServingJobBuilder) MonitoringConfigFile(filePath string) *UpdateTFServingJobBuilder {
if filePath != "" {
b.args.MonitoringConfigFile = filePath
}
return b
}
// ModelName is used to set model name,match the option --model-name
func (b *UpdateTFServingJobBuilder) ModelName(name string) *UpdateTFServingJobBuilder {
if name != "" {
b.args.ModelName = name
}
return b
}
// ModelPath is used to set model path,match the option --model-path
func (b *UpdateTFServingJobBuilder) ModelPath(path string) *UpdateTFServingJobBuilder {
if path != "" {
b.args.ModelPath = path
}
return b
}
// Build is used to build the job
func (b *UpdateTFServingJobBuilder) Build() (*Job, error) {
for key, value := range b.argValues {
b.AddArgValue(key, value)
}
if err := b.PreBuild(); err != nil {
return nil, err
}
if err := b.ArgsBuilder.Build(); err != nil {
return nil, err
}
return NewJob(b.args.Name, types.TFServingJob, b.args), nil
}