Rename Container -> Config.
Docker-DCO-1.1-Signed-off-by: Victor Marmol <vmarmol@google.com> (github: vmarmol)
This commit is contained in:
parent
e783cac215
commit
60b381e600
|
@ -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"`
|
||||
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
@ -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))
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue