github.com/iter8-tools/iter8@v1.1.2/cmd/root.go (about)

     1  package cmd
     2  
     3  import (
     4  	"github.com/iter8-tools/iter8/controllers/k8sclient"
     5  	"github.com/iter8-tools/iter8/driver"
     6  
     7  	"github.com/iter8-tools/iter8/base/log"
     8  	"github.com/sirupsen/logrus"
     9  	"github.com/spf13/cobra"
    10  	"helm.sh/helm/v3/pkg/cli"
    11  )
    12  
    13  var (
    14  	// default log level for Iter8 CLI
    15  	logLevel = "info"
    16  	// Default Helm and Kubernetes settings
    17  	settings = cli.New()
    18  	// KubeDriver used by actions package
    19  	kd = driver.NewKubeDriver(settings)
    20  	// kubeclient is the client used for controllers package
    21  	kubeClient k8sclient.Interface
    22  )
    23  
    24  // rootCmd represents the base command when called without any subcommands
    25  var rootCmd = &cobra.Command{
    26  	Use:   "iter8",
    27  	Short: "Kubernetes release optimizer",
    28  	Long: `
    29  Iter8 is the Kubernetes release optimizer built for DevOps, MLOps, SRE and data science teams. Iter8 makes it easy to ensure that Kubernetes apps and ML models perform well and maximize business value.
    30  `,
    31  	PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
    32  		ll, err := logrus.ParseLevel(logLevel)
    33  		if err != nil {
    34  			log.Logger.Error(err)
    35  			return err
    36  		}
    37  		log.Logger.Level = ll
    38  		return nil
    39  	},
    40  }
    41  
    42  // Execute adds all child commands to the root command and sets flags appropriately.
    43  // This is called by main.main(). It only needs to happen once to the rootCmd.
    44  func Execute() {
    45  	cobra.CheckErr(rootCmd.Execute())
    46  }
    47  
    48  // initialize Iter8 CLI root command and add all subcommands
    49  func init() {
    50  	// disable completion command for now
    51  	rootCmd.CompletionOptions.DisableDefaultCmd = true
    52  	rootCmd.PersistentFlags().StringVarP(&logLevel, "loglevel", "l", "info", "trace, debug, info, warning, error, fatal, panic")
    53  	rootCmd.SilenceErrors = true // will get printed in Execute() (by cobra.CheckErr())
    54  
    55  	// add docs
    56  	rootCmd.AddCommand(newDocsCmd())
    57  
    58  	// add k
    59  	rootCmd.AddCommand(kcmd)
    60  
    61  	// add version
    62  	rootCmd.AddCommand(newVersionCmd())
    63  
    64  	// add controllers
    65  	rootCmd.AddCommand(newControllersCmd(nil, kubeClient))
    66  
    67  }