executor: rename wrapNetns to withNetworkIsolation

This commit is contained in:
Nick Ethier 2019-09-30 21:38:31 -04:00
parent 5127caef11
commit 8b881d83d5
No known key found for this signature in database
GPG Key ID: 07C1A3ECED90D24A
3 changed files with 6 additions and 7 deletions

View File

@ -309,7 +309,7 @@ func (e *UniversalExecutor) Launch(command *ExecCommand) (*ProcessState, error)
e.childCmd.Env = e.commandCfg.Env
// Start the process
if err = wrapNetns(e.childCmd.Start, command.NetworkIsolation); err != nil {
if err = withNetworkIsolation(e.childCmd.Start, command.NetworkIsolation); err != nil {
return nil, fmt.Errorf("failed to start command path=%q --- args=%q: %v", path, e.childCmd.Args, err)
}
@ -342,7 +342,7 @@ func ExecScript(ctx context.Context, dir string, env []string, attrs *syscall.Sy
cmd.Stdout = buf
cmd.Stderr = buf
if err := wrapNetns(cmd.Run, netSpec); err != nil {
if err := withNetworkIsolation(cmd.Run, netSpec); err != nil {
exitErr, ok := err.(*exec.ExitError)
if !ok {
// Non-exit error, return it and let the caller treat
@ -401,7 +401,7 @@ func (e *UniversalExecutor) ExecStreaming(ctx context.Context, command []string,
return nil
},
processStart: func() error {
return wrapNetns(cmd.Start, e.commandCfg.NetworkIsolation)
return withNetworkIsolation(cmd.Start, e.commandCfg.NetworkIsolation)
},
processWait: func() (*os.ProcessState, error) {
err := cmd.Wait()

View File

@ -25,6 +25,6 @@ func (e *UniversalExecutor) start(command *ExecCommand) error {
return e.childCmd.Start()
}
func wrapNetns(f func() error, _ *drivers.NetworkIsolationSpec) error {
func withNetworkIsolation(f func() error, _ *drivers.NetworkIsolationSpec) error {
return f()
}

View File

@ -174,9 +174,8 @@ func DestroyCgroup(groups *lconfigs.Cgroup, executorPid int) error {
return mErrs.ErrorOrNil()
}
// wrapNetns takes a given function and calls it inside the network namespace
// given in the NetworkIsolationSpec
func wrapNetns(f func() error, spec *drivers.NetworkIsolationSpec) error {
// withNetworkIsolation calls the passed function the network namespace `spec`
func withNetworkIsolation(f func() error, spec *drivers.NetworkIsolationSpec) error {
if spec != nil && spec.Path != "" {
// Get a handle to the target network namespace
netns, err := ns.GetNS(spec.Path)