forked from kubeflow/arena
-
Notifications
You must be signed in to change notification settings - Fork 0
/
job.go
60 lines (57 loc) · 1.99 KB
/
job.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
package top
import (
"fmt"
"github.com/kubeflow/arena/pkg/apis/arenaclient"
"github.com/kubeflow/arena/pkg/apis/types"
"github.com/kubeflow/arena/pkg/apis/utils"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)
func NewTopJobCommand() *cobra.Command {
var (
allNamespaces bool
format string
jobType string
notStop bool
instanceName string
)
var command = &cobra.Command{
Use: "job",
Short: "Display Resource (GPU) usage of jobs.",
PreRun: func(cmd *cobra.Command, args []string) {
_ = viper.BindPFlags(cmd.Flags())
},
RunE: func(cmd *cobra.Command, args []string) error {
isDaemonMode := false
if notStop {
isDaemonMode = true
}
client, err := arenaclient.NewArenaClient(types.ArenaClientArgs{
Kubeconfig: viper.GetString("config"),
LogLevel: viper.GetString("loglevel"),
Namespace: viper.GetString("namespace"),
ArenaNamespace: viper.GetString("arena-namespace"),
IsDaemonMode: isDaemonMode,
})
if err != nil {
return fmt.Errorf("failed to create arena client: %v", err)
}
return client.Training().Top(
args,
allNamespaces,
utils.TransferTrainingJobType(jobType),
instanceName,
notStop,
utils.TransferPrintFormat(format),
)
},
}
command.Flags().BoolVar(&allNamespaces, "allNamespaces", false, "show all the namespaces")
_ = command.Flags().MarkDeprecated("allNamespaces", "please use --all-namespaces instead")
command.Flags().BoolVarP(&allNamespaces, "all-namespaces", "A", false, "show all the namespaces")
command.Flags().StringVarP(&format, "output", "o", "wide", "Output format. One of: json|yaml|wide")
command.Flags().BoolVarP(¬Stop, "refresh", "r", false, "Display continuously")
command.Flags().StringVarP(&instanceName, "instance", "i", "", "Display instance top info")
command.Flags().StringVarP(&jobType, "type", "T", "", fmt.Sprintf("The training type, the possible option is [%v]. (optional)", utils.GetSupportTrainingJobTypesInfo()))
return command
}