Refactoring project to be more similar to other go project.
This commit is contained in:
parent
bbccabcd27
commit
d7db155d88
10 changed files with 153 additions and 192 deletions
|
@ -18,6 +18,7 @@ import (
|
|||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/aurora-scheduler/australis/internal"
|
||||
"github.com/aurora-scheduler/gorealis/v2/gen-go/apache/aurora"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
@ -25,12 +26,12 @@ import (
|
|||
func init() {
|
||||
rootCmd.AddCommand(monitorCmd)
|
||||
|
||||
monitorCmd.AddCommand(monitorHostCmd.cmd)
|
||||
monitorCmd.AddCommand(monitorHostCmd.Cmd)
|
||||
|
||||
monitorHostCmd.cmd.Run = monitorHost
|
||||
monitorHostCmd.cmd.Flags().DurationVar(&monitorHostCmd.monitorInterval, "interval", time.Second*5, "Interval at which to poll scheduler.")
|
||||
monitorHostCmd.cmd.Flags().DurationVar(&monitorHostCmd.monitorTimeout, "timeout", time.Minute*10, "Time after which the monitor will stop polling and throw an error.")
|
||||
monitorHostCmd.cmd.Flags().StringSliceVar(&monitorHostCmd.statusList, "statuses", []string{aurora.MaintenanceMode_DRAINED.String()}, "List of acceptable statuses for a host to be in. (case-insensitive) [NONE, SCHEDULED, DRAINED, DRAINING]")
|
||||
monitorHostCmd.Cmd.Run = monitorHost
|
||||
monitorHostCmd.Cmd.Flags().DurationVar(&monitorHostCmd.MonitorInterval, "interval", time.Second*5, "Interval at which to poll scheduler.")
|
||||
monitorHostCmd.Cmd.Flags().DurationVar(&monitorHostCmd.MonitorTimeout, "timeout", time.Minute*10, "Time after which the monitor will stop polling and throw an error.")
|
||||
monitorHostCmd.Cmd.Flags().StringSliceVar(&monitorHostCmd.StatusList, "statuses", []string{aurora.MaintenanceMode_DRAINED.String()}, "List of acceptable statuses for a host to be in. (case-insensitive) [NONE, SCHEDULED, DRAINED, DRAINING]")
|
||||
}
|
||||
|
||||
var monitorCmd = &cobra.Command{
|
||||
|
@ -38,20 +39,20 @@ var monitorCmd = &cobra.Command{
|
|||
Short: "Watch for a specific state change",
|
||||
}
|
||||
|
||||
var monitorHostCmd = monitorCmdConfig{
|
||||
cmd: &cobra.Command{
|
||||
var monitorHostCmd = internal.MonitorCmdConfig{
|
||||
Cmd: &cobra.Command{
|
||||
Use: "hosts",
|
||||
Short: "Watch a host maintenance status until it enters one of the desired statuses.",
|
||||
Long: `Provide a list of hosts to monitor for desired statuses. Statuses may be passed using the --statuses
|
||||
flag with a list of comma separated statuses. Statuses include [NONE, SCHEDULED, DRAINED, DRAINING]`,
|
||||
},
|
||||
statusList: make([]string, 0),
|
||||
StatusList: make([]string, 0),
|
||||
}
|
||||
|
||||
func monitorHost(cmd *cobra.Command, args []string) {
|
||||
maintenanceModes := make([]aurora.MaintenanceMode, 0)
|
||||
|
||||
for _, status := range monitorHostCmd.statusList {
|
||||
for _, status := range monitorHostCmd.StatusList {
|
||||
mode, err := aurora.MaintenanceModeFromString(strings.ToUpper(status))
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
|
@ -60,10 +61,10 @@ func monitorHost(cmd *cobra.Command, args []string) {
|
|||
maintenanceModes = append(maintenanceModes, mode)
|
||||
}
|
||||
|
||||
log.Infof("Monitoring for %v at %v intervals", monitorHostCmd.monitorTimeout, monitorHostCmd.monitorInterval)
|
||||
hostResult, err := client.MonitorHostMaintenance(args, maintenanceModes, monitorHostCmd.monitorInterval, monitorHostCmd.monitorTimeout)
|
||||
log.Infof("Monitoring for %v at %v intervals", monitorHostCmd.MonitorTimeout, monitorHostCmd.MonitorInterval)
|
||||
hostResult, err := client.MonitorHostMaintenance(args, maintenanceModes, monitorHostCmd.MonitorInterval, monitorHostCmd.MonitorTimeout)
|
||||
|
||||
maintenanceMonitorPrint(hostResult, maintenanceModes)
|
||||
internal.MaintenanceMonitorPrint(hostResult, maintenanceModes, toJson)
|
||||
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue