mirror of
https://github.com/k8sgpt-ai/k8sgpt.git
synced 2025-08-29 04:40:42 +00:00
example of an integration
Signed-off-by: Alex Jones <alexsimonjones@gmail.com>
This commit is contained in:
parent
1bc0f42f71
commit
2b14cae5a6
19
demo
Executable file
19
demo
Executable file
@ -0,0 +1,19 @@
|
||||
#!/bin/bash
|
||||
|
||||
########################
|
||||
# include the magic
|
||||
########################
|
||||
. demo-magic.sh
|
||||
|
||||
# hide the evidence
|
||||
clear
|
||||
|
||||
pe "./k8sgpt analyze --explain"
|
||||
|
||||
pe "./k8sgpt filter list"
|
||||
|
||||
pe "./k8sgpt integration list"
|
||||
|
||||
pe "./k8sgpt integration activate trivy"
|
||||
|
||||
pe "./k8sgpt analyze --filter VulnerabilityReport -o json | jq ."
|
@ -77,6 +77,11 @@ func (a *Analysis) textOutput() ([]byte, error) {
|
||||
output.WriteString(fmt.Sprintf("%s %s(%s)\n", color.CyanString("%d", n),
|
||||
color.YellowString(result.Name), color.CyanString(result.ParentObject)))
|
||||
for _, err := range result.Error {
|
||||
|
||||
if hasAIFailure(err.Text) {
|
||||
err.Text = "Unable to remediate issue. Please refer to the documentation for more information."
|
||||
}
|
||||
|
||||
output.WriteString(fmt.Sprintf("- %s %s\n", color.RedString("Error:"), color.RedString(err.Text)))
|
||||
if err.KubernetesDoc != "" {
|
||||
output.WriteString(fmt.Sprintf(" %s %s\n", color.RedString("Kubernetes Doc:"), color.RedString(err.KubernetesDoc)))
|
||||
@ -86,3 +91,7 @@ func (a *Analysis) textOutput() ([]byte, error) {
|
||||
}
|
||||
return []byte(output.String()), nil
|
||||
}
|
||||
|
||||
func hasAIFailure(text string) bool {
|
||||
return strings.Contains(text, "As an AI language model")
|
||||
}
|
||||
|
41
pkg/integration/alex/alex.go
Normal file
41
pkg/integration/alex/alex.go
Normal file
@ -0,0 +1,41 @@
|
||||
package alex
|
||||
|
||||
import (
|
||||
"github.com/k8sgpt-ai/k8sgpt/pkg/common"
|
||||
)
|
||||
|
||||
// implement the IIterator interface
|
||||
type Alex struct {
|
||||
}
|
||||
|
||||
func NewAlex() *Alex {
|
||||
return &Alex{}
|
||||
}
|
||||
|
||||
func (a *Alex) Deploy(namespace string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (a *Alex) UnDeploy(namespace string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (a *Alex) AddAnalyzer(analyzers *map[string]common.IAnalyzer) {
|
||||
|
||||
(*analyzers)["Alex"] = NewAlexAnalyzer()
|
||||
}
|
||||
|
||||
func (a *Alex) RemoveAnalyzer() error {
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (a *Alex) GetAnalyzerName() string {
|
||||
|
||||
return "alex"
|
||||
}
|
||||
|
||||
func (a *Alex) IsActivate() bool {
|
||||
|
||||
return true
|
||||
}
|
15
pkg/integration/alex/analyzer.go
Normal file
15
pkg/integration/alex/analyzer.go
Normal file
@ -0,0 +1,15 @@
|
||||
package alex
|
||||
|
||||
import "github.com/k8sgpt-ai/k8sgpt/pkg/common"
|
||||
|
||||
type AlexAnalyzer struct {
|
||||
}
|
||||
|
||||
func NewAlexAnalyzer() *AlexAnalyzer {
|
||||
return &AlexAnalyzer{}
|
||||
}
|
||||
|
||||
func (*AlexAnalyzer) Analyze(analysis common.Analyzer) ([]common.Result, error) {
|
||||
|
||||
return nil, nil
|
||||
}
|
@ -20,6 +20,7 @@ import (
|
||||
|
||||
"github.com/fatih/color"
|
||||
"github.com/k8sgpt-ai/k8sgpt/pkg/common"
|
||||
"github.com/k8sgpt-ai/k8sgpt/pkg/integration/alex"
|
||||
"github.com/k8sgpt-ai/k8sgpt/pkg/integration/trivy"
|
||||
"github.com/k8sgpt-ai/k8sgpt/pkg/util"
|
||||
"github.com/spf13/viper"
|
||||
@ -45,6 +46,7 @@ type Integration struct {
|
||||
|
||||
var integrations = map[string]IIntegration{
|
||||
"trivy": trivy.NewTrivy(),
|
||||
"alex": alex.NewAlex(),
|
||||
}
|
||||
|
||||
func NewIntegration() *Integration {
|
||||
|
@ -53,7 +53,7 @@ func (TrivyAnalyzer) Analyze(a common.Analyzer) ([]common.Result, error) {
|
||||
// For each pod there may be multiple vulnerabilities
|
||||
var failures []common.Failure
|
||||
for _, vuln := range report.Report.Vulnerabilities {
|
||||
if vuln.Severity == "CRITICAL" {
|
||||
if vuln.Severity == "CRITICAL" || vuln.Severity == "HIGH" {
|
||||
// get the vulnerability ID
|
||||
// get the vulnerability description
|
||||
failures = append(failures, common.Failure{
|
||||
|
Loading…
Reference in New Issue
Block a user