diff --git a/container.go b/container.go index e3ade00b..95be4f9e 100644 --- a/container.go +++ b/container.go @@ -10,8 +10,8 @@ type MountConfig mount.MountConfig type Network network.Network -// Container defines configuration options for executing a process inside a contained environment -type Container struct { +// Config defines configuration options for executing a process inside a contained environment. +type Config struct { // Mount specific options. MountConfig *MountConfig `json:"mount_config,omitempty"` diff --git a/container_test.go b/container_test.go index c7040565..e98b38fe 100644 --- a/container_test.go +++ b/container_test.go @@ -32,14 +32,14 @@ func containsDevice(expected *devices.Device, values []*devices.Device) bool { return false } -func TestContainerJsonFormat(t *testing.T) { +func TestConfigJsonFormat(t *testing.T) { f, err := os.Open("sample_configs/attach_to_bridge.json") if err != nil { t.Fatal("Unable to open container.json") } defer f.Close() - var container *Container + var container *Config if err := json.NewDecoder(f).Decode(&container); err != nil { t.Fatalf("failed to decode container config: %s", err) } diff --git a/namespaces/create.go b/namespaces/create.go index 20bef204..15a844bc 100644 --- a/namespaces/create.go +++ b/namespaces/create.go @@ -7,4 +7,4 @@ import ( "github.com/docker/libcontainer" ) -type CreateCommand func(container *libcontainer.Container, console, rootfs, dataPath, init string, childPipe *os.File, args []string) *exec.Cmd +type CreateCommand func(container *libcontainer.Config, console, rootfs, dataPath, init string, childPipe *os.File, args []string) *exec.Cmd diff --git a/namespaces/exec.go b/namespaces/exec.go index 297de529..10238536 100644 --- a/namespaces/exec.go +++ b/namespaces/exec.go @@ -19,7 +19,7 @@ import ( // Move this to libcontainer package. // Exec performes setup outside of a namespace so that a container can be // executed. Exec is a high level function for working with container namespaces. -func Exec(container *libcontainer.Container, term Terminal, rootfs, dataPath string, args []string, createCommand CreateCommand, startCallback func()) (int, error) { +func Exec(container *libcontainer.Config, term Terminal, rootfs, dataPath string, args []string, createCommand CreateCommand, startCallback func()) (int, error) { var ( master *os.File console string @@ -105,7 +105,7 @@ func Exec(container *libcontainer.Container, term Terminal, rootfs, dataPath str // root: the path to the container json file and information // pipe: sync pipe to syncronize the parent and child processes // args: the arguemnts to pass to the container to run as the user's program -func DefaultCreateCommand(container *libcontainer.Container, console, rootfs, dataPath, init string, pipe *os.File, args []string) *exec.Cmd { +func DefaultCreateCommand(container *libcontainer.Config, console, rootfs, dataPath, init string, pipe *os.File, args []string) *exec.Cmd { // get our binary name from arg0 so we can always reexec ourself env := []string{ "console=" + console, @@ -137,7 +137,7 @@ func DefaultCreateCommand(container *libcontainer.Container, console, rootfs, da // SetupCgroups applies the cgroup restrictions to the process running in the contaienr based // on the container's configuration -func SetupCgroups(container *libcontainer.Container, nspid int) (cgroups.ActiveCgroup, error) { +func SetupCgroups(container *libcontainer.Config, nspid int) (cgroups.ActiveCgroup, error) { if container.Cgroups != nil { c := container.Cgroups if systemd.UseSystemd() { @@ -150,7 +150,7 @@ func SetupCgroups(container *libcontainer.Container, nspid int) (cgroups.ActiveC // InitializeNetworking creates the container's network stack outside of the namespace and moves // interfaces into the container's net namespaces if necessary -func InitializeNetworking(container *libcontainer.Container, nspid int, pipe *SyncPipe) error { +func InitializeNetworking(container *libcontainer.Config, nspid int, pipe *SyncPipe) error { context := map[string]string{} for _, config := range container.Networks { strategy, err := network.GetStrategy(config.Type) diff --git a/namespaces/execin.go b/namespaces/execin.go index f44e92ab..cd33025a 100644 --- a/namespaces/execin.go +++ b/namespaces/execin.go @@ -13,7 +13,7 @@ import ( ) // ExecIn uses an existing pid and joins the pid's namespaces with the new command. -func ExecIn(container *libcontainer.Container, nspid int, args []string) error { +func ExecIn(container *libcontainer.Config, nspid int, args []string) error { // TODO(vmarmol): If this gets too long, send it over a pipe to the child. // Marshall the container into JSON since it won't be available in the namespace. containerJson, err := json.Marshal(container) @@ -31,7 +31,7 @@ func ExecIn(container *libcontainer.Container, nspid int, args []string) error { } // NsEnter is run after entering the namespace. -func NsEnter(container *libcontainer.Container, nspid int, args []string) error { +func NsEnter(container *libcontainer.Config, nspid int, args []string) error { // clear the current processes env and replace it with the environment // defined on the container if err := LoadContainerEnvironment(container); err != nil { diff --git a/namespaces/init.go b/namespaces/init.go index 905889ea..e916ca28 100644 --- a/namespaces/init.go +++ b/namespaces/init.go @@ -27,7 +27,7 @@ import ( // Move this to libcontainer package. // Init is the init process that first runs inside a new namespace to setup mounts, users, networking, // and other options required for the new container. -func Init(container *libcontainer.Container, uncleanRootfs, consolePath string, syncPipe *SyncPipe, args []string) error { +func Init(container *libcontainer.Config, uncleanRootfs, consolePath string, syncPipe *SyncPipe, args []string) error { rootfs, err := utils.ResolveRootfs(uncleanRootfs) if err != nil { return err @@ -161,7 +161,7 @@ func SetupUser(u string) error { // setupVethNetwork uses the Network config if it is not nil to initialize // the new veth interface inside the container for use by changing the name to eth0 // setting the MTU and IP address along with the default gateway -func setupNetwork(container *libcontainer.Container, context map[string]string) error { +func setupNetwork(container *libcontainer.Config, context map[string]string) error { for _, config := range container.Networks { strategy, err := network.GetStrategy(config.Type) if err != nil { @@ -176,7 +176,7 @@ func setupNetwork(container *libcontainer.Container, context map[string]string) return nil } -func setupRoute(container *libcontainer.Container) error { +func setupRoute(container *libcontainer.Config) error { for _, config := range container.Routes { if err := netlink.AddRoute(config.Destination, config.Source, config.Gateway, config.InterfaceName); err != nil { return err @@ -188,7 +188,7 @@ func setupRoute(container *libcontainer.Container) error { // FinalizeNamespace drops the caps, sets the correct user // and working dir, and closes any leaky file descriptors // before execing the command inside the namespace -func FinalizeNamespace(container *libcontainer.Container) error { +func FinalizeNamespace(container *libcontainer.Config) error { // Ensure that all non-standard fds we may have accidentally // inherited are marked close-on-exec so they stay out of the // container @@ -228,7 +228,7 @@ func FinalizeNamespace(container *libcontainer.Container) error { return nil } -func LoadContainerEnvironment(container *libcontainer.Container) error { +func LoadContainerEnvironment(container *libcontainer.Config) error { os.Clearenv() for _, pair := range container.Env { p := strings.SplitN(pair, "=", 2) diff --git a/namespaces/unsupported.go b/namespaces/unsupported.go index 9c44b658..8398b94d 100644 --- a/namespaces/unsupported.go +++ b/namespaces/unsupported.go @@ -7,19 +7,19 @@ import ( "github.com/docker/libcontainer/cgroups" ) -func Exec(container *libcontainer.Container, term Terminal, rootfs, dataPath string, args []string, createCommand CreateCommand, startCallback func()) (int, error) { +func Exec(container *libcontainer.Config, term Terminal, rootfs, dataPath string, args []string, createCommand CreateCommand, startCallback func()) (int, error) { return -1, ErrUnsupported } -func Init(container *libcontainer.Container, uncleanRootfs, consolePath string, syncPipe *SyncPipe, args []string) error { +func Init(container *libcontainer.Config, uncleanRootfs, consolePath string, syncPipe *SyncPipe, args []string) error { return ErrUnsupported } -func InitializeNetworking(container *libcontainer.Container, nspid int, pipe *SyncPipe) error { +func InitializeNetworking(container *libcontainer.Config, nspid int, pipe *SyncPipe) error { return ErrUnsupported } -func SetupCgroups(container *libcontainer.Container, nspid int) (cgroups.ActiveCgroup, error) { +func SetupCgroups(container *libcontainer.Config, nspid int) (cgroups.ActiveCgroup, error) { return nil, ErrUnsupported } diff --git a/nsinit/exec.go b/nsinit/exec.go index 5bbfd088..deaf963f 100644 --- a/nsinit/exec.go +++ b/nsinit/exec.go @@ -48,7 +48,7 @@ func execAction(context *cli.Context) { // error. // // Signals sent to the current process will be forwarded to container. -func startContainer(container *libcontainer.Container, term namespaces.Terminal, dataPath string, args []string) (int, error) { +func startContainer(container *libcontainer.Config, term namespaces.Terminal, dataPath string, args []string) (int, error) { var ( cmd *exec.Cmd sigc = make(chan os.Signal, 10) @@ -56,7 +56,7 @@ func startContainer(container *libcontainer.Container, term namespaces.Terminal, signal.Notify(sigc) - createCommand := func(container *libcontainer.Container, console, rootfs, dataPath, init string, pipe *os.File, args []string) *exec.Cmd { + createCommand := func(container *libcontainer.Config, console, rootfs, dataPath, init string, pipe *os.File, args []string) *exec.Cmd { cmd = namespaces.DefaultCreateCommand(container, console, rootfs, dataPath, init, pipe, args) if logPath != "" { cmd.Env = append(cmd.Env, fmt.Sprintf("log=%s", logPath)) diff --git a/nsinit/spec.go b/nsinit/spec.go index 24294ff3..beadc9d8 100644 --- a/nsinit/spec.go +++ b/nsinit/spec.go @@ -30,7 +30,7 @@ func specAction(context *cli.Context) { } // returns the container spec in json format. -func getContainerSpec(container *libcontainer.Container) (string, error) { +func getContainerSpec(container *libcontainer.Config) (string, error) { spec, err := json.MarshalIndent(container, "", "\t") if err != nil { return "", err diff --git a/nsinit/stats.go b/nsinit/stats.go index ff6a1ce5..41301bed 100644 --- a/nsinit/stats.go +++ b/nsinit/stats.go @@ -31,7 +31,7 @@ func statsAction(context *cli.Context) { } // returns the container stats in json format. -func getContainerStats(container *libcontainer.Container) (string, error) { +func getContainerStats(container *libcontainer.Config) (string, error) { stats, err := fs.GetStats(container.Cgroups) if err != nil { return "", err diff --git a/nsinit/utils.go b/nsinit/utils.go index bd49434e..fb672521 100644 --- a/nsinit/utils.go +++ b/nsinit/utils.go @@ -11,14 +11,14 @@ import ( "github.com/docker/libcontainer" ) -func loadContainer() (*libcontainer.Container, error) { +func loadContainer() (*libcontainer.Config, error) { f, err := os.Open(filepath.Join(dataPath, "container.json")) if err != nil { return nil, err } defer f.Close() - var container *libcontainer.Container + var container *libcontainer.Config if err := json.NewDecoder(f).Decode(&container); err != nil { return nil, err } @@ -51,8 +51,8 @@ func openLog(name string) error { return nil } -func loadContainerFromJson(rawData string) (*libcontainer.Container, error) { - var container *libcontainer.Container +func loadContainerFromJson(rawData string) (*libcontainer.Config, error) { + var container *libcontainer.Config if err := json.Unmarshal([]byte(rawData), &container); err != nil { return nil, err