@@ -21,7 +21,6 @@ import (
21
21
"context"
22
22
"fmt"
23
23
"io"
24
- "os/exec"
25
24
"strings"
26
25
"time"
27
26
@@ -127,7 +126,7 @@ func (k *KubectlForwarder) forward(parentCtx context.Context, pfe *portForwardEn
127
126
}
128
127
}
129
128
130
- func portForwardCommand (ctx context.Context , k * kubectl.CLI , pfe * portForwardEntry , buf io.Writer ) * exec .Cmd {
129
+ func portForwardCommand (ctx context.Context , k * kubectl.CLI , pfe * portForwardEntry , buf io.Writer ) * kubectl .Cmd {
131
130
args := []string {
132
131
"--pod-running-timeout" , "1s" ,
133
132
fmt .Sprintf ("%s/%s" , pfe .resource .Type , pfe .resource .Name ),
@@ -137,7 +136,7 @@ func portForwardCommand(ctx context.Context, k *kubectl.CLI, pfe *portForwardEnt
137
136
if pfe .resource .Address != "" && pfe .resource .Address != util .Loopback {
138
137
args = append (args , []string {"--address" , pfe .resource .Address }... )
139
138
}
140
- cmd := k .Command (ctx , "port-forward" , args ... )
139
+ cmd := k .CommandWithStrictCancellation (ctx , "port-forward" , args ... )
141
140
cmd .Stdout = buf
142
141
cmd .Stderr = buf
143
142
return cmd
@@ -159,7 +158,7 @@ func (*KubectlForwarder) Terminate(p *portForwardEntry) {
159
158
// Monitor monitors the logs for a kubectl port forward command
160
159
// If it sees an error, it calls back to the EntryManager to
161
160
// retry the entire port forward operation.
162
- func (* KubectlForwarder ) monitorErrorLogs (ctx context.Context , buf * bytes.Buffer , cmd * exec .Cmd , p * portForwardEntry ) {
161
+ func (* KubectlForwarder ) monitorErrorLogs (ctx context.Context , buf * bytes.Buffer , cmd * kubectl .Cmd , p * portForwardEntry ) {
163
162
for {
164
163
select {
165
164
case <- ctx .Done ():
@@ -179,7 +178,7 @@ func (*KubectlForwarder) monitorErrorLogs(ctx context.Context, buf *bytes.Buffer
179
178
strings .Contains (s , "error upgrading connection" ) {
180
179
// kubectl is having an error. retry the command
181
180
logrus .Tracef ("killing port forwarding %v" , p )
182
- if err := cmd .Process . Kill (); err != nil {
181
+ if err := cmd .Terminate (); err != nil {
183
182
logrus .Tracef ("failed to kill port forwarding %v, err: %s" , p , err )
184
183
}
185
184
return
0 commit comments