diff --git a/cmd/find/problems.go b/cmd/analyze/analyze.go similarity index 83% rename from cmd/find/problems.go rename to cmd/analyze/analyze.go index 7a6c947e3d..cc159d157c 100644 --- a/cmd/find/problems.go +++ b/cmd/analyze/analyze.go @@ -1,4 +1,4 @@ -package find +package analyze import ( "context" @@ -20,9 +20,9 @@ var ( output string ) -// problemsCmd represents the problems command -var problemsCmd = &cobra.Command{ - Use: "problems", +// AnalyzeCmd represents the problems command +var AnalyzeCmd = &cobra.Command{ + Use: "analyze", Short: "This command will find problems within your Kubernetes cluster", Long: `This command will find problems within your Kubernetes cluster and provide you with a list of issues that need to be resolved`, @@ -89,11 +89,10 @@ var problemsCmd = &cobra.Command{ func init() { - problemsCmd.Flags().BoolVarP(&explain, "explain", "e", false, "Explain the problem to me") + AnalyzeCmd.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") + AnalyzeCmd.Flags().StringVarP(&backend, "backend", "b", "openai", "Backend AI provider") // output as json - problemsCmd.Flags().StringVarP(&output, "output", "o", "text", "Output format (text, json)") - FindCmd.AddCommand(problemsCmd) + AnalyzeCmd.Flags().StringVarP(&output, "output", "o", "text", "Output format (text, json)") } diff --git a/cmd/find/find.go b/cmd/find/find.go deleted file mode 100644 index 7c5387c1fc..0000000000 --- a/cmd/find/find.go +++ /dev/null @@ -1,19 +0,0 @@ -package find - -import ( - "github.com/spf13/cobra" -) - -// findCmd represents the find command -var FindCmd = &cobra.Command{ - Use: "find", - Short: "Find issues within your Kubernetes cluster", - Long: ``, - Run: func(cmd *cobra.Command, args []string) { - cmd.Help() - }, -} - -func init() { - -} diff --git a/cmd/root.go b/cmd/root.go index 4bd9df63b0..a359a88b01 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -4,8 +4,8 @@ import ( "os" "github.com/fatih/color" + "github.com/k8sgpt-ai/k8sgpt/cmd/analyze" "github.com/k8sgpt-ai/k8sgpt/cmd/auth" - "github.com/k8sgpt-ai/k8sgpt/cmd/find" "github.com/k8sgpt-ai/k8sgpt/pkg/kubernetes" "github.com/spf13/cobra" "github.com/spf13/viper" @@ -43,7 +43,7 @@ func init() { // Cobra supports persistent flags, which, if defined here, // will be global for your application. rootCmd.AddCommand(auth.AuthCmd) - rootCmd.AddCommand(find.FindCmd) + rootCmd.AddCommand(analyze.AnalyzeCmd) 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.") diff --git a/pkg/analyzer/podAnalyzer.go b/pkg/analyzer/podAnalyzer.go index ec01d08650..354677f319 100644 --- a/pkg/analyzer/podAnalyzer.go +++ b/pkg/analyzer/podAnalyzer.go @@ -52,7 +52,7 @@ func AnalyzePod(ctx context.Context, client *kubernetes.Client, aiClient ai.IAI, // parse the event log and append details evt, err := FetchLatestPodEvent(ctx, client, &pod) - if err != nil { + if err != nil || evt == nil { continue } if evt.Reason == "FailedCreatePodSandBox" {