diff --git a/pkg/apis/serving/update_custom_builder.go b/pkg/apis/serving/update_custom_builder.go index 16701d334..81cfb12ec 100644 --- a/pkg/apis/serving/update_custom_builder.go +++ b/pkg/apis/serving/update_custom_builder.go @@ -43,6 +43,14 @@ func (b *UpdateCustomServingJobBuilder) Namespace(namespace string) *UpdateCusto return b } +// Version is used to set serving job version, match the option --version +func (b *UpdateCustomServingJobBuilder) Version(version string) *UpdateCustomServingJobBuilder { + if version != "" { + b.args.Version = version + } + return b +} + // Command is used to set job command func (b *UpdateCustomServingJobBuilder) Command(args []string) *UpdateCustomServingJobBuilder { b.args.Command = strings.Join(args, " ") @@ -69,6 +77,24 @@ func (b *UpdateCustomServingJobBuilder) Envs(envs map[string]string) *UpdateCust return b } +// Tolerations are used to set tolerations for tolerate nodes, match option --toleration +func (b *UpdateCustomServingJobBuilder) Tolerations(tolerations []string) *UpdateCustomServingJobBuilder { + b.argValues["toleration"] = &tolerations + return b +} + +// NodeSelectors is used to set node selectors for scheduling job, match option --selector +func (b *UpdateCustomServingJobBuilder) NodeSelectors(selectors map[string]string) *UpdateCustomServingJobBuilder { + if len(selectors) != 0 { + selectorsSlice := []string{} + for key, value := range selectors { + selectorsSlice = append(selectorsSlice, fmt.Sprintf("%v=%v", key, value)) + } + b.argValues["selector"] = &selectorsSlice + } + return b +} + // Annotations is used to add annotations for job pods,match option --annotation func (b *UpdateCustomServingJobBuilder) Annotations(annotations map[string]string) *UpdateCustomServingJobBuilder { if len(annotations) != 0 { diff --git a/pkg/apis/serving/update_kserve_builder.go b/pkg/apis/serving/update_kserve_builder.go index ef09fb80b..326bdc05f 100644 --- a/pkg/apis/serving/update_kserve_builder.go +++ b/pkg/apis/serving/update_kserve_builder.go @@ -43,6 +43,14 @@ func (b *UpdateKServeJobBuilder) Namespace(namespace string) *UpdateKServeJobBui return b } +// Version is used to set serving job version, match the option --version +func (b *UpdateKServeJobBuilder) Version(version string) *UpdateKServeJobBuilder { + if version != "" { + b.args.Version = version + } + return b +} + // Command is used to set job command func (b *UpdateKServeJobBuilder) Command(args []string) *UpdateKServeJobBuilder { b.args.Command = strings.Join(args, " ") diff --git a/samples/sdk/custom-serving/main.go b/samples/sdk/custom-serving/main.go index 73d6519dd..8b1f717c2 100644 --- a/samples/sdk/custom-serving/main.go +++ b/samples/sdk/custom-serving/main.go @@ -42,16 +42,38 @@ func main() { Version(jobVersion). Replicas(1). RestfulPort(5000). - Image("happy365/fast-style-transfer:latest").Command([]string{"python app.py"}).Build() + Image("happy365/fast-style-transfer:latest").Command([]string{"python app.py"}). + Annotations(map[string]string{"testAnnotation": "v1"}). + Build() if err != nil { - fmt.Printf("failed to build custom serving job,reason: %v\n", err) + fmt.Printf("failed to build custom serving job, reason: %v\n", err) return } - // submit tfjob + + // submit custom serving if err := client.Serving().Submit(job); err != nil { - fmt.Printf("failed to submit job,reason: %v\n", err) + fmt.Printf("failed to submit custom serving job, reason: %v\n", err) return } + + // update custom serve + updateJob, err := serving.NewUpdateCustomServingJobBuilder(). + Name(jobName). + Namespace("default"). + Version(jobVersion). + Replicas(1). + Annotations(map[string]string{"testAnnotation": "v2"}). + Build() + if err != nil { + fmt.Printf("failed to build update custom serving job, reason: %v\n", err) + return + } + + if err := client.Serving().Update(updateJob); err != nil { + fmt.Printf("failed to update custom serving job, resion: %v\n", err) + return + } + // list all jobs jobInfos, err := client.Serving().List(true, types.AllServingJob) if err != nil { @@ -61,6 +83,7 @@ func main() { for _, job := range jobInfos { fmt.Printf("found job %s\n", job.Name) } + // get the job information and wait it to be running,timeout: 500s for i := 250; i >= 0; i-- { time.Sleep(2 * time.Second) @@ -80,6 +103,7 @@ func main() { fmt.Printf("job info: %v\n", job) break } + // get the job log,the status of job must be RUNNING logArgs, err := logger.NewLoggerBuilder().Build() if err != nil {