Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ( Root = &cobra.Command{ Use: "honey", SilenceUsage: true, SilenceErrors: true, Short: "DevOps tool to help find an instance in sea of clouds", Version: version, PersistentPreRunE: func(cmd *cobra.Command, args []string) error { if err := cmd.RegisterFlagCompletionFunc("k8s-namespace", func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { getter := genericclioptions.NewConfigFlags(true) flag := cmd.Flag("k8s-context").Value.String() if flag != "" { getter.Context = &flag } factory := cmdutil.NewFactory(getter) if client, err := factory.KubernetesClientSet(); err == nil { to := int64(3) cobra.CompDebugln(fmt.Sprintf("About to call kube client for namespaces with timeout of: %d", to), true) nsNames := []string{} if namespaces, err := client.CoreV1().Namespaces().List(context.Background(), metav1.ListOptions{TimeoutSeconds: &to}); err == nil { for _, ns := range namespaces.Items { if strings.HasPrefix(ns.Name, toComplete) { nsNames = append(nsNames, ns.Name) } } return nsNames, cobra.ShellCompDirectiveNoFileComp } } return nil, cobra.ShellCompDirectiveDefault }); err != nil { return err } return cmd.RegisterFlagCompletionFunc("k8s-context", func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { cobra.CompDebugln("About to get the different kube-contexts", true) loadingRules := clientcmd.NewDefaultClientConfigLoadingRules() if config, err := clientcmd.NewNonInteractiveDeferredLoadingClientConfig( loadingRules, &clientcmd.ConfigOverrides{}).RawConfig(); err == nil { ctxs := []string{} for name := range config.Contexts { if strings.HasPrefix(name, toComplete) { ctxs = append(ctxs, name) } } return ctxs, cobra.ShellCompDirectiveNoFileComp } return nil, cobra.ShellCompDirectiveNoFileComp }) }, RunE: func(cmd *cobra.Command, args []string) error { if len(args) > 0 { re, err := regexp.Compile(args[0]) if err != nil { return errors.Wrap(err, "Failed to compile flags regexp") } flagsRe = re filter = args[0] } ctx := context.TODO() ci := place.GetConfig(ctx) backends, err := ci.Backends() if err != nil { return err } if len(backends) == 0 { return errors.New("oops you must specify at least one backend") } defer operations.CacheDB.Close() instances, err := operations.Find(context.TODO(), backends, filter) if err != nil { return err } return printers.Print(&printers.PrintInput{ Data: instances, Format: ci.OutFormat, NoColor: ci.NoColor, }) }, } )
Functions ¶
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.