mirror of https://github.com/k3s-io/k3s
Merge pull request #40159 from euank/beware-of-shadows
Automatic merge from submit-queue (batch tested with PRs 40011, 40159)
dockertools/nsenterexec: fix err shadow
The shadow of err meant the combination of `exec-handler=nsenter` +
`tty` + a non-zero exit code meant that the exit code would be LOST
FOREVER 👻
This isn't all that important since no one really used the nsenter exec
handler as I understand it
```release-note
NONE
```
pull/6/head
commit
54ff406702
|
@ -53,6 +53,7 @@ func (*NsenterExecHandler) ExecInContainer(client DockerInterface, container *do
|
|||
args = append(args, container.Config.Env...)
|
||||
args = append(args, cmd...)
|
||||
command := exec.Command(nsenter, args...)
|
||||
var cmdErr error
|
||||
if tty {
|
||||
p, err := kubecontainer.StartPty(command)
|
||||
if err != nil {
|
||||
|
@ -75,7 +76,7 @@ func (*NsenterExecHandler) ExecInContainer(client DockerInterface, container *do
|
|||
go io.Copy(stdout, p)
|
||||
}
|
||||
|
||||
err = command.Wait()
|
||||
cmdErr = command.Wait()
|
||||
} else {
|
||||
if stdin != nil {
|
||||
// Use an os.Pipe here as it returns true *os.File objects.
|
||||
|
@ -97,13 +98,13 @@ func (*NsenterExecHandler) ExecInContainer(client DockerInterface, container *do
|
|||
command.Stderr = stderr
|
||||
}
|
||||
|
||||
err = command.Run()
|
||||
cmdErr = command.Run()
|
||||
}
|
||||
|
||||
if exitErr, ok := err.(*exec.ExitError); ok {
|
||||
if exitErr, ok := cmdErr.(*exec.ExitError); ok {
|
||||
return &utilexec.ExitErrorWrapper{ExitError: exitErr}
|
||||
}
|
||||
return err
|
||||
return cmdErr
|
||||
}
|
||||
|
||||
// NativeExecHandler executes commands in Docker containers using Docker's exec API.
|
||||
|
|
Loading…
Reference in New Issue