-
Notifications
You must be signed in to change notification settings - Fork 612
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into feature/add-tests-to-hpa-analyzer
- Loading branch information
Showing
18 changed files
with
274 additions
and
277 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,20 @@ | ||
package ai | ||
|
||
import "context" | ||
import ( | ||
"context" | ||
) | ||
|
||
type IAI interface { | ||
Configure(token string, language string) error | ||
GetCompletion(ctx context.Context, prompt string) (string, error) | ||
Parse(ctx context.Context, prompt []string, nocache bool) (string, error) | ||
} | ||
|
||
func NewClient(provider string) IAI { | ||
switch provider { | ||
case "openai": | ||
return &OpenAIClient{} | ||
default: | ||
return &OpenAIClient{} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
package analysis | ||
|
||
import ( | ||
"context" | ||
"github.com/k8sgpt-ai/k8sgpt/pkg/ai" | ||
"github.com/k8sgpt-ai/k8sgpt/pkg/analyzer" | ||
"github.com/k8sgpt-ai/k8sgpt/pkg/kubernetes" | ||
"github.com/spf13/viper" | ||
) | ||
|
||
type Analysis struct { | ||
Context context.Context | ||
Filters []string | ||
Client *kubernetes.Client | ||
AIClient ai.IAI | ||
Results []analyzer.Result | ||
Namespace string | ||
NoCache bool | ||
Explain bool | ||
} | ||
|
||
func (a *Analysis) RunAnalysis() error { | ||
|
||
activeFilters := viper.GetStringSlice("active_filters") | ||
|
||
analyzerMap := analyzer.GetAnalyzerMap() | ||
|
||
analyzerConfig := analyzer.Analyzer{ | ||
Client: a.Client, | ||
Context: a.Context, | ||
Namespace: a.Namespace, | ||
AIClient: a.AIClient, | ||
} | ||
|
||
// if there are no filters selected and no active_filters then run all of them | ||
if len(a.Filters) == 0 && len(activeFilters) == 0 { | ||
for _, analyzer := range analyzerMap { | ||
results, err := analyzer.Analyze(analyzerConfig) | ||
if err != nil { | ||
return err | ||
} | ||
a.Results = append(a.Results, results...) | ||
} | ||
return nil | ||
} | ||
|
||
// if the filters flag is specified | ||
if len(a.Filters) != 0 { | ||
for _, filter := range a.Filters { | ||
if analyzer, ok := analyzerMap[filter]; ok { | ||
results, err := analyzer.Analyze(analyzerConfig) | ||
if err != nil { | ||
return err | ||
} | ||
a.Results = append(a.Results, results...) | ||
} | ||
} | ||
return nil | ||
} | ||
|
||
// use active_filters | ||
for _, filter := range activeFilters { | ||
if analyzer, ok := analyzerMap[filter]; ok { | ||
results, err := analyzer.Analyze(analyzerConfig) | ||
if err != nil { | ||
return err | ||
} | ||
a.Results = append(a.Results, results...) | ||
} | ||
} | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.