Skip to content

Commit

Permalink
Fix lints
Browse files Browse the repository at this point in the history
  • Loading branch information
SuperSandro2000 committed Mar 22, 2024
1 parent 75c5749 commit b2090eb
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
14 changes: 7 additions & 7 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,17 @@ import (
)

func main() {
//parse command line
// parse command line
portForwardArgs, subcommandArgs := splitArgs()

//setup async machinery
ctx, cancel := signal.NotifyContext(context.Background(), //once one subprocess returns, we cancel this ctx to reap the other one
// setup async machinery
ctx, cancel := signal.NotifyContext(context.Background(), // once one subprocess returns, we cancel this ctx to reap the other one
os.Interrupt, syscall.SIGTERM)
var wg sync.WaitGroup
errChan := make(chan error, 2) //collects errors from the subprocess; any error from one will terminate the whole program
portReadableChan := make(chan struct{}) //signals that the ports are established and the subcommand can start
errChan := make(chan error, 2) // collects errors from the subprocess; any error from one will terminate the whole program
portReadableChan := make(chan struct{}) // signals that the ports are established and the subcommand can start

//run subprocesses
// run subprocesses
wg.Add(2)
go func() {
defer wg.Done()
Expand All @@ -53,7 +53,7 @@ func main() {
runSubcommand(ctx, subcommandArgs, errChan, portReadableChan)
}()

//once either exits, cancel the other
// once either exits, cancel the other
err := <-errChan
cancel()
wg.Wait()
Expand Down
10 changes: 5 additions & 5 deletions subprocess.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func runKubectlPortForward(ctx context.Context, args []string, errChan chan<- er
cmd.Cancel = func() error { return cmd.Process.Signal(os.Interrupt) }
cmd.WaitDelay = 3 * time.Second
cmd.Stdin = nil
cmd.Stdout = stderr //os.Stdout is exclusively reserved for the actual payload command
cmd.Stdout = stderr // os.Stdout is exclusively reserved for the actual payload command
cmd.Stderr = stderr
errChan <- cmd.Run()
}
Expand All @@ -58,7 +58,7 @@ type portReadableDetector struct {
func (d *portReadableDetector) Write(buf []byte) (int, error) {
if !d.done && bytes.Contains(buf, []byte("Forwarding from")) {
go func() {
//give kubectl some extra time if it needs to listen on multiple ports
// give kubectl some extra time if it needs to listen on multiple ports
time.Sleep(25 * time.Microsecond)
close(d.portReadableChan)
}()
Expand All @@ -68,11 +68,11 @@ func (d *portReadableDetector) Write(buf []byte) (int, error) {
}

func runSubcommand(ctx context.Context, cmdline []string, errChan chan<- error, portReadableChan <-chan struct{}) {
//wait for either the port-forward to become active, or for the port-forward
//failing and its failure being signaled to us by canceling `ctx`
// wait for either the port-forward to become active, or for the port-forward
// failing and its failure being signaled to us by canceling `ctx`
select {
case <-portReadableChan:
//continue below
// continue below
case <-ctx.Done():
return
}
Expand Down

0 comments on commit b2090eb

Please sign in to comment.