-
Notifications
You must be signed in to change notification settings - Fork 612
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #243 from k8sgpt-ai/feat/integrate
feat: integrations
- Loading branch information
Showing
34 changed files
with
1,351 additions
and
117 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package integration | ||
|
||
import ( | ||
"github.com/fatih/color" | ||
"github.com/k8sgpt-ai/k8sgpt/pkg/integration" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
// activateCmd represents the activate command | ||
var activateCmd = &cobra.Command{ | ||
Use: "activate [integration]", | ||
Short: "Activate an integration", | ||
Long: ``, | ||
Args: cobra.ExactArgs(1), | ||
Run: func(cmd *cobra.Command, args []string) { | ||
integrationName := args[0] | ||
|
||
integration := integration.NewIntegration() | ||
// Check if the integation exists | ||
err := integration.Activate(integrationName, namespace) | ||
if err != nil { | ||
color.Red("Error: %v", err) | ||
return | ||
} | ||
|
||
color.Green("Activated integration %s", integrationName) | ||
}, | ||
} | ||
|
||
func init() { | ||
IntegrationCmd.AddCommand(activateCmd) | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* | ||
Copyright © 2023 NAME HERE <EMAIL ADDRESS> | ||
*/ | ||
package integration | ||
|
||
import ( | ||
"github.com/fatih/color" | ||
"github.com/k8sgpt-ai/k8sgpt/pkg/integration" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
// deactivateCmd represents the deactivate command | ||
var deactivateCmd = &cobra.Command{ | ||
Use: "deactivate [integration]", | ||
Short: "Deactivate an integration", | ||
Args: cobra.ExactArgs(1), | ||
Long: `For example e.g. k8sgpt integration deactivate trivy`, | ||
Run: func(cmd *cobra.Command, args []string) { | ||
integrationName := args[0] | ||
|
||
integration := integration.NewIntegration() | ||
|
||
if err := integration.Deactivate(integrationName, namespace); err != nil { | ||
color.Red("Error: %v", err) | ||
return | ||
} | ||
|
||
color.Green("Deactivated integration %s", integrationName) | ||
|
||
}, | ||
} | ||
|
||
func init() { | ||
IntegrationCmd.AddCommand(deactivateCmd) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package integration | ||
|
||
import ( | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
var ( | ||
namespace string | ||
) | ||
|
||
// IntegrationCmd represents the integrate command | ||
var IntegrationCmd = &cobra.Command{ | ||
Use: "integration", | ||
Aliases: []string{"integrations"}, | ||
Short: "Intergrate another tool into K8sGPT", | ||
Long: `Intergrate another tool into K8sGPT. For example: | ||
k8sgpt integration activate trivy | ||
This would allow you to deploy trivy into your cluster and use a K8sGPT analyzer to parse trivy results.`, | ||
Run: func(cmd *cobra.Command, args []string) { | ||
cmd.Help() | ||
}, | ||
} | ||
|
||
func init() { | ||
IntegrationCmd.PersistentFlags().StringVarP(&namespace, "namespace", "n", "default", "The namespace to use for the integration") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package integration | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
|
||
"github.com/fatih/color" | ||
"github.com/k8sgpt-ai/k8sgpt/pkg/integration" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
// listCmd represents the list command | ||
var listCmd = &cobra.Command{ | ||
Use: "list", | ||
Short: "Lists built-in integrations", | ||
Long: ``, | ||
Run: func(cmd *cobra.Command, args []string) { | ||
integrationProvider := integration.NewIntegration() | ||
integrations := integrationProvider.List() | ||
|
||
fmt.Println(color.YellowString("Active:")) | ||
for _, i := range integrations { | ||
b, err := integrationProvider.IsActivate(i) | ||
if err != nil { | ||
fmt.Println(err) | ||
os.Exit(1) | ||
} | ||
if b { | ||
fmt.Printf("> %s\n", color.GreenString(i)) | ||
} | ||
} | ||
|
||
fmt.Println(color.YellowString("Unused: ")) | ||
for _, i := range integrations { | ||
b, err := integrationProvider.IsActivate(i) | ||
if err != nil { | ||
fmt.Println(err) | ||
os.Exit(1) | ||
} | ||
if !b { | ||
fmt.Printf("> %s\n", color.GreenString(i)) | ||
} | ||
} | ||
}, | ||
} | ||
|
||
func init() { | ||
IntegrationCmd.AddCommand(listCmd) | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.