summaryrefslogtreecommitdiff
path: root/libpod
diff options
context:
space:
mode:
Diffstat (limited to 'libpod')
-rw-r--r--libpod/container.go2
-rw-r--r--libpod/container_api.go4
-rw-r--r--libpod/container_attach.go4
-rw-r--r--libpod/container_commit.go2
-rw-r--r--libpod/container_ffjson.go2
-rw-r--r--libpod/container_inspect.go2
-rw-r--r--libpod/container_internal.go12
-rw-r--r--libpod/container_internal_linux.go6
-rw-r--r--libpod/diff.go2
-rw-r--r--libpod/driver/driver.go2
-rw-r--r--libpod/image/filters.go2
-rw-r--r--libpod/image/image.go10
-rw-r--r--libpod/image/pull.go4
-rw-r--r--libpod/in_memory_state.go2
-rw-r--r--libpod/info.go2
-rw-r--r--libpod/networking_linux.go6
-rw-r--r--libpod/networking_unsupported.go2
-rw-r--r--libpod/oci.go6
-rw-r--r--libpod/oci_linux.go12
-rw-r--r--libpod/pod_api.go8
-rw-r--r--libpod/pod_ffjson.go2
-rw-r--r--libpod/pod_internal.go8
-rw-r--r--libpod/runtime.go8
-rw-r--r--libpod/runtime_img.go4
-rw-r--r--libpod/runtime_img_test.go2
-rw-r--r--libpod/runtime_pod_linux.go46
-rw-r--r--libpod/util_linux.go69
-rw-r--r--libpod/util_unsupported.go23
-rw-r--r--libpod/version.go2
29 files changed, 195 insertions, 61 deletions
diff --git a/libpod/container.go b/libpod/container.go
index 9f72bbe53..b79258c43 100644
--- a/libpod/container.go
+++ b/libpod/container.go
@@ -43,7 +43,7 @@ const CgroupfsDefaultCgroupParent = "/libpod_parent"
// SystemdDefaultCgroupParent is the cgroup parent for the systemd cgroup
// manager in libpod
-const SystemdDefaultCgroupParent = "system.slice"
+const SystemdDefaultCgroupParent = "machine.slice"
// LinuxNS represents a Linux namespace
type LinuxNS int
diff --git a/libpod/container_api.go b/libpod/container_api.go
index 62281218f..3e5b6ea53 100644
--- a/libpod/container_api.go
+++ b/libpod/container_api.go
@@ -8,11 +8,11 @@ import (
"strings"
"time"
+ "github.com/containers/libpod/libpod/driver"
+ "github.com/containers/libpod/pkg/inspect"
"github.com/containers/storage/pkg/stringid"
"github.com/docker/docker/daemon/caps"
"github.com/pkg/errors"
- "github.com/projectatomic/libpod/libpod/driver"
- "github.com/projectatomic/libpod/pkg/inspect"
"github.com/sirupsen/logrus"
"k8s.io/apimachinery/pkg/util/wait"
"k8s.io/client-go/tools/remotecommand"
diff --git a/libpod/container_attach.go b/libpod/container_attach.go
index 5bfea3a0e..3c4e0775d 100644
--- a/libpod/container_attach.go
+++ b/libpod/container_attach.go
@@ -7,10 +7,10 @@ import (
"os"
"path/filepath"
+ "github.com/containers/libpod/pkg/kubeutils"
+ "github.com/containers/libpod/utils"
"github.com/docker/docker/pkg/term"
"github.com/pkg/errors"
- "github.com/projectatomic/libpod/pkg/kubeutils"
- "github.com/projectatomic/libpod/utils"
"github.com/sirupsen/logrus"
"golang.org/x/sys/unix"
"k8s.io/client-go/tools/remotecommand"
diff --git a/libpod/container_commit.go b/libpod/container_commit.go
index 929850cbe..de659c982 100644
--- a/libpod/container_commit.go
+++ b/libpod/container_commit.go
@@ -5,10 +5,10 @@ import (
"strings"
is "github.com/containers/image/storage"
+ "github.com/containers/libpod/libpod/image"
"github.com/pkg/errors"
"github.com/projectatomic/buildah"
"github.com/projectatomic/buildah/util"
- "github.com/projectatomic/libpod/libpod/image"
"github.com/sirupsen/logrus"
)
diff --git a/libpod/container_ffjson.go b/libpod/container_ffjson.go
index 2af9d63f5..4ae77eb0c 100644
--- a/libpod/container_ffjson.go
+++ b/libpod/container_ffjson.go
@@ -1,5 +1,5 @@
// Code generated by ffjson <https://github.com/pquerna/ffjson>. DO NOT EDIT.
-// source: /home/mcs/code/gopath//src/github.com/projectatomic/libpod/libpod/container.go
+// source: /home/mcs/code/gopath//src/github.com/containers/libpod/libpod/container.go
package libpod
diff --git a/libpod/container_inspect.go b/libpod/container_inspect.go
index dec0b47b4..a7ee911a6 100644
--- a/libpod/container_inspect.go
+++ b/libpod/container_inspect.go
@@ -1,8 +1,8 @@
package libpod
import (
+ "github.com/containers/libpod/pkg/inspect"
"github.com/cri-o/ocicni/pkg/ocicni"
- "github.com/projectatomic/libpod/pkg/inspect"
"github.com/sirupsen/logrus"
)
diff --git a/libpod/container_internal.go b/libpod/container_internal.go
index 535f34200..32036ca7a 100644
--- a/libpod/container_internal.go
+++ b/libpod/container_internal.go
@@ -13,6 +13,12 @@ import (
"syscall"
"time"
+ "github.com/containers/libpod/pkg/chrootuser"
+ "github.com/containers/libpod/pkg/hooks"
+ "github.com/containers/libpod/pkg/hooks/exec"
+ "github.com/containers/libpod/pkg/rootless"
+ "github.com/containers/libpod/pkg/secrets"
+ "github.com/containers/libpod/pkg/util"
"github.com/containers/storage"
"github.com/containers/storage/pkg/archive"
"github.com/containers/storage/pkg/chrootarchive"
@@ -22,12 +28,6 @@ import (
"github.com/opencontainers/runtime-tools/generate"
"github.com/opencontainers/selinux/go-selinux/label"
"github.com/pkg/errors"
- "github.com/projectatomic/libpod/pkg/chrootuser"
- "github.com/projectatomic/libpod/pkg/hooks"
- "github.com/projectatomic/libpod/pkg/hooks/exec"
- "github.com/projectatomic/libpod/pkg/rootless"
- "github.com/projectatomic/libpod/pkg/secrets"
- "github.com/projectatomic/libpod/pkg/util"
"github.com/sirupsen/logrus"
"github.com/ulule/deepcopier"
"golang.org/x/text/language"
diff --git a/libpod/container_internal_linux.go b/libpod/container_internal_linux.go
index 59fb6af87..2aba1abde 100644
--- a/libpod/container_internal_linux.go
+++ b/libpod/container_internal_linux.go
@@ -10,14 +10,14 @@ import (
"syscall"
"time"
+ crioAnnotations "github.com/containers/libpod/pkg/annotations"
+ "github.com/containers/libpod/pkg/chrootuser"
+ "github.com/containers/libpod/pkg/rootless"
"github.com/containers/storage/pkg/idtools"
spec "github.com/opencontainers/runtime-spec/specs-go"
"github.com/opencontainers/runtime-tools/generate"
"github.com/opencontainers/selinux/go-selinux/label"
"github.com/pkg/errors"
- crioAnnotations "github.com/projectatomic/libpod/pkg/annotations"
- "github.com/projectatomic/libpod/pkg/chrootuser"
- "github.com/projectatomic/libpod/pkg/rootless"
"github.com/sirupsen/logrus"
"golang.org/x/sys/unix"
)
diff --git a/libpod/diff.go b/libpod/diff.go
index 6e07f3049..e86a186ed 100644
--- a/libpod/diff.go
+++ b/libpod/diff.go
@@ -1,9 +1,9 @@
package libpod
import (
+ "github.com/containers/libpod/libpod/layers"
"github.com/containers/storage/pkg/archive"
"github.com/pkg/errors"
- "github.com/projectatomic/libpod/libpod/layers"
)
// GetDiff returns the differences between the two images, layers, or containers
diff --git a/libpod/driver/driver.go b/libpod/driver/driver.go
index d84ce8d3c..717ac2a4d 100644
--- a/libpod/driver/driver.go
+++ b/libpod/driver/driver.go
@@ -1,8 +1,8 @@
package driver
import (
+ "github.com/containers/libpod/pkg/inspect"
cstorage "github.com/containers/storage"
- "github.com/projectatomic/libpod/pkg/inspect"
)
// GetDriverName returns the name of the driver for the given store
diff --git a/libpod/image/filters.go b/libpod/image/filters.go
index 95ef3b44a..d0c3adfb5 100644
--- a/libpod/image/filters.go
+++ b/libpod/image/filters.go
@@ -5,7 +5,7 @@ import (
"strings"
"time"
- "github.com/projectatomic/libpod/pkg/inspect"
+ "github.com/containers/libpod/pkg/inspect"
)
// ResultFilter is a mock function for image filtering
diff --git a/libpod/image/image.go b/libpod/image/image.go
index 57891a463..2c70c6316 100644
--- a/libpod/image/image.go
+++ b/libpod/image/image.go
@@ -18,16 +18,16 @@ import (
"github.com/containers/image/transports"
"github.com/containers/image/transports/alltransports"
"github.com/containers/image/types"
+ "github.com/containers/libpod/libpod/common"
+ "github.com/containers/libpod/libpod/driver"
+ "github.com/containers/libpod/pkg/inspect"
+ "github.com/containers/libpod/pkg/registries"
+ "github.com/containers/libpod/pkg/util"
"github.com/containers/storage"
"github.com/containers/storage/pkg/reexec"
"github.com/opencontainers/go-digest"
ociv1 "github.com/opencontainers/image-spec/specs-go/v1"
"github.com/pkg/errors"
- "github.com/projectatomic/libpod/libpod/common"
- "github.com/projectatomic/libpod/libpod/driver"
- "github.com/projectatomic/libpod/pkg/inspect"
- "github.com/projectatomic/libpod/pkg/registries"
- "github.com/projectatomic/libpod/pkg/util"
"github.com/sirupsen/logrus"
)
diff --git a/libpod/image/pull.go b/libpod/image/pull.go
index 6c470b552..d8483878e 100644
--- a/libpod/image/pull.go
+++ b/libpod/image/pull.go
@@ -18,9 +18,9 @@ import (
"github.com/containers/image/transports"
"github.com/containers/image/transports/alltransports"
"github.com/containers/image/types"
+ "github.com/containers/libpod/pkg/registries"
+ "github.com/containers/libpod/pkg/util"
"github.com/pkg/errors"
- "github.com/projectatomic/libpod/pkg/registries"
- "github.com/projectatomic/libpod/pkg/util"
"github.com/sirupsen/logrus"
)
diff --git a/libpod/in_memory_state.go b/libpod/in_memory_state.go
index 0327b331e..78e765ccd 100644
--- a/libpod/in_memory_state.go
+++ b/libpod/in_memory_state.go
@@ -3,9 +3,9 @@ package libpod
import (
"strings"
+ "github.com/containers/libpod/pkg/registrar"
"github.com/containers/storage/pkg/truncindex"
"github.com/pkg/errors"
- "github.com/projectatomic/libpod/pkg/registrar"
)
// TODO: Maybe separate idIndex for pod/containers
diff --git a/libpod/info.go b/libpod/info.go
index 1108845ea..3add1ce0f 100644
--- a/libpod/info.go
+++ b/libpod/info.go
@@ -10,9 +10,9 @@ import (
"strings"
"time"
+ "github.com/containers/libpod/utils"
"github.com/containers/storage/pkg/system"
"github.com/pkg/errors"
- "github.com/projectatomic/libpod/utils"
)
// InfoData holds the info type, i.e store, host etc and the data for each type
diff --git a/libpod/networking_linux.go b/libpod/networking_linux.go
index 2186b4ac9..e5f935e30 100644
--- a/libpod/networking_linux.go
+++ b/libpod/networking_linux.go
@@ -14,11 +14,11 @@ import (
cnitypes "github.com/containernetworking/cni/pkg/types/current"
"github.com/containernetworking/plugins/pkg/ns"
+ "github.com/containers/libpod/pkg/inspect"
+ "github.com/containers/libpod/pkg/netns"
+ "github.com/containers/libpod/utils"
"github.com/cri-o/ocicni/pkg/ocicni"
"github.com/pkg/errors"
- "github.com/projectatomic/libpod/pkg/inspect"
- "github.com/projectatomic/libpod/pkg/netns"
- "github.com/projectatomic/libpod/utils"
"github.com/sirupsen/logrus"
"github.com/vishvananda/netlink"
"golang.org/x/sys/unix"
diff --git a/libpod/networking_unsupported.go b/libpod/networking_unsupported.go
index 070985c47..3a8ac4455 100644
--- a/libpod/networking_unsupported.go
+++ b/libpod/networking_unsupported.go
@@ -3,7 +3,7 @@
package libpod
import (
- "github.com/projectatomic/libpod/pkg/inspect"
+ "github.com/containers/libpod/pkg/inspect"
)
func (r *Runtime) setupRootlessNetNS(ctr *Container) (err error) {
diff --git a/libpod/oci.go b/libpod/oci.go
index d98ab433f..9021a522b 100644
--- a/libpod/oci.go
+++ b/libpod/oci.go
@@ -15,21 +15,21 @@ import (
"syscall"
"time"
+ "github.com/containers/libpod/pkg/ctime"
+ "github.com/containers/libpod/pkg/rootless"
"github.com/coreos/go-systemd/activation"
"github.com/cri-o/ocicni/pkg/ocicni"
spec "github.com/opencontainers/runtime-spec/specs-go"
"github.com/opencontainers/selinux/go-selinux"
"github.com/opencontainers/selinux/go-selinux/label"
"github.com/pkg/errors"
- "github.com/projectatomic/libpod/pkg/ctime"
- "github.com/projectatomic/libpod/pkg/rootless"
"github.com/sirupsen/logrus"
"golang.org/x/sys/unix"
kwait "k8s.io/apimachinery/pkg/util/wait"
// TODO import these functions into libpod and remove the import
// Trying to keep libpod from depending on CRI-O code
- "github.com/projectatomic/libpod/utils"
+ "github.com/containers/libpod/utils"
)
// OCI code is undergoing heavy rewrite
diff --git a/libpod/oci_linux.go b/libpod/oci_linux.go
index bdf859d7d..335a7eec3 100644
--- a/libpod/oci_linux.go
+++ b/libpod/oci_linux.go
@@ -12,9 +12,9 @@ import (
"sync"
"github.com/containerd/cgroups"
+ "github.com/containers/libpod/utils"
"github.com/containers/storage/pkg/idtools"
spec "github.com/opencontainers/runtime-spec/specs-go"
- "github.com/projectatomic/libpod/utils"
"github.com/sirupsen/logrus"
"golang.org/x/sys/unix"
)
@@ -24,8 +24,14 @@ func (r *OCIRuntime) moveConmonToCgroup(ctr *Container, cgroupParent string, cmd
if r.cgroupManager == SystemdCgroupsManager {
unitName := createUnitName("libpod-conmon", ctr.ID())
- logrus.Infof("Running conmon under slice %s and unitName %s", cgroupParent, unitName)
- if err := utils.RunUnderSystemdScope(cmd.Process.Pid, cgroupParent, unitName); err != nil {
+ realCgroupParent := cgroupParent
+ splitParent := strings.Split(cgroupParent, "/")
+ if strings.HasSuffix(cgroupParent, ".slice") && len(splitParent) > 1 {
+ realCgroupParent = splitParent[len(splitParent)-1]
+ }
+
+ logrus.Infof("Running conmon under slice %s and unitName %s", realCgroupParent, unitName)
+ if err := utils.RunUnderSystemdScope(cmd.Process.Pid, realCgroupParent, unitName); err != nil {
logrus.Warnf("Failed to add conmon to systemd sandbox cgroup: %v", err)
}
} else {
diff --git a/libpod/pod_api.go b/libpod/pod_api.go
index 82cf7b727..d1e19063c 100644
--- a/libpod/pod_api.go
+++ b/libpod/pod_api.go
@@ -55,7 +55,11 @@ func (p *Pod) Start(ctx context.Context) (map[string]error, error) {
startNode(ctx, node, false, ctrErrors, ctrsVisited, false)
}
- return ctrErrors, nil
+ if len(ctrErrors) > 0 {
+ return ctrErrors, errors.Wrapf(ErrCtrExists, "error starting some containers")
+ }
+
+ return nil, nil
}
// Stop stops all containers within a pod that are not already stopped
@@ -352,7 +356,7 @@ func (p *Pod) Kill(signal uint) (map[string]error, error) {
}
if len(ctrErrors) > 0 {
- return ctrErrors, nil
+ return ctrErrors, errors.Wrapf(ErrCtrExists, "error killing some containers")
}
return nil, nil
diff --git a/libpod/pod_ffjson.go b/libpod/pod_ffjson.go
index 58b08d61b..a244dadbc 100644
--- a/libpod/pod_ffjson.go
+++ b/libpod/pod_ffjson.go
@@ -1,5 +1,5 @@
// Code generated by ffjson <https://github.com/pquerna/ffjson>. DO NOT EDIT.
-// source: /home/mcs/code/gopath//src/github.com/projectatomic/libpod/libpod/pod.go
+// source: /home/dwalsh/go/src/github.com/containers/libpod/libpod/pod.go
package libpod
diff --git a/libpod/pod_internal.go b/libpod/pod_internal.go
index c8d8405bb..1ba4487ab 100644
--- a/libpod/pod_internal.go
+++ b/libpod/pod_internal.go
@@ -2,6 +2,7 @@ package libpod
import (
"context"
+ "fmt"
"path/filepath"
"strings"
"time"
@@ -67,8 +68,11 @@ func (p *Pod) refresh() error {
if p.config.UsePodCgroup {
switch p.runtime.config.CgroupManager {
case SystemdCgroupsManager:
- // NOOP for now, until proper systemd cgroup management
- // is implemented
+ cgroupPath, err := systemdSliceFromPath(p.config.CgroupParent, fmt.Sprintf("libpod_pod_%s", p.ID()))
+ if err != nil {
+ logrus.Errorf("Error creating CGroup for pod %s: %v", p.ID(), err)
+ }
+ p.state.CgroupPath = cgroupPath
case CgroupfsCgroupsManager:
p.state.CgroupPath = filepath.Join(p.config.CgroupParent, p.ID())
diff --git a/libpod/runtime.go b/libpod/runtime.go
index cd5501de1..73f516cd5 100644
--- a/libpod/runtime.go
+++ b/libpod/runtime.go
@@ -11,14 +11,14 @@ import (
"github.com/BurntSushi/toml"
is "github.com/containers/image/storage"
"github.com/containers/image/types"
+ "github.com/containers/libpod/libpod/image"
+ "github.com/containers/libpod/pkg/hooks"
+ sysreg "github.com/containers/libpod/pkg/registries"
+ "github.com/containers/libpod/pkg/rootless"
"github.com/containers/storage"
"github.com/cri-o/ocicni/pkg/ocicni"
"github.com/docker/docker/pkg/namesgenerator"
"github.com/pkg/errors"
- "github.com/projectatomic/libpod/libpod/image"
- "github.com/projectatomic/libpod/pkg/hooks"
- sysreg "github.com/projectatomic/libpod/pkg/registries"
- "github.com/projectatomic/libpod/pkg/rootless"
"github.com/sirupsen/logrus"
"github.com/ulule/deepcopier"
)
diff --git a/libpod/runtime_img.go b/libpod/runtime_img.go
index 47dad41da..2e4e1b26f 100644
--- a/libpod/runtime_img.go
+++ b/libpod/runtime_img.go
@@ -5,13 +5,13 @@ import (
"fmt"
"io"
+ "github.com/containers/libpod/libpod/common"
+ "github.com/containers/libpod/libpod/image"
"github.com/containers/storage"
"github.com/containers/storage/pkg/archive"
ociv1 "github.com/opencontainers/image-spec/specs-go/v1"
"github.com/pkg/errors"
"github.com/projectatomic/buildah/imagebuildah"
- "github.com/projectatomic/libpod/libpod/common"
- "github.com/projectatomic/libpod/libpod/image"
)
// Runtime API
diff --git a/libpod/runtime_img_test.go b/libpod/runtime_img_test.go
index c608c1b25..2bccb2752 100644
--- a/libpod/runtime_img_test.go
+++ b/libpod/runtime_img_test.go
@@ -6,7 +6,7 @@ import (
"reflect"
"testing"
- sysreg "github.com/projectatomic/libpod/pkg/registries"
+ sysreg "github.com/containers/libpod/pkg/registries"
"github.com/stretchr/testify/assert"
)
diff --git a/libpod/runtime_pod_linux.go b/libpod/runtime_pod_linux.go
index 58affa45f..3592c2fee 100644
--- a/libpod/runtime_pod_linux.go
+++ b/libpod/runtime_pod_linux.go
@@ -4,6 +4,7 @@ package libpod
import (
"context"
+ "fmt"
"path"
"path/filepath"
"strings"
@@ -70,12 +71,23 @@ func (r *Runtime) NewPod(options ...PodCreateOption) (*Pod, error) {
} else if len(pod.config.CgroupParent) < 6 || !strings.HasSuffix(path.Base(pod.config.CgroupParent), ".slice") {
return nil, errors.Wrapf(ErrInvalidArg, "did not receive systemd slice as cgroup parent when using systemd to manage cgroups")
}
- // Creating CGroup path is currently a NOOP until proper systemd
- // cgroup management is merged
+ // If we are set to use pod cgroups, set the cgroup parent that
+ // all containers in the pod will share
+ if pod.config.UsePodCgroup {
+ cgroupPath, err := systemdSliceFromPath(pod.config.CgroupParent, fmt.Sprintf("libpod_pod_%s", pod.ID()))
+ if err != nil {
+ return nil, errors.Wrapf(err, "unable to create pod cgroup for pod %s", pod.ID())
+ }
+ pod.state.CgroupPath = cgroupPath
+ }
default:
return nil, errors.Wrapf(ErrInvalidArg, "unsupported CGroup manager: %s - cannot validate cgroup parent", r.config.CgroupManager)
}
+ if pod.config.UsePodCgroup {
+ logrus.Debugf("Got pod cgroup as %s", pod.state.CgroupPath)
+ }
+
if err := r.state.AddPod(pod); err != nil {
return nil, errors.Wrapf(err, "error adding pod to state")
}
@@ -91,11 +103,20 @@ func (r *Runtime) removePod(ctx context.Context, p *Pod, removeCtrs, force bool)
return ErrRuntimeStopped
}
+ if !p.valid {
+ if ok, _ := r.state.HasPod(p.ID()); !ok {
+ // Pod was either already removed, or never existed to
+ // begin with
+ return nil
+ }
+ }
+
p.lock.Lock()
defer p.lock.Unlock()
- if !p.valid {
- return ErrPodRemoved
+ // Force a pod update
+ if err := p.updatePod(); err != nil {
+ return err
}
ctrs, err := r.state.PodContainers(p)
@@ -216,20 +237,27 @@ func (r *Runtime) removePod(ctx context.Context, p *Pod, removeCtrs, force bool)
// Remove pod cgroup, if present
if p.state.CgroupPath != "" {
+ logrus.Debugf("Removing pod cgroup %s", p.state.CgroupPath)
+
switch p.runtime.config.CgroupManager {
case SystemdCgroupsManager:
- // NOOP for now, until proper systemd cgroup management
- // is implemented
+ if err := deleteSystemdCgroup(p.state.CgroupPath); err != nil {
+ // The pod is already almost gone.
+ // No point in hard-failing if we fail
+ // this bit of cleanup.
+ logrus.Errorf("Error deleting pod %s cgroup %s: %v", p.ID(), p.state.CgroupPath, err)
+ }
case CgroupfsCgroupsManager:
// Delete the cgroupfs cgroup
- logrus.Debugf("Removing pod cgroup %s", p.state.CgroupPath)
-
cgroup, err := cgroups.Load(cgroups.V1, cgroups.StaticPath(p.state.CgroupPath))
if err != nil && err != cgroups.ErrCgroupDeleted {
return err
} else if err == nil {
if err := cgroup.Delete(); err != nil {
- return err
+ // The pod is already almost gone.
+ // No point in hard-failing if we fail
+ // this bit of cleanup.
+ logrus.Errorf("Error deleting pod %s cgroup %s: %v", p.ID(), p.state.CgroupPath, err)
}
}
default:
diff --git a/libpod/util_linux.go b/libpod/util_linux.go
new file mode 100644
index 000000000..0cd486379
--- /dev/null
+++ b/libpod/util_linux.go
@@ -0,0 +1,69 @@
+// +build linux
+
+package libpod
+
+import (
+ "fmt"
+ "strings"
+
+ "github.com/containerd/cgroups"
+ spec "github.com/opencontainers/runtime-spec/specs-go"
+ "github.com/pkg/errors"
+ "github.com/sirupsen/logrus"
+)
+
+// systemdSliceFromPath makes a new systemd slice under the given parent with
+// the given name.
+// The parent must be a slice. The name must NOT include ".slice"
+func systemdSliceFromPath(parent, name string) (string, error) {
+ cgroupPath, err := assembleSystemdCgroupName(parent, name)
+ if err != nil {
+ return "", err
+ }
+
+ logrus.Debugf("Created cgroup path %s for parent %s and name %s", cgroupPath, parent, name)
+
+ if err := makeSystemdCgroup(cgroupPath); err != nil {
+ return "", errors.Wrapf(err, "error creating cgroup %s", cgroupPath)
+ }
+
+ logrus.Debugf("Created cgroup %s", cgroupPath)
+
+ return cgroupPath, nil
+}
+
+// makeSystemdCgroup creates a systemd CGroup at the given location.
+func makeSystemdCgroup(path string) error {
+ controller, err := cgroups.NewSystemd(SystemdDefaultCgroupParent)
+ if err != nil {
+ return err
+ }
+
+ return controller.Create(path, &spec.LinuxResources{})
+}
+
+// deleteSystemdCgroup deletes the systemd cgroup at the given location
+func deleteSystemdCgroup(path string) error {
+ controller, err := cgroups.NewSystemd(SystemdDefaultCgroupParent)
+ if err != nil {
+ return err
+ }
+
+ return controller.Delete(path)
+}
+
+// assembleSystemdCgroupName creates a systemd cgroup path given a base and
+// a new component to add.
+// The base MUST be systemd slice (end in .slice)
+func assembleSystemdCgroupName(baseSlice, newSlice string) (string, error) {
+ const sliceSuffix = ".slice"
+
+ if !strings.HasSuffix(baseSlice, sliceSuffix) {
+ return "", errors.Wrapf(ErrInvalidArg, "cannot assemble cgroup path with base %q - must end in .slice", baseSlice)
+ }
+
+ noSlice := strings.TrimSuffix(baseSlice, sliceSuffix)
+ final := fmt.Sprintf("%s/%s-%s%s", baseSlice, noSlice, newSlice, sliceSuffix)
+
+ return final, nil
+}
diff --git a/libpod/util_unsupported.go b/libpod/util_unsupported.go
new file mode 100644
index 000000000..d598b465f
--- /dev/null
+++ b/libpod/util_unsupported.go
@@ -0,0 +1,23 @@
+// +build !linux
+
+package libpod
+
+import (
+ "github.com/pkg/errors"
+)
+
+func systemdSliceFromPath(parent, name string) (string, error) {
+ return "", errors.Wrapf(ErrOSNotSupported, "cgroups are not supported on non-linux OSes")
+}
+
+func makeSystemdCgroup(path string) error {
+ return errors.Wrapf(ErrOSNotSupported, "cgroups are not supported on non-linux OSes")
+}
+
+func deleteSystemdCgroup(path string) error {
+ return errors.Wrapf(ErrOSNotSupported, "cgroups are not supported on non-linux OSes")
+}
+
+func assembleSystemdCgroupName(baseSlice, newSlice string) (string, error) {
+ return "", errors.Wrapf(ErrOSNotSupported, "cgroups are not supported on non-linux OSes")
+}
diff --git a/libpod/version.go b/libpod/version.go
index cb3e6b16d..5e7cd83c9 100644
--- a/libpod/version.go
+++ b/libpod/version.go
@@ -4,7 +4,7 @@ import (
"runtime"
"strconv"
- podmanVersion "github.com/projectatomic/libpod/version"
+ podmanVersion "github.com/containers/libpod/version"
)
// Overwritten at build time