Skip to content

Instantly share code, notes, and snippets.

@krsna1729
Last active March 24, 2021 05:24
Show Gist options
  • Save krsna1729/77128dfd579d54b2f71ad5ce4f4a0096 to your computer and use it in GitHub Desktop.
Save krsna1729/77128dfd579d54b2f71ad5ce4f4a0096 to your computer and use it in GitHub Desktop.
loading systemd cgroup example slice:prefix:ctr
package main
import (
"log"
"strings"
"github.com/containerd/cgroups"
"github.com/opencontainers/runc/libcontainer/cgroups/systemd"
)
func loadSystemdCgroup(cgroupsPath string) {
// Split into slice, prefix, ctr
parts := strings.Split(cgroupsPath, ":")
if (len(parts) != 3){
log.Fatalln("Invalid systemd cgroupspath", cgroupsPath)
}
slice := parts[0]
prefix := parts[1]
ctr := parts[2]
// Find the systemd path of the slice
slicePath, err := systemd.ExpandSlice(slice)
if err != nil {
log.Fatalln("Invalid slice", slice, err)
}
log.Println(slicePath)
// Load the cgroup of the container under the slice
_, err = cgroups.Load(cgroups.Systemd, cgroups.Slice(slicePath, prefix + "-" + ctr + ".scope"))
if err != nil {
log.Fatalln(err)
}
}
func main() {
loadSystemdCgroup("kubepods-besteffort-poda6537f3e_228a_4833_91d0_d5889163f4e2.slice:crio:afc6fe0403eff2f2fb82ef4bd5434854a2dc180d4a53c375a307ac9530cbc67d")
loadSystemdCgroup("kubepods-podf3807a4b_0e6b_49a6_a36c_73d66ab89d22.slice:crio:434bf679db8a064d13e7104e3d47e09314ecfca1d790010917d63dd8612c6198")
}
@krsna1729
Copy link
Author

2021/03/24 01:21:22 /kubepods.slice/kubepods-besteffort.slice/kubepods-besteffort-poda6537f3e_228a_4833_91d0_d5889163f4e2.slice
2021/03/24 01:21:22 /kubepods.slice/kubepods-podf3807a4b_0e6b_49a6_a36c_73d66ab89d22.slice

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment