From a582d444c5c53f25d7172947c690b35cad2cc176 Mon Sep 17 00:00:00 2001 From: HOLLEVILLE Matthis <99146727+matthisholleville@users.noreply.github.com> Date: Mon, 10 Apr 2023 07:49:22 +0200 Subject: [PATCH 1/7] fix: use hpa namespace instead analyzer namespace (#230) Signed-off-by: Matthis Holleville --- pkg/analyzer/hpa.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/pkg/analyzer/hpa.go b/pkg/analyzer/hpa.go index 6f22a44..70a3666 100644 --- a/pkg/analyzer/hpa.go +++ b/pkg/analyzer/hpa.go @@ -2,6 +2,7 @@ package analyzer import ( "fmt" + "github.com/k8sgpt-ai/k8sgpt/pkg/util" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) @@ -26,22 +27,22 @@ func (HpaAnalyzer) Analyze(a Analyzer) ([]Result, error) { switch scaleTargetRef.Kind { case "Deployment": - _, err := a.Client.GetClient().AppsV1().Deployments(a.Namespace).Get(a.Context, scaleTargetRef.Name, metav1.GetOptions{}) + _, err := a.Client.GetClient().AppsV1().Deployments(hpa.Namespace).Get(a.Context, scaleTargetRef.Name, metav1.GetOptions{}) if err != nil { scaleTargetRefNotFound = true } case "ReplicationController": - _, err := a.Client.GetClient().CoreV1().ReplicationControllers(a.Namespace).Get(a.Context, scaleTargetRef.Name, metav1.GetOptions{}) + _, err := a.Client.GetClient().CoreV1().ReplicationControllers(hpa.Namespace).Get(a.Context, scaleTargetRef.Name, metav1.GetOptions{}) if err != nil { scaleTargetRefNotFound = true } case "ReplicaSet": - _, err := a.Client.GetClient().AppsV1().ReplicaSets(a.Namespace).Get(a.Context, scaleTargetRef.Name, metav1.GetOptions{}) + _, err := a.Client.GetClient().AppsV1().ReplicaSets(hpa.Namespace).Get(a.Context, scaleTargetRef.Name, metav1.GetOptions{}) if err != nil { scaleTargetRefNotFound = true } case "StatefulSet": - _, err := a.Client.GetClient().AppsV1().StatefulSets(a.Namespace).Get(a.Context, scaleTargetRef.Name, metav1.GetOptions{}) + _, err := a.Client.GetClient().AppsV1().StatefulSets(hpa.Namespace).Get(a.Context, scaleTargetRef.Name, metav1.GetOptions{}) if err != nil { scaleTargetRefNotFound = true } From ba01bd4b6ecd64fbe249be54f20471afc6339208 Mon Sep 17 00:00:00 2001 From: Aris Boutselis Date: Mon, 10 Apr 2023 12:54:51 +0100 Subject: [PATCH 2/7] docs: add statefulSet analyzer in the docs. (#233) Signed-off-by: Aris Boutselis --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 9b83e21..14e7a74 100644 --- a/README.md +++ b/README.md @@ -140,6 +140,7 @@ you will be able to write your own analyzers. - [x] serviceAnalyzer - [x] eventAnalyzer - [x] ingressAnalyzer +- [x] statefulSetAnalyzer #### Optional @@ -254,4 +255,4 @@ Find us on [Slack](https://k8sgpt.slack.com/) - \ No newline at end of file + From ab55f157ef026502d29eadf5ad83e917fe085a6c Mon Sep 17 00:00:00 2001 From: Thomas Stadler Date: Mon, 10 Apr 2023 20:01:55 +0200 Subject: [PATCH 3/7] fix: exit progressbar on error (#99) Signed-off-by: Thomas Stadler --- pkg/ai/openai.go | 1 - pkg/analysis/analysis.go | 10 +++++----- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/pkg/ai/openai.go b/pkg/ai/openai.go index 49bf39a..1da3841 100644 --- a/pkg/ai/openai.go +++ b/pkg/ai/openai.go @@ -77,7 +77,6 @@ func (a *OpenAIClient) Parse(ctx context.Context, prompt []string, nocache bool) response, err := a.GetCompletion(ctx, inputKey) if err != nil { - color.Red("error getting completion: %v", err) return "", err } diff --git a/pkg/analysis/analysis.go b/pkg/analysis/analysis.go index 942fff7..9f04bcb 100644 --- a/pkg/analysis/analysis.go +++ b/pkg/analysis/analysis.go @@ -4,7 +4,6 @@ import ( "context" "encoding/json" "fmt" - "os" "strings" "github.com/fatih/color" @@ -143,13 +142,14 @@ func (a *Analysis) GetAIResults(output string) error { for index, analysis := range a.Results { parsedText, err := a.AIClient.Parse(a.Context, analysis.Error, a.NoCache) if err != nil { + bar.Exit() + // Check for exhaustion if strings.Contains(err.Error(), "status code: 429") { - color.Red("Exhausted API quota. Please try again later") - os.Exit(1) + return fmt.Errorf("exhausted API quota for AI provider %s: %v", a.AIClient.GetName(), err) + } else { + return fmt.Errorf("failed while calling AI provider %s: %v", a.AIClient.GetName(), err) } - color.Red("Error: %v", err) - continue } analysis.Details = parsedText if output != "json" { From 992b107c2d906663bb22998004a0859bccd45c77 Mon Sep 17 00:00:00 2001 From: Alex Jones Date: Mon, 10 Apr 2023 20:25:45 +0100 Subject: [PATCH 4/7] chore: adding k8sgpt-approvers (#238) * chore: adding k8sgpt-approvers * Update CODEOWNERS Signed-off-by: Alex Jones --------- Signed-off-by: Alex Jones Co-authored-by: Thomas Schuetz <38893055+thschue@users.noreply.github.com> --- .github/CODEOWNERS | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index 3c61820..f35a326 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -9,4 +9,4 @@ # Unless a later match takes precedence, these owners will be requested for # review when someone opens a pull request. -* @k8sgpt-ai/maintainers \ No newline at end of file +* @k8sgpt-ai/maintainers @k8sgpt-ai/k8sgpt-approvers From 3845d4747f4e0fc823d1bcf631d6ecdd5e4ccd03 Mon Sep 17 00:00:00 2001 From: Thomas Stadler Date: Mon, 10 Apr 2023 22:30:10 +0200 Subject: [PATCH 5/7] chore: fix mistake introduced by ab55f157 (#240) Signed-off-by: Thomas Stadler --- pkg/analysis/analysis.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/pkg/analysis/analysis.go b/pkg/analysis/analysis.go index 9f04bcb..6dd54b6 100644 --- a/pkg/analysis/analysis.go +++ b/pkg/analysis/analysis.go @@ -142,7 +142,11 @@ func (a *Analysis) GetAIResults(output string) error { for index, analysis := range a.Results { parsedText, err := a.AIClient.Parse(a.Context, analysis.Error, a.NoCache) if err != nil { - bar.Exit() + // FIXME: can we avoid checking if output is json multiple times? + // maybe implement the progress bar better? + if output != "json" { + bar.Exit() + } // Check for exhaustion if strings.Contains(err.Error(), "status code: 429") { From 21dc61c04f4d772b5147b38a4d28e5dbddf5cdd8 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Tue, 11 Apr 2023 07:36:58 +0200 Subject: [PATCH 6/7] chore(deps): update google-github-actions/release-please-action digest to f7edb9e (#241) Signed-off-by: Renovate Bot Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> --- .github/workflows/release.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index c0e656c..bb2526f 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -25,7 +25,7 @@ jobs: - name: Checkout uses: actions/checkout@8f4b7f84864484a7bf31766abe9204da3cbe65b3 # v3 - - uses: google-github-actions/release-please-action@ee9822ec2c397e8a364d634464339ac43a06e042 # v3 + - uses: google-github-actions/release-please-action@f7edb9e61420a022c0f1123edaf342d7e127df92 # v3 id: release with: command: manifest From dd5824f4365b01e3c501d8b5cda914dff138e03d Mon Sep 17 00:00:00 2001 From: Matthis Holleville Date: Tue, 11 Apr 2023 19:20:49 +0200 Subject: [PATCH 7/7] feat: return errors if filter specified by flag does not exist. Signed-off-by: Matthis Holleville --- pkg/analysis/analysis.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pkg/analysis/analysis.go b/pkg/analysis/analysis.go index 6dd54b6..c9c1697 100644 --- a/pkg/analysis/analysis.go +++ b/pkg/analysis/analysis.go @@ -3,6 +3,7 @@ package analysis import ( "context" "encoding/json" + "errors" "fmt" "strings" @@ -72,6 +73,8 @@ func (a *Analysis) RunAnalysis() error { return err } a.Results = append(a.Results, results...) + } else { + return errors.New(fmt.Sprintf("\"%s\" filter does not exist. Please run k8sgpt filters list.", filter)) } } return nil