Skip to content

Commit

Permalink
Option.StdOutEnabled to control forwarder logs
Browse files Browse the repository at this point in the history
Signed-off-by: hfuss <[email protected]>
  • Loading branch information
onelapahead committed Oct 1, 2022
1 parent 03f99cd commit ef6312b
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 15 deletions.
20 changes: 11 additions & 9 deletions const.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,20 @@ type carry struct {
}

type PodOption struct {
LocalPort int // the local port for forwarding
PodPort int // the k8s pod port
Pod v1.Pod // the k8s pod metadata
LocalPort int // the local port for forwarding
PodPort int // the k8s pod port
Pod v1.Pod // the k8s pod metadata
StdOutEnabled bool
}

type Option struct {
LocalPort int // the local port for forwarding
RemotePort int // the remote port port for forwarding
Namespace string // the k8s namespace metadata
PodName string // the k8s pod metadata
ServiceName string // the k8s service metadata
Source string // the k8s source string, eg: svc/my-nginx-svc po/my-nginx-66b6c48dd5-ttdb2
LocalPort int // the local port for forwarding
RemotePort int // the remote port port for forwarding
Namespace string // the k8s namespace metadata
PodName string // the k8s pod metadata
ServiceName string // the k8s service metadata
Source string // the k8s source string, eg: svc/my-nginx-svc po/my-nginx-66b6c48dd5-ttdb2
StdOutEnabled bool // whether to output the forward logs to stdout or not
}

type Result struct {
Expand Down
16 changes: 10 additions & 6 deletions forwarder.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,6 @@ func forwarders(ctx context.Context, options []*Option, config *restclient.Confi
return nil, err
}

stream := genericclioptions.IOStreams{
In: os.Stdin,
Out: os.Stdout,
ErrOut: os.Stderr,
}

carries := make([]*carry, len(podOptions))

var g errgroup.Group
Expand All @@ -86,6 +80,16 @@ func forwarders(ctx context.Context, options []*Option, config *restclient.Confi
stopCh := make(chan struct{}, 1)
readyCh := make(chan struct{})

stream := genericclioptions.IOStreams{
In: os.Stdin,
ErrOut: os.Stderr,
}

stream.Out = os.DevNull
if option.StdOutEnabled {
stream.Out = os.Stdout
}

req := &portForwardAPodRequest{
RestConfig: config,
Pod: option.Pod,
Expand Down
1 change: 1 addition & 0 deletions utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,5 +140,6 @@ func buildPodOption(option *Option, pod *v1.Pod) *PodOption {
Namespace: pod.Namespace,
},
},
StdOutEnabled: option.StdOutEnabled,
}
}

0 comments on commit ef6312b

Please sign in to comment.