diff --git a/Makefile b/Makefile index 41b25c15..a91dbc3f 100644 --- a/Makefile +++ b/Makefile @@ -95,10 +95,6 @@ generate: ## Generate code for the application build: ## Build the application cd cmd && go build $(BUILD_FLAGS) -o ../bin/kubehound kubehound/*.go -.PHONY: build-ingestor -build-ingestor: ## Build the ingestor API CLI - cd cmd && go build $(BUILD_FLAGS) -o ../bin/kubehound-ingestor kubehound-ingestor/*.go - .PHONY: kubehound kubehound: | backend-up build ## Prepare kubehound (deploy backend, build go binary) diff --git a/cmd/kubehound/grpc_client.go b/cmd/kubehound/grpc_client.go index 6c1dbfdc..dedc1a47 100644 --- a/cmd/kubehound/grpc_client.go +++ b/cmd/kubehound/grpc_client.go @@ -36,5 +36,5 @@ var ( func init() { cmd.InitGrpcClientCmd(grpcClientIngestCmd, true) - rootCmd.AddCommand(grpcClientIngestCmd) + ingestorCmd.AddCommand(grpcClientIngestCmd) } diff --git a/cmd/kubehound/ingestor.go b/cmd/kubehound/ingestor.go new file mode 100644 index 00000000..1dd0fe7f --- /dev/null +++ b/cmd/kubehound/ingestor.go @@ -0,0 +1,38 @@ +package main + +import ( + "fmt" + + "github.com/DataDog/KubeHound/pkg/cmd" + "github.com/DataDog/KubeHound/pkg/kubehound/core" + "github.com/spf13/cobra" +) + +var ( + ingestorCmd = &cobra.Command{ + Use: "ingest", + Short: "Kubehound Ingestor Service - exposes a gRPC API to ingest data from cloud storage", + Long: `instance of Kubehound that pulls data from cloud storage`, + SilenceUsage: true, + PersistentPreRunE: func(cobraCmd *cobra.Command, args []string) error { + return cmd.InitializeKubehoundConfig(cobraCmd.Context(), cfgFile, true, false) + }, + RunE: func(cobraCmd *cobra.Command, args []string) error { + // Passing the Kubehound config from viper + khCfg, err := cmd.GetConfig() + if err != nil { + return fmt.Errorf("get config: %w", err) + } + + return core.CoreGrpcApi(cobraCmd.Context(), khCfg) + }, + PersistentPostRunE: func(cobraCmd *cobra.Command, args []string) error { + return cmd.CloseKubehoundConfig() + }, + } +) + +func init() { + cmd.InitRootCmd(ingestorCmd) + rootCmd.AddCommand(ingestorCmd) +} diff --git a/cmd/kubehound/root.go b/cmd/kubehound/root.go index 600fb5b2..fc3d21f2 100644 --- a/cmd/kubehound/root.go +++ b/cmd/kubehound/root.go @@ -14,7 +14,7 @@ var ( var ( rootCmd = &cobra.Command{ - Use: "kubehound-local", + Use: "kubehound", Short: "A local Kubehound instance", Long: `A local instance of Kubehound - a Kubernetes attack path generator`, PreRunE: func(cobraCmd *cobra.Command, args []string) error {