Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for updating the nodeSelector and toleration in GO SDK. #1043

Merged
merged 1 commit into from
Feb 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions pkg/apis/serving/update_custom_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -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, " ")
Expand All @@ -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 {
Expand Down
8 changes: 8 additions & 0 deletions pkg/apis/serving/update_kserve_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -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, " ")
Expand Down
32 changes: 28 additions & 4 deletions samples/sdk/custom-serving/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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)
Expand All @@ -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 {
Expand Down
Loading