diff --git a/pkg/controller/diagnose/diagnose.go b/pkg/controller/diagnose/diagnose.go index 059e72d8..b60f8fde 100644 --- a/pkg/controller/diagnose/diagnose.go +++ b/pkg/controller/diagnose/diagnose.go @@ -6,6 +6,7 @@ import ( "os" "os/exec" "strconv" + "strings" skoopContext "github.com/alibaba/kubeskoop/pkg/skoop/context" ) @@ -15,9 +16,9 @@ type Controller interface { } func NewDiagnoseController(namespace string) Controller { - diagnoseArgs := "" + var diagnoseArgs []string if diagnoseArgsFromEnv, ok := os.LookupEnv("KUBESKOOP_DIAGNOSE_ARGS"); ok { - diagnoseArgs = diagnoseArgsFromEnv + diagnoseArgs = strings.Split(diagnoseArgsFromEnv, " ") } // 1. build skoop global context return &Diagnostor{ @@ -28,7 +29,7 @@ func NewDiagnoseController(namespace string) Controller { type Diagnostor struct { namespace string - diagnoseArgs string + diagnoseArgs []string } func (d *Diagnostor) Diagnose(ctx context.Context, taskConfig *skoopContext.TaskConfig) (string, error) { @@ -39,14 +40,17 @@ func (d *Diagnostor) Diagnose(ctx context.Context, taskConfig *skoopContext.Task defer os.RemoveAll(tempDir) resultStorage := fmt.Sprintf("%v/result.json", tempDir) - cmd := exec.CommandContext(ctx, "skoop", "--output", resultStorage, "--format", "json", + args := []string{"--output", resultStorage, "--format", "json", "-s", taskConfig.Source, "-d", taskConfig.Destination.Address, "--dport", strconv.FormatUint(uint64(taskConfig.Destination.Port), 10), "--protocol", taskConfig.Protocol, "--collector-namespace", d.namespace, - d.diagnoseArgs, - ) + } + if len(d.diagnoseArgs) != 0 { + args = append(args, d.diagnoseArgs...) + } + cmd := exec.CommandContext(ctx, "skoop", args...) output, err := cmd.CombinedOutput() if err != nil { return "", fmt.Errorf("failed to diagnose: %v, output: %v", err, string(output))