goimports style fixes.

This commit is contained in:
Renan DelValle 2019-03-19 15:28:24 -07:00
parent 4551231644
commit 616d4bc57e
No known key found for this signature in database
GPG key ID: C240AD6D6F443EC9
9 changed files with 125 additions and 131 deletions

View file

@ -3,7 +3,7 @@ package cmd
import (
"fmt"
"github.com/paypal/gorealis/v2"
realis "github.com/paypal/gorealis/v2"
"github.com/paypal/gorealis/v2/gen-go/apache/aurora"
"github.com/spf13/cobra"
"github.com/spf13/pflag"
@ -29,7 +29,6 @@ func init() {
taskStatusCmd.Flags().StringVarP(role, "role", "r", "", "Aurora Role")
taskStatusCmd.Flags().StringVarP(name, "name", "n", "", "Aurora Name")
/* Fetch Leader */
leaderCmd.Flags().String("zkPath", "/aurora/scheduler", "Zookeeper node path where leader election happens")
@ -37,9 +36,9 @@ func init() {
// Hijack help function to hide unnecessary global flags
help := leaderCmd.HelpFunc()
leaderCmd.SetHelpFunc(func(cmd *cobra.Command, s []string){
if cmd.HasInheritedFlags(){
cmd.InheritedFlags().VisitAll(func(f *pflag.Flag){
leaderCmd.SetHelpFunc(func(cmd *cobra.Command, s []string) {
if cmd.HasInheritedFlags() {
cmd.InheritedFlags().VisitAll(func(f *pflag.Flag) {
if f.Name != "logLevel" {
f.Hidden = true
}
@ -66,7 +65,6 @@ var fetchTaskCmd = &cobra.Command{
Short: "Task information from Aurora",
}
var taskConfigCmd = &cobra.Command{
Use: "config",
Short: "Fetch a list of task configurations from Aurora.",

View file

@ -1,7 +1,7 @@
package cmd
import (
"github.com/paypal/gorealis/v2"
realis "github.com/paypal/gorealis/v2"
"github.com/spf13/cobra"
)

View file

@ -49,4 +49,3 @@ func rollbackUpdate(cmd *cobra.Command, args []string) {
fmt.Printf("Rollback update for update ID %v sent successfully\n", updateID)
}

View file

@ -1,11 +1,12 @@
package cmd
import (
"github.com/spf13/viper"
"strings"
"time"
"github.com/paypal/gorealis/v2"
"github.com/spf13/viper"
realis "github.com/paypal/gorealis/v2"
"github.com/spf13/cobra"
"github.com/sirupsen/logrus"
@ -48,7 +49,7 @@ func init() {
rootCmd.PersistentFlags().BoolVarP(&skipCertVerification, "skipCertVerification", "i", false, "Skip CA certificate hostname verification.")
rootCmd.PersistentFlags().StringVar(&configFile, "config", "/etc/aurora/australis.yml", "Config file to use.")
rootCmd.PersistentFlags().BoolVar(&toJson, "toJSON", false, "Print output in JSON format.")
rootCmd.PersistentFlags().StringVarP(&logLevel, "logLevel", "l", "info", "Set logging level [" + getLoggingLevels() + "].")
rootCmd.PersistentFlags().StringVarP(&logLevel, "logLevel", "l", "info", "Set logging level ["+getLoggingLevels()+"].")
}
var rootCmd = &cobra.Command{
@ -81,7 +82,6 @@ func setConfig(cmd *cobra.Command, args []string) {
func connect(cmd *cobra.Command, args []string) {
var err error
setConfig(cmd, args)
zkAddrSlice := strings.Split(zkAddr, ",")
@ -133,7 +133,7 @@ func connect(cmd *cobra.Command, args []string) {
// Prefer zookeeper if both ways of connecting are provided
if len(zkAddrSlice) > 0 && zkAddrSlice[0] != "" {
// Configure Zookeeper to connect
zkOptions := []realis.ZKOpt{ realis.ZKEndpoints(zkAddrSlice...), realis.ZKPath("/aurora/scheduler")}
zkOptions := []realis.ZKOpt{realis.ZKEndpoints(zkAddrSlice...), realis.ZKPath("/aurora/scheduler")}
realisOptions = append(realisOptions, realis.ZookeeperOptions(zkOptions...))
} else if schedAddr != "" {
realisOptions = append(realisOptions, realis.SchedulerUrl(schedAddr))

View file

@ -2,10 +2,11 @@ package cmd
import (
"fmt"
"github.com/pkg/errors"
"github.com/spf13/cobra"
"strconv"
"strings"
"github.com/pkg/errors"
"github.com/spf13/cobra"
)
func init() {
@ -32,7 +33,7 @@ var setQuotaCmd = &cobra.Command{
*role = args[0]
for i:=1; i < len(args); i++ {
for i := 1; i < len(args); i++ {
resourcePair := strings.Split(args[i], ":")
if len(resourcePair) != 2 {

View file

@ -1,47 +1,46 @@
package cmd
import (
"time"
"github.com/paypal/gorealis/v2/gen-go/apache/aurora"
"github.com/spf13/cobra"
"time"
)
func init() {
rootCmd.AddCommand(startCmd)
// Sub-commands
startCmd.AddCommand(startDrainCmd)
// Maintenance specific flags
startDrainCmd.Flags().DurationVar(&monitorInterval,"interval", time.Second * 5, "Interval at which to poll scheduler.")
startDrainCmd.Flags().DurationVar(&monitorTimeout,"timeout", time.Minute * 10, "Time after which the monitor will stop polling and throw an error.")
startDrainCmd.Flags().DurationVar(&monitorInterval, "interval", time.Second*5, "Interval at which to poll scheduler.")
startDrainCmd.Flags().DurationVar(&monitorTimeout, "timeout", time.Minute*10, "Time after which the monitor will stop polling and throw an error.")
startCmd.AddCommand(startSLADrainCmd)
/* SLA Aware commands */
startSLADrainCmd.AddCommand(startSLACountDrainCmd)
// SLA Maintenance specific flags
startSLACountDrainCmd.Flags().DurationVar(&monitorInterval,"interval", time.Second * 5, "Interval at which to poll scheduler.")
startSLACountDrainCmd.Flags().DurationVar(&monitorTimeout,"timeout", time.Minute * 20, "Time after which the monitor will stop polling and throw an error.")
startSLACountDrainCmd.Flags().DurationVar(&monitorInterval, "interval", time.Second*5, "Interval at which to poll scheduler.")
startSLACountDrainCmd.Flags().DurationVar(&monitorTimeout, "timeout", time.Minute*20, "Time after which the monitor will stop polling and throw an error.")
startSLACountDrainCmd.Flags().Int64Var(&count, "count", 5, "Instances count that should be running to meet SLA.")
startSLACountDrainCmd.Flags().DurationVar(&duration, "duration", time.Minute * 10, "Window of time from which we derive the SLA.")
startSLACountDrainCmd.Flags().DurationVar(&duration, "duration", time.Minute*10, "Window of time from which we derive the SLA.")
startSLADrainCmd.AddCommand(startSLAPercentageDrainCmd)
// SLA Maintenance specific flags
startSLAPercentageDrainCmd.Flags().DurationVar(&monitorInterval,"interval", time.Second * 5, "Interval at which to poll scheduler.")
startSLAPercentageDrainCmd.Flags().DurationVar(&monitorTimeout,"timeout", time.Minute * 1, "Time after which the monitor will stop polling and throw an error.")
startSLAPercentageDrainCmd.Flags().DurationVar(&monitorInterval, "interval", time.Second*5, "Interval at which to poll scheduler.")
startSLAPercentageDrainCmd.Flags().DurationVar(&monitorTimeout, "timeout", time.Minute*1, "Time after which the monitor will stop polling and throw an error.")
startSLAPercentageDrainCmd.Flags().Float64Var(&percent, "percent", 75.0, "Percentage of instances that should be running to meet SLA.")
startSLAPercentageDrainCmd.Flags().DurationVar(&duration, "duration", time.Minute * 10, "Window of time from which we derive the SLA.")
startSLAPercentageDrainCmd.Flags().DurationVar(&duration, "duration", time.Minute*10, "Window of time from which we derive the SLA.")
startCmd.AddCommand(startMaintenanceCmd)
// SLA Maintenance specific flags
startMaintenanceCmd.Flags().DurationVar(&monitorInterval,"interval", time.Second * 5, "Interval at which to poll scheduler.")
startMaintenanceCmd.Flags().DurationVar(&monitorTimeout,"timeout", time.Minute * 10, "Time after which the monitor will stop polling and throw an error.")
startMaintenanceCmd.Flags().DurationVar(&monitorInterval, "interval", time.Second*5, "Interval at which to poll scheduler.")
startMaintenanceCmd.Flags().DurationVar(&monitorTimeout, "timeout", time.Minute*10, "Time after which the monitor will stop polling and throw an error.")
}
var startCmd = &cobra.Command{
@ -179,7 +178,6 @@ func maintenance(cmd *cobra.Command, args []string) {
monitorInterval,
monitorTimeout)
maintenanceMonitorPrint(hostResult, []aurora.MaintenanceMode{aurora.MaintenanceMode_SCHEDULED})
if err != nil {

View file

@ -12,8 +12,8 @@ func init() {
// Stop subcommands
stopCmd.AddCommand(stopMaintCmd)
stopMaintCmd.Flags().DurationVar(&monitorInterval,"interval", time.Second * 5, "Interval at which to poll scheduler.")
stopMaintCmd.Flags().DurationVar(&monitorTimeout,"timeout", time.Minute * 1, "Time after which the monitor will stop polling and throw an error.")
stopMaintCmd.Flags().DurationVar(&monitorInterval, "interval", time.Second*5, "Interval at which to poll scheduler.")
stopMaintCmd.Flags().DurationVar(&monitorTimeout, "timeout", time.Minute*1, "Time after which the monitor will stop polling and throw an error.")
// Stop update
@ -60,7 +60,7 @@ func endMaintenance(cmd *cobra.Command, args []string) {
monitorInterval,
monitorTimeout)
maintenanceMonitorPrint(hostResult,[]aurora.MaintenanceMode{aurora.MaintenanceMode_NONE})
maintenanceMonitorPrint(hostResult, []aurora.MaintenanceMode{aurora.MaintenanceMode_NONE})
if err != nil {
log.Fatalln("error: %+v", err)

View file

@ -20,7 +20,6 @@ func toJSON(v interface{}) string {
return string(output)
}
func getLoggingLevels() string {
var buffer bytes.Buffer
@ -30,17 +29,16 @@ func getLoggingLevels() string {
buffer.WriteString(" ")
}
buffer.Truncate(buffer.Len()-1)
buffer.Truncate(buffer.Len() - 1)
return buffer.String()
}
func maintenanceMonitorPrint(hostResult map[string]bool, desiredStates []aurora.MaintenanceMode) {
if len(hostResult) > 0 {
// Create anonymous struct for JSON formatting
output := struct{
output := struct {
DesiredStates []string `json:desired_states`
Transitioned []string `json:transitioned`
NonTransitioned []string `json:non-transitioned`
@ -50,7 +48,7 @@ func maintenanceMonitorPrint(hostResult map[string]bool, desiredStates []aurora.
make([]string, 0),
}
for _,state := range desiredStates {
for _, state := range desiredStates {
output.DesiredStates = append(output.DesiredStates, state.String())
}