Add k8s function to compress cgroupfs path to systemd
We are copying this to avoid getting in lots of dependencies. We also remove now unused function. Signed-off-by: Mrunal Patel <mrunalp@gmail.com>
This commit is contained in:
parent
8538c4067a
commit
612dcc0267
1 changed files with 11 additions and 37 deletions
|
@ -5,6 +5,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"net"
|
"net"
|
||||||
"os"
|
"os"
|
||||||
|
"path"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"regexp"
|
"regexp"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
@ -15,7 +16,6 @@ import (
|
||||||
"github.com/kubernetes-incubator/cri-o/libkpod/sandbox"
|
"github.com/kubernetes-incubator/cri-o/libkpod/sandbox"
|
||||||
"github.com/kubernetes-incubator/cri-o/oci"
|
"github.com/kubernetes-incubator/cri-o/oci"
|
||||||
"github.com/kubernetes-incubator/cri-o/pkg/annotations"
|
"github.com/kubernetes-incubator/cri-o/pkg/annotations"
|
||||||
"github.com/opencontainers/runc/libcontainer/cgroups/systemd"
|
|
||||||
"github.com/opencontainers/runtime-tools/generate"
|
"github.com/opencontainers/runtime-tools/generate"
|
||||||
"github.com/opencontainers/selinux/go-selinux/label"
|
"github.com/opencontainers/selinux/go-selinux/label"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
|
@ -572,40 +572,14 @@ func setupShm(podSandboxRunDir, mountLabel string) (shmPath string, err error) {
|
||||||
return shmPath, nil
|
return shmPath, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// convertCgroupNameToSystemd converts the internal cgroup name to a systemd name.
|
// convertCgroupFsNameToSystemd converts an expanded cgroupfs name to its systemd name.
|
||||||
// For example, the name /Burstable/pod_123-456 becomes Burstable-pod_123_456.slice
|
// For example, it will convert test.slice/test-a.slice/test-a-b.slice to become test-a-b.slice
|
||||||
// If outputToCgroupFs is true, it expands the systemd name into the cgroupfs form.
|
// NOTE: this is public right now to allow its usage in dockermanager and dockershim, ideally both those
|
||||||
// For example, it will return /Burstable.slice/Burstable-pod_123_456.slice in above scenario.
|
// code areas could use something from libcontainer if we get this style function upstream.
|
||||||
func convertCgroupNameToSystemd(name string, outputToCgroupFs bool) (systemdCgroup string, err error) {
|
func convertCgroupFsNameToSystemd(cgroupfsName string) (string, error) {
|
||||||
result := ""
|
// TODO: see if libcontainer systemd implementation could use something similar, and if so, move
|
||||||
if name != "" && name != "/" {
|
// this function up to that library. At that time, it would most likely do validation specific to systemd
|
||||||
// systemd treats - as a step in the hierarchy, we convert all - to _
|
// above and beyond the simple assumption here that the base of the path encodes the hierarchy
|
||||||
name = strings.Replace(name, "-", "_", -1)
|
// per systemd convention.
|
||||||
parts := strings.Split(name, "/")
|
return path.Base(cgroupfsName), nil
|
||||||
for _, part := range parts {
|
|
||||||
// ignore leading stuff for now
|
|
||||||
if part == "" {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
if len(result) > 0 {
|
|
||||||
result = result + "-"
|
|
||||||
}
|
|
||||||
result = result + part
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// root converts to -
|
|
||||||
result = "-"
|
|
||||||
}
|
|
||||||
// always have a .slice suffix
|
|
||||||
result = result + ".slice"
|
|
||||||
|
|
||||||
// if the caller desired the result in cgroupfs format...
|
|
||||||
if outputToCgroupFs {
|
|
||||||
var err error
|
|
||||||
result, err = systemd.ExpandSlice(result)
|
|
||||||
if err != nil {
|
|
||||||
return "", fmt.Errorf("error adapting cgroup name, input: %v, err: %v", name, err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return result, nil
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue