mirror of
https://github.com/k8sgpt-ai/k8sgpt.git
synced 2025-08-31 06:35:22 +00:00
Merge pull request #17 from k8sgpt-ai/chore/tidying
chore: tidying up packages
This commit is contained in:
@@ -8,9 +8,9 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
|
|
||||||
"github.com/fatih/color"
|
"github.com/fatih/color"
|
||||||
|
"github.com/k8sgpt-ai/k8sgpt/pkg/ai"
|
||||||
"github.com/k8sgpt-ai/k8sgpt/pkg/analyzer"
|
"github.com/k8sgpt-ai/k8sgpt/pkg/analyzer"
|
||||||
"github.com/k8sgpt-ai/k8sgpt/pkg/client"
|
"github.com/k8sgpt-ai/k8sgpt/pkg/kubernetes"
|
||||||
"github.com/k8sgpt-ai/k8sgpt/pkg/openai"
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
"github.com/spf13/viper"
|
"github.com/spf13/viper"
|
||||||
)
|
)
|
||||||
@@ -26,7 +26,7 @@ var problemsCmd = &cobra.Command{
|
|||||||
Run: func(cmd *cobra.Command, args []string) {
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
|
|
||||||
// Initialise the openAI client
|
// Initialise the openAI client
|
||||||
openAIClient, err := openai.NewClient()
|
openAIClient, err := ai.NewClient()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
color.Red("Error: %v", err)
|
color.Red("Error: %v", err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
@@ -34,9 +34,12 @@ var problemsCmd = &cobra.Command{
|
|||||||
|
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
// Get kubernetes client from viper
|
// Get kubernetes client from viper
|
||||||
client := viper.Get("kubernetesClient").(*client.Client)
|
client := viper.Get("kubernetesClient").(*kubernetes.Client)
|
||||||
|
|
||||||
analyzer.RunAnalysis(ctx, client, openAIClient, explain)
|
if err := analyzer.RunAnalysis(ctx, client, openAIClient, explain); err != nil {
|
||||||
|
color.Red("Error: %v", err)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -9,7 +9,7 @@ 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"
|
||||||
"github.com/k8sgpt-ai/k8sgpt/pkg/client"
|
"github.com/k8sgpt-ai/k8sgpt/pkg/kubernetes"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
"github.com/spf13/viper"
|
"github.com/spf13/viper"
|
||||||
)
|
)
|
||||||
@@ -56,7 +56,7 @@ func init() {
|
|||||||
rootCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
|
rootCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
|
||||||
|
|
||||||
//Initialise the kubeconfig
|
//Initialise the kubeconfig
|
||||||
kubernetesClient, err := client.NewClient(masterURL, kubeconfig)
|
kubernetesClient, err := kubernetes.NewClient(masterURL, kubeconfig)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
color.Red("Error initialising kubernetes client: %v", err)
|
color.Red("Error initialising kubernetes client: %v", err)
|
||||||
}
|
}
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
package openai
|
package ai
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
@@ -3,24 +3,22 @@ package analyzer
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/briandowns/spinner"
|
"github.com/briandowns/spinner"
|
||||||
"github.com/fatih/color"
|
"github.com/fatih/color"
|
||||||
"github.com/k8sgpt-ai/k8sgpt/pkg/client"
|
"github.com/k8sgpt-ai/k8sgpt/pkg/ai"
|
||||||
ai "github.com/k8sgpt-ai/k8sgpt/pkg/openai"
|
"github.com/k8sgpt-ai/k8sgpt/pkg/kubernetes"
|
||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
)
|
)
|
||||||
|
|
||||||
func RunAnalysis(ctx context.Context, client *client.Client, openAIClient *ai.Client, explain bool) {
|
func RunAnalysis(ctx context.Context, client *kubernetes.Client, aiClient *ai.Client, explain bool) error {
|
||||||
|
|
||||||
// search all namespaces for pods that are not running
|
// search all namespaces for pods that are not running
|
||||||
list, err := client.GetClient().CoreV1().Pods("").List(ctx, metav1.ListOptions{})
|
list, err := client.GetClient().CoreV1().Pods("").List(ctx, metav1.ListOptions{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
color.Red("Error: %v", err)
|
return err
|
||||||
os.Exit(1)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var brokenPods = map[string][]string{}
|
var brokenPods = map[string][]string{}
|
||||||
@@ -59,14 +57,15 @@ func RunAnalysis(ctx context.Context, client *client.Client, openAIClient *ai.Cl
|
|||||||
s := spinner.New(spinner.CharSets[35], 100*time.Millisecond) // Build our new spinner
|
s := spinner.New(spinner.CharSets[35], 100*time.Millisecond) // Build our new spinner
|
||||||
s.Start()
|
s.Start()
|
||||||
|
|
||||||
response, err := openAIClient.GetCompletion(ctx, strings.Join(value, " "))
|
response, err := aiClient.GetCompletion(ctx, strings.Join(value, " "))
|
||||||
s.Stop()
|
s.Stop()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
color.Red("Error: %v", err)
|
return err
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Printf("%s\n", color.GreenString(response))
|
fmt.Printf("%s\n", color.GreenString(response))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
package client
|
package kubernetes
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"k8s.io/client-go/kubernetes"
|
"k8s.io/client-go/kubernetes"
|
Reference in New Issue
Block a user