Skip to content
New issue

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

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

Already on GitHub? # to your account

fix bug: error for getting training job logs when no chief pod #501

Merged
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
39 changes: 36 additions & 3 deletions pkg/training/logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@ package training

import (
"fmt"
"strings"

"github.com/kubeflow/arena/pkg/apis/types"
"github.com/kubeflow/arena/pkg/apis/utils"
podlogs "github.com/kubeflow/arena/pkg/podlogs"
v1 "k8s.io/api/core/v1"
)

// AcceptJobLog is used for arena-go-sdk
Expand All @@ -34,10 +36,13 @@ func AcceptJobLog(jobName string, trainingType types.TrainingJobType, args *type
if err != nil {
return err
}
chiefPod := job.ChiefPod()
// 3.if instance name not set,set the chief pod name to instance name
if args.InstanceName == "" && chiefPod != nil {
args.InstanceName = chiefPod.Name
if args.InstanceName == "" {
name, err := getInstanceName(job)
if err != nil {
return err
}
args.InstanceName = name
}
podStatuses := map[string]string{}
for _, pod := range job.AllPods() {
Expand Down Expand Up @@ -72,3 +77,31 @@ func getTrainingJobTypes() []string {
}
return jobTypes
}

func getInstanceName(job TrainingJob) (string, error) {
pods := job.AllPods()
// if not found pods,return an error
if pods == nil || len(pods) == 0 {
return "", fmt.Errorf("not found instances of the job %v", job.Name())
}
// if the job has only one pod,return its' name
if len(pods) == 1 {
return pods[0].Name, nil
}
// if job has many pods and the chief pod name is existed,return it
if job.ChiefPod() != nil && job.ChiefPod().Name != "" {
return job.ChiefPod().Name, nil
}
// return an error
return "", fmt.Errorf("%v", moreThanOneInstanceHelpInfo(pods))
}

func moreThanOneInstanceHelpInfo(pods []*v1.Pod) string {
header := fmt.Sprintf("There is %d instances have been found:", len(pods))
lines := []string{}
footer := fmt.Sprintf("please use '-i' or '--instance' to filter.")
for _, p := range pods {
lines = append(lines, fmt.Sprintf("%v", p.Name))
}
return fmt.Sprintf("%s\n\n%s\n\n%s\n", header, strings.Join(lines, "\n"), footer)
}