Skip to content

Commit

Permalink
local-capture: Validate --netns and k8s flags are only set on Linux
Browse files Browse the repository at this point in the history
Signed-off-by: Chance Zibolski <chance.zibolski@gmail.com>
  • Loading branch information
chancez committed May 4, 2024
1 parent be8f200 commit 68047bf
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions cmd/local_capture.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"log/slog"
"os"
"path/filepath"
"runtime"
"strings"

"github.com/chancez/capper/pkg/capture"
Expand Down Expand Up @@ -48,6 +49,22 @@ func runLocalCapture(cmd *cobra.Command, args []string) error {
return err
}

// Validate certain flags are only used on Linux
if runtime.GOOS != "linux" {
var flag string
switch {
case len(netNamespaces) > 0:
flag = "--netns"
case captureOpts.K8sPod != "":
flag = "--k8s-pod"
case captureOpts.K8sNamespace != "":
flag = "--k8s-namespace"
}
if flag != "" {
return fmt.Errorf("%s is only valid on Linux", flag)
}
}

if captureOpts.K8sNamespace != "" && captureOpts.K8sPod != "" {
containerdSock := "/run/containerd/containerd.sock"
captureOpts.Logger.Debug("connecting to containerd", "addr", containerdSock)
Expand Down

0 comments on commit 68047bf

Please sign in to comment.