mirror of
https://github.com/k8sgpt-ai/k8sgpt.git
synced 2025-09-07 10:11:08 +00:00
feat: serve/integration capability (#645)
* chore: updated schema for integrations support (#616) Signed-off-by: Alex Jones <alexsimonjones@gmail.com> wip: enabling integration activation Signed-off-by: Alex Jones <alexsimonjones@gmail.com> wip: enabling integration activation Signed-off-by: Alex Jones <alexsimonjones@gmail.com> * wip Signed-off-by: Alex Jones <alexsimonjones@gmail.com> * feat: skipinstall fixed Signed-off-by: Alex Jones <alexsimonjones@gmail.com> * feat: fixed filters for integrations but its ugly Signed-off-by: Alex Jones <alexsimonjones@gmail.com> * chore: updated library Signed-off-by: Alex Jones <alexsimonjones@gmail.com> * chore: updated go mod Signed-off-by: Alex Jones <alexsimonjones@gmail.com> * chore: updated go mod Signed-off-by: Alex Jones <alexsimonjones@gmail.com> --------- Signed-off-by: Alex Jones <alexsimonjones@gmail.com>
This commit is contained in:
@@ -15,10 +15,8 @@ package integration
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"os"
|
||||
"strings"
|
||||
"fmt"
|
||||
|
||||
"github.com/fatih/color"
|
||||
"github.com/k8sgpt-ai/k8sgpt/pkg/common"
|
||||
"github.com/k8sgpt-ai/k8sgpt/pkg/integration/trivy"
|
||||
"github.com/k8sgpt-ai/k8sgpt/pkg/util"
|
||||
@@ -35,6 +33,8 @@ type IIntegration interface {
|
||||
|
||||
GetAnalyzerName() []string
|
||||
|
||||
OwnsAnalyzer(string) bool
|
||||
|
||||
IsActivate() bool
|
||||
}
|
||||
|
||||
@@ -64,34 +64,38 @@ func (*Integration) Get(name string) (IIntegration, error) {
|
||||
return integrations[name], nil
|
||||
}
|
||||
|
||||
func (i *Integration) AnalyzerByIntegration(input string) (string, error) {
|
||||
|
||||
for _, name := range i.List() {
|
||||
if integ, err := i.Get(name); err == nil {
|
||||
if integ.OwnsAnalyzer(input) {
|
||||
return name, nil
|
||||
}
|
||||
}
|
||||
}
|
||||
return "", errors.New("analyzerbyintegration: no matches found")
|
||||
}
|
||||
|
||||
func (*Integration) Activate(name string, namespace string, activeFilters []string, skipInstall bool) error {
|
||||
if _, ok := integrations[name]; !ok {
|
||||
return errors.New("integration not found")
|
||||
}
|
||||
|
||||
mergedFilters := activeFilters
|
||||
|
||||
mergedFilters = append(mergedFilters, integrations[name].GetAnalyzerName()...)
|
||||
|
||||
uniqueFilters, dupplicatedFilters := util.RemoveDuplicates(mergedFilters)
|
||||
|
||||
// Verify dupplicate
|
||||
if len(dupplicatedFilters) != 0 {
|
||||
color.Red("Integration already activated : %s", strings.Join(dupplicatedFilters, ", "))
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
viper.Set("active_filters", uniqueFilters)
|
||||
|
||||
if !skipInstall {
|
||||
if err := integrations[name].Deploy(namespace); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
mergedFilters := activeFilters
|
||||
mergedFilters = append(mergedFilters, integrations[name].GetAnalyzerName()...)
|
||||
uniqueFilters, _ := util.RemoveDuplicates(mergedFilters)
|
||||
|
||||
viper.Set("active_filters", uniqueFilters)
|
||||
|
||||
if err := viper.WriteConfig(); err != nil {
|
||||
color.Red("Error writing config file: %s", err.Error())
|
||||
os.Exit(1)
|
||||
return fmt.Errorf("error writing config file: %s", err.Error())
|
||||
|
||||
}
|
||||
|
||||
return nil
|
||||
@@ -111,6 +115,7 @@ func (*Integration) Deactivate(name string, namespace string) error {
|
||||
activeFilters = append(activeFilters[:x], activeFilters[x+1:]...)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if err := integrations[name].UnDeploy(namespace); err != nil {
|
||||
@@ -120,8 +125,8 @@ func (*Integration) Deactivate(name string, namespace string) error {
|
||||
viper.Set("active_filters", activeFilters)
|
||||
|
||||
if err := viper.WriteConfig(); err != nil {
|
||||
color.Red("Error writing config file: %s", err.Error())
|
||||
os.Exit(1)
|
||||
return fmt.Errorf("error writing config file: %s", err.Error())
|
||||
|
||||
}
|
||||
|
||||
return nil
|
||||
|
Reference in New Issue
Block a user