mirror of
https://github.com/k8sgpt-ai/k8sgpt.git
synced 2025-09-28 00:07:40 +00:00
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:
33
cmd/integration/activate.go
Normal file
33
cmd/integration/activate.go
Normal 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)
|
||||
|
||||
}
|
35
cmd/integration/deactivate.go
Normal file
35
cmd/integration/deactivate.go
Normal 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")
|
||||
}
|
26
cmd/integration/integration.go
Normal file
26
cmd/integration/integration.go
Normal 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
31
cmd/integration/list.go
Normal 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)
|
||||
|
||||
}
|
Reference in New Issue
Block a user