feat: initial impl of integration

Signed-off-by: AlexsJones <alexsimonjones@gmail.com>
Signed-off-by: Alex Jones <alexsimonjones@gmail.com>
This commit is contained in:
AlexsJones
2023-04-09 15:40:01 +01:00
committed by Alex Jones
parent 9423b53c1d
commit 61d6e52465
10 changed files with 860 additions and 8 deletions

View File

@@ -0,0 +1,33 @@
package integration
import (
"github.com/fatih/color"
"github.com/k8sgpt-ai/k8sgpt/pkg/integration"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)
// 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) {
intName := args[0]
integration := viper.Get("integration").(*integration.Integration)
// Check if the integation exists
err := integration.Activate(intName, namespace)
if err != nil {
color.Red("Error: %v", err)
return
}
color.Green("Activate integration %s", intName)
},
}
func init() {
IntegrationCmd.AddCommand(activateCmd)
}

View File

@@ -0,0 +1,35 @@
/*
Copyright © 2023 NAME HERE <EMAIL ADDRESS>
*/
package integration
import (
"github.com/k8sgpt-ai/k8sgpt/pkg/integration"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)
var (
name string
)
// deactivateCmd represents the deactivate command
var deactivateCmd = &cobra.Command{
Use: "deactivate",
Short: "Deactivate an integration",
Long: ``,
Run: func(cmd *cobra.Command, args []string) {
// Check if the integation exists
integration := viper.Get("integration").(*integration.Integration)
integration.Deactivate(name, namespace)
// Deactivate
},
}
func init() {
IntegrationCmd.AddCommand(deactivateCmd)
deactivateCmd.Flags().StringVarP(&name, "name", "n", "", "The name of the integration to deactivate")
}

View File

@@ -0,0 +1,26 @@
package integration
import (
"github.com/spf13/cobra"
)
var (
namespace string
)
// IntegrationCmd represents the integrate command
var IntegrationCmd = &cobra.Command{
Use: "integration",
Short: "Intergrate another tool into K8sGPT",
Long: `Intergrate another tool into K8sGPT. For example:
k8sgpt integration add 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")
}

31
cmd/integration/list.go Normal file
View File

@@ -0,0 +1,31 @@
package integration
import (
"fmt"
"github.com/fatih/color"
"github.com/k8sgpt-ai/k8sgpt/pkg/integration"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)
// listCmd represents the list command
var listCmd = &cobra.Command{
Use: "list",
Short: "Lists built-in integrations",
Long: ``,
Run: func(cmd *cobra.Command, args []string) {
integration := viper.Get("integration").(*integration.Integration)
integrations := integration.List()
for _, integration := range integrations {
fmt.Printf("> %s\n", color.GreenString(integration))
}
},
}
func init() {
IntegrationCmd.AddCommand(listCmd)
}