Skip to content

Commit

Permalink
Add stub functions for gather data
Browse files Browse the repository at this point in the history
Signed-off-by: Vishal Thapar <[email protected]>
  • Loading branch information
vthapar authored and mangelajo committed Mar 17, 2021
1 parent 62a00a9 commit 148f091
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 17 deletions.
86 changes: 69 additions & 17 deletions pkg/subctl/cmd/gather.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,41 +21,58 @@ import (
"strings"

"github.com/spf13/cobra"
"github.com/submariner-io/submariner-operator/pkg/internal/cli"
"github.com/submariner-io/submariner-operator/pkg/subctl/components"
)

var (
gatherType string
gatherModule string
)

const (
Logs = "logs"
Resources = "resources"
)

var gatherModuleFlags = map[string]bool{
"connectivity": false,
"discovery": false,
"broker": false,
"operator": false,
components.Connectivity: false,
components.ServiceDiscovery: false,
components.Broker: false,
components.Operator: false,
}

var gatherTypeFlags = map[string]bool{
"logs": false,
"resources": false,
}

var gatherFuncs = map[string]func(*cli.Status, string) error{
components.Connectivity: gatherConnectivity,
components.ServiceDiscovery: gatherDiscovery,
components.Broker: gatherBroker,
components.Operator: gatherOperator,
}

func init() {
addKubeconfigFlag(gatherCmd)
addGatherFlags(gatherCmd)
rootCmd.AddCommand(gatherCmd)
}

func addGatherFlags(gatherCmd *cobra.Command) {
gatherCmd.Flags().StringVar(&gatherType, "type", strings.Join(getAllTypeKeys(), ","), "comma-separated list of data types to gather")
gatherCmd.Flags().StringVar(&gatherModule, "module", strings.Join(getAllModuleKeys(), ","), "comma-separated list of components for which to gather data")
gatherCmd.Flags().StringVar(&gatherType, "type", strings.Join(getAllTypeKeys(), ","),
"comma-separated list of data types to gather")
gatherCmd.Flags().StringVar(&gatherModule, "module", strings.Join(getAllModuleKeys(), ","),
"comma-separated list of components for which to gather data")
}

var gatherCmd = &cobra.Command{
Use: "gather <kubeConfig1>",
Use: "gather <kubeConfig>",
Short: "Gather troubleshooting data from a cluster",
Long: fmt.Sprintf("This command gathers data from a submariner cluster for troubleshooting. Data gathered" +
"can be selected by component (%v) and type (%v). Default is to capture all data.", strings.Join(getAllModuleKeys(), ","), strings.Join(getAllTypeKeys(), ",")),
Long: fmt.Sprintf("This command gathers data from a submariner cluster for troubleshooting. The data gathered "+
"can be selected by component (%v) and type (%v). Default is to capture all data.",
strings.Join(getAllModuleKeys(), ","), strings.Join(getAllTypeKeys(), ",")),
Run: func(cmd *cobra.Command, args []string) {
gatherData()
},
Expand All @@ -65,22 +82,57 @@ func gatherData() {
err := checkGatherArguments()
exitOnError("Invalid arguments", err)

fmt.Printf("Gathering following data for module(s): ")
for module, ok := range gatherModuleFlags {
if ok {
fmt.Printf("%s ", module)
for dataType, ok := range gatherTypeFlags {
if ok {
status := cli.NewStatus()
status.Start(fmt.Sprintf("Gathering %s %s...", module, dataType))
status.End(cli.CheckForError(gatherFuncs[module](status, dataType)))
}
}
}
}
for dataType, ok := range gatherTypeFlags {
if ok {
fmt.Printf("\n * %s ", dataType)
}
}

func gatherConnectivity(status *cli.Status, dataType string) error {
switch dataType {
case Logs:
status.QueueWarningMessage("Gather Connectivity Logs not implemented yet")
case Resources:
status.QueueWarningMessage("Gather Connectivity Resources not implemented yet")
}
fmt.Println()
return nil
}

func checkGatherArguments() error {
func gatherDiscovery(status *cli.Status, dataType string) error {
switch dataType {
case Logs:
status.QueueWarningMessage("Gather ServiceDiscovery Logs not implemented yet")
case Resources:
status.QueueWarningMessage("Gather ServiceDiscovery Resources not implemented yet")
}
return nil
}

func gatherBroker(status *cli.Status, dataType string) error {
if dataType == Resources {
status.QueueWarningMessage("Gather Broker Resources not implemented yet")
}
return nil
}

func gatherOperator(status *cli.Status, dataType string) error {
switch dataType {
case Logs:
status.QueueWarningMessage("Gather Operator Logs not implemented yet")
case Resources:
status.QueueWarningMessage("Gather Operator Resources not implemented yet")
}
return nil
}

func checkGatherArguments() error {
gatherTypeList := strings.Split(gatherType, ",")
for _, arg := range gatherTypeList {
if _, found := gatherTypeFlags[arg]; !found {
Expand Down
2 changes: 2 additions & 0 deletions pkg/subctl/components/consts.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,6 @@ const (
Connectivity = "connectivity"
ServiceDiscovery = "service-discovery"
Globalnet = "globalnet"
Broker = "broker"
Operator = "operator"
)

0 comments on commit 148f091

Please sign in to comment.