Signed-off-by: Alex Jones <alexsimonjones@gmail.com>
This commit is contained in:
Alex Jones
2023-04-11 12:30:57 +01:00
parent 80ac51c804
commit 4984840de1
22 changed files with 170 additions and 85 deletions

View File

@@ -3,7 +3,7 @@ package integration
import (
"errors"
"github.com/k8sgpt-ai/k8sgpt/pkg/analyzer"
"github.com/k8sgpt-ai/k8sgpt/pkg/common"
"github.com/k8sgpt-ai/k8sgpt/pkg/integration/trivy"
)
@@ -13,7 +13,7 @@ type IIntegration interface {
// Remove removes an integration from the cluster
UnDeploy(namespace string) error
//
AddAnalyzer() (string, analyzer.IAnalyzer, error)
AddAnalyzer(*map[string]common.IAnalyzer)
// RemoveAnalyzer removes an analyzer from the cluster
RemoveAnalyzer() error
@@ -23,6 +23,10 @@ type IIntegration interface {
type Integration struct {
}
type IntegrationProvider struct {
Active []string `mapstructure:"active"`
}
var integrations = map[string]IIntegration{
"trivy": trivy.NewTrivy(),
}
@@ -39,16 +43,40 @@ func (*Integration) List() []string {
return keys
}
func (*Integration) Get(name string) (IIntegration, error) {
if _, ok := integrations[name]; !ok {
return nil, errors.New("integration not found")
}
return integrations[name], nil
}
func (*Integration) Activate(name string, namespace string) error {
if _, ok := integrations[name]; !ok {
return errors.New("integration not found")
}
return integrations[name].Deploy(namespace)
if err := integrations[name].Deploy(namespace); err != nil {
return err
}
return nil
}
func (*Integration) Deactivate(name string, namespace string) error {
if _, ok := integrations[name]; !ok {
return errors.New("integration not found")
}
return integrations[name].UnDeploy(namespace)
if err := integrations[name].UnDeploy(namespace); err != nil {
return err
}
return nil
}
func (*Integration) IsActivate(name string) (bool, error) {
if _, ok := integrations[name]; !ok {
return false, errors.New("integration not found")
}
return integrations[name].IsActivate(), nil
}