kubearmor-client/cmd/sysdump.go
tesla59 ee40b91f0b feat: (recommend) Implement recommend functionality for Docker Client
cmd: rename k8s client to k8sclient

Signed-off-by: tesla59 <nishant@heim.id>

cmd: wrap k8sClient in interface to use in recommend package

Signed-off-by: tesla59 <nishant@heim.id>

k8s: fix ListDeployment method

Signed-off-by: tesla59 <nishant@heim.id>

recommend: refactor k8s policy generation
use a common interface to support other clients as well
also create common Object{} to support different k8s obejcts such as Deployment, Daemonset etc

Signed-off-by: tesla59 <nishant@heim.id>

recommend: use image name as Object's name while generating policy

Signed-off-by: tesla59 <nishant@heim.id>

recommend: remove DeploymentName Field from Object{}

Signed-off-by: tesla59 <nishant@heim.id>

recommend: use ListOptions to select deployment by labels

Signed-off-by: tesla59 <nishant@heim.id>

k8s: generate recommended policies for CronJob, DaemonSet and Jobs

Signed-off-by: tesla59 <nishant@heim.id>

k8s: generate recommend policy for statefulset and unowned replicaset

Signed-off-by: tesla59 <nishant@heim.id>

k8s: remove K8sClientWrapper abstraction

Signed-off-by: tesla59 <nishant@heim.id>

recommend: initialize dockerClient and generate policies for containers as well

Signed-off-by: tesla59 <nishant@heim.id>

recommend: add new flag k8s to specify which client to use
this removes dependency of recommend command on kubearmor

Signed-off-by: tesla59 <nishant@heim.id>

recommend: fallback to docker client if k8s client is not present

Signed-off-by: tesla59 <nishant@heim.id>

recommend: only log the client if images is not specified

Signed-off-by: tesla59 <nishant@heim.id>

recommend: generate policyDir based on image namespace set to null

Signed-off-by: tesla59 <nishant@heim.id>

recommend: trim \n in final report generation

Signed-off-by: tesla59 <nishant@heim.id>

recommend: handle err when listing objects

Signed-off-by: tesla59 <nishant@heim.id>

docker: Use API version negotiation to avoid version mismatch errors

Signed-off-by: tesla59 <nishant@heim.id>
2025-07-15 21:29:08 +05:30

29 lines
766 B
Go

// SPDX-License-Identifier: Apache-2.0
// Copyright 2021 Authors of KubeArmor
package cmd
import (
"github.com/kubearmor/kubearmor-client/sysdump"
"github.com/spf13/cobra"
)
var dumpOptions sysdump.Options
// sysdumpCmd represents the get command
var sysdumpCmd = &cobra.Command{
Use: "sysdump",
Short: "Collect system dump information for troubleshooting and error report",
Long: `Collect system dump information for troubleshooting and error reports`,
RunE: func(cmd *cobra.Command, args []string) error {
if err := sysdump.Collect(k8sClient, dumpOptions); err != nil {
return err
}
return nil
},
}
func init() {
rootCmd.AddCommand(sysdumpCmd)
sysdumpCmd.Flags().StringVarP(&dumpOptions.Filename, "file", "f", "", "output file to use")
}