Skip to content

Commit

Permalink
fix: append coreAnalyzer if active_filter is empty and integration is…
Browse files Browse the repository at this point in the history
… added (#441)

Signed-off-by: Matthis Holleville <matthish29@gmail.com>
  • Loading branch information
matthisholleville committed May 19, 2023
1 parent c588e96 commit b7dc384
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
11 changes: 10 additions & 1 deletion cmd/integration/activate.go
Expand Up @@ -15,8 +15,10 @@ package integration

import (
"github.com/fatih/color"
"github.com/k8sgpt-ai/k8sgpt/pkg/analyzer"
"github.com/k8sgpt-ai/k8sgpt/pkg/integration"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)

// activateCmd represents the activate command
Expand All @@ -27,10 +29,17 @@ var activateCmd = &cobra.Command{
Args: cobra.ExactArgs(1),
Run: func(cmd *cobra.Command, args []string) {
integrationName := args[0]
coreFilters, _, _ := analyzer.ListFilters()

// Update filters
activeFilters := viper.GetStringSlice("active_filters")
if len(activeFilters) == 0 {
activeFilters = coreFilters
}

integration := integration.NewIntegration()
// Check if the integation exists
err := integration.Activate(integrationName, namespace)
err := integration.Activate(integrationName, namespace, activeFilters)
if err != nil {
color.Red("Error: %v", err)
return
Expand Down
5 changes: 1 addition & 4 deletions pkg/integration/integration.go
Expand Up @@ -66,14 +66,11 @@ func (*Integration) Get(name string) (IIntegration, error) {
return integrations[name], nil
}

func (*Integration) Activate(name string, namespace string) error {
func (*Integration) Activate(name string, namespace string, activeFilters []string) error {
if _, ok := integrations[name]; !ok {
return errors.New("integration not found")
}

// Update filters
activeFilters := viper.GetStringSlice("active_filters")

mergedFilters := append(activeFilters, integrations[name].GetAnalyzerName())

uniqueFilters, dupplicatedFilters := util.RemoveDuplicates(mergedFilters)
Expand Down

0 comments on commit b7dc384

Please sign in to comment.