Add -debug flag if debug mode is enabled

This commit is contained in:
M. Mert Yildiran 2022-12-27 08:05:05 +03:00
parent afbd6963b8
commit 74da75e966
No known key found for this signature in database
GPG Key ID: DA5D6DCBB758A461
2 changed files with 13 additions and 3 deletions

View File

@ -108,9 +108,14 @@ func pcap() {
}, },
} }
cmdHub := []string{"-port", fmt.Sprintf("%d", config.Config.Tap.Hub.DstPort)}
if config.DebugMode {
cmdHub = append(cmdHub, fmt.Sprintf("-%s", config.DebugFlag))
}
respHub, err := cli.ContainerCreate(ctx, &container.Config{ respHub, err := cli.ContainerCreate(ctx, &container.Config{
Image: imageHub, Image: imageHub,
Cmd: []string{"-port", fmt.Sprintf("%d", config.Config.Tap.Hub.DstPort), "-debug"}, Cmd: cmdHub,
Tty: false, Tty: false,
ExposedPorts: nat.PortSet{nat.Port(fmt.Sprintf("%d/tcp", config.Config.Tap.Hub.DstPort)): {}}, ExposedPorts: nat.PortSet{nat.Port(fmt.Sprintf("%d/tcp", config.Config.Tap.Hub.DstPort)): {}},
}, hostConfigHub, nil, nil, "kubeshark-hub") }, hostConfigHub, nil, nil, "kubeshark-hub")
@ -124,9 +129,14 @@ func pcap() {
return return
} }
cmdWorker := []string{"-i", "any", "-port", fmt.Sprintf("%d", config.Config.Tap.Worker.DstPort)}
if config.DebugMode {
cmdWorker = append(cmdWorker, fmt.Sprintf("-%s", config.DebugFlag))
}
respWorker, err := cli.ContainerCreate(ctx, &container.Config{ respWorker, err := cli.ContainerCreate(ctx, &container.Config{
Image: imageWorker, Image: imageWorker,
Cmd: []string{"-i", "any", "-port", fmt.Sprintf("%d", config.Config.Tap.Worker.DstPort), "-debug"}, Cmd: cmdWorker,
Tty: false, Tty: false,
}, nil, nil, nil, "kubeshark-worker") }, nil, nil, nil, "kubeshark-worker")
if err != nil { if err != nil {

View File

@ -32,7 +32,7 @@ func init() {
rootCmd.PersistentFlags().StringSlice(config.SetCommandName, []string{}, fmt.Sprintf("Override values using --%s", config.SetCommandName)) rootCmd.PersistentFlags().StringSlice(config.SetCommandName, []string{}, fmt.Sprintf("Override values using --%s", config.SetCommandName))
rootCmd.PersistentFlags().String(config.ConfigFilePathCommandName, defaultConfig.ConfigFilePath, fmt.Sprintf("Override config file path using --%s", config.ConfigFilePathCommandName)) rootCmd.PersistentFlags().String(config.ConfigFilePathCommandName, defaultConfig.ConfigFilePath, fmt.Sprintf("Override config file path using --%s", config.ConfigFilePathCommandName))
rootCmd.PersistentFlags().BoolP("debug", "d", false, "Enable debug mode.") rootCmd.PersistentFlags().BoolP(config.DebugFlag, "d", false, "Enable debug mode.")
} }
// Execute adds all child commands to the root command and sets flags appropriately. // Execute adds all child commands to the root command and sets flags appropriately.