From c8385531e6c486d7f09c19c8685ea3d506859138 Mon Sep 17 00:00:00 2001 From: Alex Jones Date: Fri, 24 Mar 2023 12:33:59 +0000 Subject: [PATCH] updated Signed-off-by: Alex Jones --- README.md | 7 ++++++- cmd/auth/auth.go | 4 ++-- cmd/find/problems.go | 14 +++++++++++--- cmd/init/init.go | 42 ------------------------------------------ cmd/root.go | 2 -- 5 files changed, 19 insertions(+), 50 deletions(-) delete mode 100644 cmd/init/init.go diff --git a/README.md b/README.md index bd6e230..3b7174c 100644 --- a/README.md +++ b/README.md @@ -20,13 +20,18 @@ It has SRE experience codified into it's analyzers and helps to pull out the mos ``` # Ensure KUBECONFIG env is set to an active Kubernetes cluster -k8sgpt init k8sgpt auth k8sgpt find problems # for more detail k8s find problems --explain ``` +## Upcoming major milestones + +- [] Multiple AI backend support +- [] Custom AI/ML model backend support +- [] Custom analyzers + ### What about kubectl-ai? The the kubectl-ai [project](https://github.com/sozercan/kubectl-ai) uses AI to create manifests and apply them to the cluster. It is not what we are trying to do here, it is focusing on writing YAML manifests. diff --git a/cmd/auth/auth.go b/cmd/auth/auth.go index fab9d25..87ff6b6 100644 --- a/cmd/auth/auth.go +++ b/cmd/auth/auth.go @@ -24,8 +24,8 @@ var AuthCmd = &cobra.Command{ Run: func(cmd *cobra.Command, args []string) { backendType := viper.GetString("backend_type") - if backendType == "" { - color.Red("No backend set. Please run k8sgpt init") + if backendType == "" && backend == "" { + color.Red("No backend set. Please run k8sgpt auth") os.Exit(1) } // override the default backend if a flag is provided diff --git a/cmd/find/problems.go b/cmd/find/problems.go index 22aac13..2c6de8e 100644 --- a/cmd/find/problems.go +++ b/cmd/find/problems.go @@ -13,7 +13,10 @@ import ( "github.com/spf13/viper" ) -var explain bool +var ( + explain bool + backend string +) // problemsCmd represents the problems command var problemsCmd = &cobra.Command{ @@ -26,9 +29,13 @@ var problemsCmd = &cobra.Command{ // get backend from file backendType := viper.GetString("backend_type") if backendType == "" { - color.Red("No backend set. Please run k8sgpt init") + color.Red("No backend set. Please run k8sgpt auth") os.Exit(1) } + // override the default backend if a flag is provided + if backend != "" { + backendType = backend + } // get the token with viper token := viper.GetString(fmt.Sprintf("%s_key", backendType)) // check if nil @@ -64,7 +71,8 @@ var problemsCmd = &cobra.Command{ func init() { problemsCmd.Flags().BoolVarP(&explain, "explain", "e", false, "Explain the problem to me") - + // add flag for backend + problemsCmd.Flags().StringVarP(&backend, "backend", "b", "openai", "Backend AI provider") FindCmd.AddCommand(problemsCmd) } diff --git a/cmd/init/init.go b/cmd/init/init.go deleted file mode 100644 index b3d2557..0000000 --- a/cmd/init/init.go +++ /dev/null @@ -1,42 +0,0 @@ -package init - -import ( - "os" - - "github.com/fatih/color" - "github.com/spf13/cobra" - "github.com/spf13/viper" -) - -var ( - backend string -) - -// authCmd represents the auth command -var InitCmd = &cobra.Command{ - Use: "init", - Short: "Initialise k8sgpt with a backend AI provider", - Long: `Currently only OpenAI is supported.`, - Run: func(cmd *cobra.Command, args []string) { - - /* - This is largely a placeholder for now. In the future we will support - multiple backends and this will allow us to set the backend we want to use. - */ - if backend != "openai" { - color.Yellow("Only OpenAI is supported at the moment") - } - viper.Set("backend_type", backend) - if err := viper.WriteConfig(); err != nil { - color.Red("Error writing config file: %s", err.Error()) - os.Exit(1) - } - - color.Green("Backend set to %s", backend) - }, -} - -func init() { - // add flag for backend - InitCmd.Flags().StringVarP(&backend, "backend", "b", "openai", "Backend AI provider") -} diff --git a/cmd/root.go b/cmd/root.go index 7d7d4fa..4bd9df6 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -6,7 +6,6 @@ import ( "github.com/fatih/color" "github.com/k8sgpt-ai/k8sgpt/cmd/auth" "github.com/k8sgpt-ai/k8sgpt/cmd/find" - i "github.com/k8sgpt-ai/k8sgpt/cmd/init" "github.com/k8sgpt-ai/k8sgpt/pkg/kubernetes" "github.com/spf13/cobra" "github.com/spf13/viper" @@ -45,7 +44,6 @@ func init() { // will be global for your application. rootCmd.AddCommand(auth.AuthCmd) rootCmd.AddCommand(find.FindCmd) - rootCmd.AddCommand(i.InitCmd) rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is $HOME/.k8sgpt.git.yaml)") rootCmd.PersistentFlags().StringVar(&masterURL, "master", "", "The address of the Kubernetes API server. Overrides any value in kubeconfig. Only required if out-of-cluster.") rootCmd.PersistentFlags().StringVar(&kubeconfig, "kubeconfig", "", "Path to a kubeconfig. Only required if out-of-cluster.")