Last active
March 24, 2021 05:24
-
-
Save krsna1729/77128dfd579d54b2f71ad5ce4f4a0096 to your computer and use it in GitHub Desktop.
loading systemd cgroup example slice:prefix:ctr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") | |
} |
Author
krsna1729
commented
Mar 24, 2021
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment