diff --git a/README.md b/README.md
index e330ae5..f61e15e 100644
--- a/README.md
+++ b/README.md
@@ -6,7 +6,7 @@
AI Powered Kubernetes debugging for SRE, Platform and DevOps teams.
-
+
## What is k8sgpt?
diff --git a/images/demo2.gif b/images/demo2.gif
new file mode 100644
index 0000000..0d360aa
Binary files /dev/null and b/images/demo2.gif differ
diff --git a/pkg/analyzer/analyzer.go b/pkg/analyzer/analyzer.go
index c4ec6b5..1e504a5 100644
--- a/pkg/analyzer/analyzer.go
+++ b/pkg/analyzer/analyzer.go
@@ -2,6 +2,7 @@ package analyzer
import (
"context"
+ "encoding/base64"
"fmt"
"strings"
"time"
@@ -10,6 +11,7 @@ import (
"github.com/fatih/color"
"github.com/k8sgpt-ai/k8sgpt/pkg/ai"
"github.com/k8sgpt-ai/k8sgpt/pkg/kubernetes"
+ "github.com/spf13/viper"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
@@ -50,20 +52,51 @@ func RunAnalysis(ctx context.Context, client *kubernetes.Client, aiClient *ai.Cl
}
}
- for key, value := range brokenPods {
- fmt.Printf("%s: %s\n", color.YellowString(key), color.RedString(value[0]))
+ count := 0
+ for key, value := range brokenPods {
+ fmt.Printf("%s: %s: %s\n", color.CyanString("%d", count), color.YellowString(key), color.RedString(value[0]))
+ count++
if explain {
s := spinner.New(spinner.CharSets[35], 100*time.Millisecond) // Build our new spinner
s.Start()
- response, err := aiClient.GetCompletion(ctx, strings.Join(value, " "))
- s.Stop()
- if err != nil {
- return err
+ inputValue := strings.Join(value, " ")
+
+ // Check for cached data
+ sEnc := base64.StdEncoding.EncodeToString([]byte(inputValue))
+ // find in viper cache
+ if viper.IsSet(sEnc) {
+ s.Stop()
+ // retrieve data from cache
+ response := viper.GetString(sEnc)
+ if response == "" {
+ color.Red("error retrieving cached data")
+ continue
+ }
+ output, err := base64.StdEncoding.DecodeString(response)
+ if err != nil {
+ color.Red("error decoding cached data: %v", err)
+ continue
+ }
+
+ color.Green(string(output))
+ continue
}
- fmt.Printf("%s\n", color.GreenString(response))
+ response, err := aiClient.GetCompletion(ctx, inputValue)
+ s.Stop()
+ if err != nil {
+ color.Red("error getting completion: %v", err)
+ continue
+ }
+
+ if !viper.IsSet(sEnc) {
+ viper.Set(sEnc, base64.StdEncoding.EncodeToString([]byte(response)))
+ if err := viper.WriteConfig(); err != nil {
+ return err
+ }
+ }
}
}