mirror of
https://github.com/k8sgpt-ai/k8sgpt.git
synced 2025-09-03 08:15:45 +00:00
@@ -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
|
# Ensure KUBECONFIG env is set to an active Kubernetes cluster
|
||||||
k8sgpt init
|
|
||||||
k8sgpt auth
|
k8sgpt auth
|
||||||
k8sgpt find problems
|
k8sgpt find problems
|
||||||
# for more detail
|
# for more detail
|
||||||
k8s find problems --explain
|
k8s find problems --explain
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## Upcoming major milestones
|
||||||
|
|
||||||
|
- [] Multiple AI backend support
|
||||||
|
- [] Custom AI/ML model backend support
|
||||||
|
- [] Custom analyzers
|
||||||
|
|
||||||
### What about kubectl-ai?
|
### 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.
|
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.
|
||||||
|
@@ -24,8 +24,8 @@ var AuthCmd = &cobra.Command{
|
|||||||
Run: func(cmd *cobra.Command, args []string) {
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
|
|
||||||
backendType := viper.GetString("backend_type")
|
backendType := viper.GetString("backend_type")
|
||||||
if backendType == "" {
|
if backendType == "" && backend == "" {
|
||||||
color.Red("No backend set. Please run k8sgpt init")
|
color.Red("No backend set. Please run k8sgpt auth")
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
// override the default backend if a flag is provided
|
// override the default backend if a flag is provided
|
||||||
|
@@ -13,7 +13,10 @@ import (
|
|||||||
"github.com/spf13/viper"
|
"github.com/spf13/viper"
|
||||||
)
|
)
|
||||||
|
|
||||||
var explain bool
|
var (
|
||||||
|
explain bool
|
||||||
|
backend string
|
||||||
|
)
|
||||||
|
|
||||||
// problemsCmd represents the problems command
|
// problemsCmd represents the problems command
|
||||||
var problemsCmd = &cobra.Command{
|
var problemsCmd = &cobra.Command{
|
||||||
@@ -26,9 +29,13 @@ var problemsCmd = &cobra.Command{
|
|||||||
// get backend from file
|
// get backend from file
|
||||||
backendType := viper.GetString("backend_type")
|
backendType := viper.GetString("backend_type")
|
||||||
if backendType == "" {
|
if backendType == "" {
|
||||||
color.Red("No backend set. Please run k8sgpt init")
|
color.Red("No backend set. Please run k8sgpt auth")
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
// override the default backend if a flag is provided
|
||||||
|
if backend != "" {
|
||||||
|
backendType = backend
|
||||||
|
}
|
||||||
// get the token with viper
|
// get the token with viper
|
||||||
token := viper.GetString(fmt.Sprintf("%s_key", backendType))
|
token := viper.GetString(fmt.Sprintf("%s_key", backendType))
|
||||||
// check if nil
|
// check if nil
|
||||||
@@ -64,7 +71,8 @@ var problemsCmd = &cobra.Command{
|
|||||||
func init() {
|
func init() {
|
||||||
|
|
||||||
problemsCmd.Flags().BoolVarP(&explain, "explain", "e", false, "Explain the problem to me")
|
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)
|
FindCmd.AddCommand(problemsCmd)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -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")
|
|
||||||
}
|
|
@@ -6,7 +6,6 @@ import (
|
|||||||
"github.com/fatih/color"
|
"github.com/fatih/color"
|
||||||
"github.com/k8sgpt-ai/k8sgpt/cmd/auth"
|
"github.com/k8sgpt-ai/k8sgpt/cmd/auth"
|
||||||
"github.com/k8sgpt-ai/k8sgpt/cmd/find"
|
"github.com/k8sgpt-ai/k8sgpt/cmd/find"
|
||||||
i "github.com/k8sgpt-ai/k8sgpt/cmd/init"
|
|
||||||
"github.com/k8sgpt-ai/k8sgpt/pkg/kubernetes"
|
"github.com/k8sgpt-ai/k8sgpt/pkg/kubernetes"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
"github.com/spf13/viper"
|
"github.com/spf13/viper"
|
||||||
@@ -45,7 +44,6 @@ func init() {
|
|||||||
// will be global for your application.
|
// will be global for your application.
|
||||||
rootCmd.AddCommand(auth.AuthCmd)
|
rootCmd.AddCommand(auth.AuthCmd)
|
||||||
rootCmd.AddCommand(find.FindCmd)
|
rootCmd.AddCommand(find.FindCmd)
|
||||||
rootCmd.AddCommand(i.InitCmd)
|
|
||||||
rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is $HOME/.k8sgpt.git.yaml)")
|
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(&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.")
|
rootCmd.PersistentFlags().StringVar(&kubeconfig, "kubeconfig", "", "Path to a kubeconfig. Only required if out-of-cluster.")
|
||||||
|
Reference in New Issue
Block a user