Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bugfix: convert dianoseArgs to array #150

Merged
merged 1 commit into from
Jan 25, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions pkg/controller/diagnose/diagnose.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"os"
"os/exec"
"strconv"
"strings"

skoopContext "github.com/alibaba/kubeskoop/pkg/skoop/context"
)
Expand All @@ -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{
Expand All @@ -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) {
Expand All @@ -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))
Expand Down
Loading