From 133850f984cc0bb41ec1e4521a32ab30558778f1 Mon Sep 17 00:00:00 2001 From: Alex Jones Date: Sun, 3 Sep 2023 16:13:52 +0100 Subject: [PATCH] chore: fixes a bug where filters do not deactive (#621) Signed-off-by: Alex Jones Co-authored-by: Alex Jones --- pkg/integration/integration.go | 26 ++++++-------------------- pkg/integration/trivy/trivy.go | 5 ----- 2 files changed, 6 insertions(+), 25 deletions(-) diff --git a/pkg/integration/integration.go b/pkg/integration/integration.go index d5c7268b7d..6e9d0c2363 100644 --- a/pkg/integration/integration.go +++ b/pkg/integration/integration.go @@ -32,8 +32,6 @@ type IIntegration interface { UnDeploy(namespace string) error // AddAnalyzer(*map[string]common.IAnalyzer) - // RemoveAnalyzer removes an analyzer from the cluster - RemoveAnalyzer() error GetAnalyzerName() []string @@ -73,9 +71,7 @@ func (*Integration) Activate(name string, namespace string, activeFilters []stri mergedFilters := activeFilters - for _, integrationAnalyzer := range integrations[name].GetAnalyzerName() { - mergedFilters = append(mergedFilters, integrationAnalyzer) - } + mergedFilters = append(mergedFilters, integrations[name].GetAnalyzerName()...) uniqueFilters, dupplicatedFilters := util.RemoveDuplicates(mergedFilters) @@ -108,23 +104,13 @@ func (*Integration) Deactivate(name string, namespace string) error { activeFilters := viper.GetStringSlice("active_filters") - // Update filters - // This might be a bad idea, but we cannot reference analyzer here - foundFilter := false - for i, v := range activeFilters { - - for _, intanal := range integrations[name].GetAnalyzerName() { - if v == intanal { - foundFilter = true - activeFilters = append(activeFilters[:i], activeFilters[i+1:]...) - break + // Update filters and remove the specific filters for the integration + for _, filter := range integrations[name].GetAnalyzerName() { + for x, af := range activeFilters { + if af == filter { + activeFilters = append(activeFilters[:x], activeFilters[x+1:]...) } } - - } - if !foundFilter { - color.Red("Ingregation %s does not exist in configuration file. Please use k8sgpt integration add.", name) - os.Exit(1) } if err := integrations[name].UnDeploy(namespace); err != nil { diff --git a/pkg/integration/trivy/trivy.go b/pkg/integration/trivy/trivy.go index c3d78fb6b6..8b939697d4 100644 --- a/pkg/integration/trivy/trivy.go +++ b/pkg/integration/trivy/trivy.go @@ -118,8 +118,3 @@ func (t *Trivy) AddAnalyzer(mergedMap *map[string]common.IAnalyzer) { } } - -func (t *Trivy) RemoveAnalyzer() error { - - return nil -}