This repository has been archived by the owner on May 2, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #36 from nabla-containers/docker-network
Updated to work with docker prestart hooks for network setup
- Loading branch information
Showing
7 changed files
with
129 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package libcontainer | ||
|
||
import ( | ||
"bytes" | ||
"encoding/json" | ||
"fmt" | ||
spec "github.com/opencontainers/runtime-spec/specs-go" | ||
"os" | ||
"os/exec" | ||
"syscall" | ||
"time" | ||
) | ||
|
||
func runHook(hook spec.Hook, cid, bundlePath string) error { | ||
// Adapted from: | ||
// github.com/kata-containers/runtime/cli/hook.go | ||
state := spec.State{ | ||
Pid: os.Getpid(), | ||
Bundle: bundlePath, | ||
ID: cid, | ||
} | ||
|
||
stateJSON, err := json.Marshal(state) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
var stdout, stderr bytes.Buffer | ||
cmd := &exec.Cmd{ | ||
Path: hook.Path, | ||
Args: hook.Args, | ||
Env: hook.Env, | ||
Stdin: bytes.NewReader(stateJSON), | ||
Stdout: &stdout, | ||
Stderr: &stderr, | ||
} | ||
|
||
if err := cmd.Start(); err != nil { | ||
return err | ||
} | ||
|
||
if hook.Timeout == nil { | ||
if err := cmd.Wait(); err != nil { | ||
return fmt.Errorf("%s: stdout: %s, stderr: %s", err, stdout.String(), stderr.String()) | ||
} | ||
} else { | ||
done := make(chan error, 1) | ||
go func() { | ||
done <- cmd.Wait() | ||
close(done) | ||
}() | ||
|
||
select { | ||
case err := <-done: | ||
if err != nil { | ||
return fmt.Errorf("%s: stdout: %s, stderr: %s", err, stdout.String(), stderr.String()) | ||
} | ||
case <-time.After(time.Duration(*hook.Timeout) * time.Second): | ||
if err := syscall.Kill(cmd.Process.Pid, syscall.SIGKILL); err != nil { | ||
return err | ||
} | ||
|
||
return fmt.Errorf("Hook timeout") | ||
} | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -63,9 +63,6 @@ instance of a container.`, | |
} | ||
os.Stdout.Write(data) | ||
|
||
// DEBUG | ||
os.Stderr.Write(data) | ||
|
||
return nil | ||
}, | ||
} | ||
|