diff options
Diffstat (limited to 'libpod')
-rw-r--r-- | libpod/container.go | 29 | ||||
-rw-r--r-- | libpod/networking.go | 3 | ||||
-rw-r--r-- | libpod/options.go | 14 | ||||
-rw-r--r-- | libpod/runtime.go | 6 | ||||
-rw-r--r-- | libpod/util.go | 2 |
5 files changed, 43 insertions, 11 deletions
diff --git a/libpod/container.go b/libpod/container.go index fbc01be0a..dfd77938d 100644 --- a/libpod/container.go +++ b/libpod/container.go @@ -8,7 +8,6 @@ import ( "net" "os" "path/filepath" - "strconv" "syscall" "time" @@ -685,12 +684,32 @@ func (c *Container) Init() (err error) { if c.config.CreateNetNS { g.AddOrReplaceLinuxNamespace(spec.NetworkNamespace, c.state.NetNS.Path()) } + // Remove default /etc/shm mount + g.RemoveMount("/dev/shm") // Mount ShmDir from host into container - g.AddBindMount(c.config.ShmDir, "/dev/shm", []string{"rw"}) + shmMnt := spec.Mount{ + Type: "bind", + Source: c.config.ShmDir, + Destination: "/dev/shm", + Options: []string{"rw", "bind"}, + } + g.AddMount(shmMnt) // Bind mount resolv.conf - g.AddBindMount(runDirResolv, "/etc/resolv.conf", []string{"rw"}) + resolvMnt := spec.Mount{ + Type: "bind", + Source: runDirResolv, + Destination: "/etc/resolv.conf", + Options: []string{"rw", "bind"}, + } + g.AddMount(resolvMnt) // Bind mount hosts - g.AddBindMount(runDirHosts, "/etc/hosts", []string{"rw"}) + hostsMnt := spec.Mount{ + Type: "bind", + Source: runDirHosts, + Destination: "/etc/hosts", + Options: []string{"rw", "bind"}, + } + g.AddMount(hostsMnt) if c.config.User != "" { if !c.state.Mounted { @@ -1162,7 +1181,7 @@ func (c *Container) mountStorage() (err error) { } if !mounted { - shmOptions := "mode=1777,size=" + strconv.Itoa(DefaultShmSize) + shmOptions := fmt.Sprintf("mode=1777,size=%d", c.config.ShmSize) if err := unix.Mount("shm", c.config.ShmDir, "tmpfs", unix.MS_NOEXEC|unix.MS_NOSUID|unix.MS_NODEV, label.FormatMountLabel(shmOptions, c.config.MountLabel)); err != nil { return errors.Wrapf(err, "failed to mount shm tmpfs %q", c.config.ShmDir) diff --git a/libpod/networking.go b/libpod/networking.go index 456830708..41bd65d25 100644 --- a/libpod/networking.go +++ b/libpod/networking.go @@ -38,7 +38,8 @@ func (r *Runtime) createNetNS(ctr *Container) (err error) { podNetwork := getPodNetwork(ctr.ID(), ctr.Name(), ctrNS.Path(), ctr.config.PortMappings) - if err := r.netPlugin.SetUpPod(podNetwork); err != nil { + _, err = r.netPlugin.SetUpPod(podNetwork) + if err != nil { return errors.Wrapf(err, "error configuring network namespace for container %s", ctr.ID()) } diff --git a/libpod/options.go b/libpod/options.go index 75ad7acfb..1429f16c3 100644 --- a/libpod/options.go +++ b/libpod/options.go @@ -275,7 +275,7 @@ func WithCNIPluginDir(dir string) RuntimeOption { return ErrRuntimeFinalized } - rt.config.CNIPluginDir = dir + rt.config.CNIPluginDir = []string{dir} return nil } @@ -295,6 +295,18 @@ func WithShmDir(dir string) CtrCreateOption { } } +// WithShmSize sets the size of /dev/shm tmpfs mount +func WithShmSize(size int64) CtrCreateOption { + return func(ctr *Container) error { + if ctr.valid { + return ErrCtrFinalized + } + + ctr.config.ShmSize = size + return nil + } +} + // WithSELinuxLabels sets the mount label for SELinux func WithSELinuxLabels(processLabel, mountLabel string) CtrCreateOption { return func(ctr *Container) error { diff --git a/libpod/runtime.go b/libpod/runtime.go index aed6acd86..d0aa481cf 100644 --- a/libpod/runtime.go +++ b/libpod/runtime.go @@ -51,7 +51,7 @@ type RuntimeConfig struct { MaxLogSize int64 NoPivotRoot bool CNIConfigDir string - CNIPluginDir string + CNIPluginDir []string } var ( @@ -73,7 +73,7 @@ var ( MaxLogSize: -1, NoPivotRoot: false, CNIConfigDir: "/etc/cni/net.d/", - CNIPluginDir: "/usr/libexec/cni", + CNIPluginDir: []string{"/usr/libexec/cni", "/opt/cni/bin"}, } ) @@ -173,7 +173,7 @@ func NewRuntime(options ...RuntimeOption) (runtime *Runtime, err error) { } // Set up the CNI net plugin - netPlugin, err := ocicni.InitCNI(runtime.config.CNIConfigDir, runtime.config.CNIPluginDir) + netPlugin, err := ocicni.InitCNI(runtime.config.CNIConfigDir, runtime.config.CNIPluginDir...) if err != nil { return nil, errors.Wrapf(err, "error configuring CNI network plugin") } diff --git a/libpod/util.go b/libpod/util.go index de5c3ff31..1a033a940 100644 --- a/libpod/util.go +++ b/libpod/util.go @@ -24,7 +24,7 @@ const ( func WriteFile(content string, path string) error { baseDir := filepath.Dir(path) if baseDir != "" { - if _, err := os.Stat(path); err != nil { + if _, err := os.Stat(baseDir); err != nil { return err } } |