Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add cgroup1/ to make cgroup1 and cgroup2 symmmetric #255

Merged
merged 3 commits into from
Nov 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ cgutil:
proto:
protobuild --quiet ${PACKAGES}
# Keep them Go-idiomatic and backward-compatible with the gogo/protobuf era.
go-fix-acronym -w -a '(Cpu|Tcp|Rss)' $(shell find stats/v1/ cgroup2/stats/ -name '*.pb.go')
go-fix-acronym -w -a '(Cpu|Tcp|Rss)' $(shell find cgroup1/stats/ cgroup2/stats/ -name '*.pb.go')
4 changes: 2 additions & 2 deletions Protobuild.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ generators = ["go"]

# Aggregrate the API descriptors to lock down API changes.
[[descriptors]]
prefix = "github.com/containerd/cgroups/stats/v1"
target = "stats/v1/metrics.pb.txt"
prefix = "github.com/containerd/cgroups/cgroup1/stats"
target = "cgroup1/stats/metrics.pb.txt"
ignore_files = [
"google/protobuf/descriptor.proto",
]
Expand Down
28 changes: 14 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ uses the v1 implementation of cgroups.

```go
shares := uint64(100)
control, err := cgroups.New(cgroups.V1, cgroups.StaticPath("/test"), &specs.LinuxResources{
control, err := cgroup1.New(cgroup1.Default, cgroup1.StaticPath("/test"), &specs.LinuxResources{
CPU: &specs.LinuxCPU{
Shares: &shares,
},
Expand All @@ -37,7 +37,7 @@ defer control.Delete()


```go
control, err := cgroups.New(cgroups.Systemd, cgroups.Slice("system.slice", "runc-test"), &specs.LinuxResources{
control, err := cgroup1.New(cgroup1.Systemd, cgroup1.Slice("system.slice", "runc-test"), &specs.LinuxResources{
CPU: &specs.CPU{
Shares: &shares,
},
Expand All @@ -48,13 +48,13 @@ control, err := cgroups.New(cgroups.Systemd, cgroups.Slice("system.slice", "runc
### Load an existing cgroup

```go
control, err = cgroups.Load(cgroups.V1, cgroups.StaticPath("/test"))
control, err = cgroup1.Load(cgroup1.Default, cgroups.StaticPath("/test"))
```

### Add a process to the cgroup

```go
if err := control.Add(cgroups.Process{Pid:1234}); err != nil {
if err := control.Add(cgroup1.Process{Pid:1234}); err != nil {
}
```

Expand Down Expand Up @@ -84,7 +84,7 @@ if err := control.Thaw(); err != nil {
### List all processes in the cgroup or recursively

```go
processes, err := control.Processes(cgroups.Devices, recursive)
processes, err := control.Processes(cgroup1.Devices, recursive)
```

### Get Stats on the cgroup
Expand All @@ -95,7 +95,7 @@ stats, err := control.Stat()

By adding `cgroups.IgnoreNotExist` all non-existent files will be ignored, e.g. swap memory stats without swap enabled
```go
stats, err := control.Stat(cgroups.IgnoreNotExist)
stats, err := control.Stat(cgroup1.IgnoreNotExist)
```

### Move process across cgroups
Expand All @@ -117,19 +117,19 @@ subCgroup, err := control.New("child", resources)
This allows you to get notified by an eventfd for v1 memory cgroups events.

```go
event := cgroups.MemoryThresholdEvent(50 * 1024 * 1024, false)
event := cgroup1.MemoryThresholdEvent(50 * 1024 * 1024, false)
efd, err := control.RegisterMemoryEvent(event)
```

```go
event := cgroups.MemoryPressureEvent(cgroups.MediumPressure, cgroups.DefaultMode)
event := cgroup1.MemoryPressureEvent(cgroup1.MediumPressure, cgroup1.DefaultMode)
efd, err := control.RegisterMemoryEvent(event)
```

```go
efd, err := control.OOMEventFD()
// or by using RegisterMemoryEvent
event := cgroups.OOMEvent()
event := cgroup1.OOMEvent()
efd, err := control.RegisterMemoryEvent(event)
```

Expand All @@ -153,14 +153,14 @@ so the resulting slice would be located here on disk:

```go
import (
cgroupsv2 "github.com/containerd/cgroups/v2"
"github.com/containerd/cgroups/v2/cgroup2"
specs "github.com/opencontainers/runtime-spec/specs-go"
)

res := cgroupsv2.Resources{}
res := cgroup2.Resources{}
// dummy PID of -1 is used for creating a "general slice" to be used as a parent cgroup.
// see https://github.com/containerd/cgroups/blob/1df78138f1e1e6ee593db155c6b369466f577651/v2/manager.go#L732-L735
m, err := cgroupsv2.NewSystemd("/", "my-cgroup-abc.slice", -1, &res)
m, err := cgroup2.NewSystemd("/", "my-cgroup-abc.slice", -1, &res)
if err != nil {
return err
}
Expand All @@ -169,7 +169,7 @@ if err != nil {
### Load an existing cgroup

```go
m, err := cgroupsv2.LoadSystemd("/", "my-cgroup-abc.slice")
m, err := cgroup2.LoadSystemd("/", "my-cgroup-abc.slice")
if err != nil {
return err
}
Expand All @@ -178,7 +178,7 @@ if err != nil {
### Delete a cgroup

```go
m, err := cgroupsv2.LoadSystemd("/", "my-cgroup-abc.slice")
m, err := cgroup2.LoadSystemd("/", "my-cgroup-abc.slice")
if err != nil {
return err
}
Expand Down
5 changes: 3 additions & 2 deletions blkio.go → cgroup1/blkio.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
limitations under the License.
*/

package cgroups
package cgroup1

import (
"bufio"
Expand All @@ -25,7 +25,8 @@ import (
"strconv"
"strings"

v1 "github.com/containerd/cgroups/v2/stats/v1"
v1 "github.com/containerd/cgroups/v2/cgroup1/stats"

specs "github.com/opencontainers/runtime-spec/specs-go"
)

Expand Down
4 changes: 2 additions & 2 deletions blkio_test.go → cgroup1/blkio_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@
limitations under the License.
*/

package cgroups
package cgroup1

import (
"os"
"strings"
"testing"

v1 "github.com/containerd/cgroups/v2/stats/v1"
v1 "github.com/containerd/cgroups/v2/cgroup1/stats"
)

const data = `major minor #blocks name
Expand Down
4 changes: 2 additions & 2 deletions cgroup.go → cgroup1/cgroup.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
limitations under the License.
*/

package cgroups
package cgroup1

import (
"errors"
Expand All @@ -28,7 +28,7 @@ import (
"syscall"
"time"

v1 "github.com/containerd/cgroups/v2/stats/v1"
v1 "github.com/containerd/cgroups/v2/cgroup1/stats"

"github.com/opencontainers/runtime-spec/specs-go"
)
Expand Down
2 changes: 1 addition & 1 deletion cgroup_test.go → cgroup1/cgroup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
limitations under the License.
*/

package cgroups
package cgroup1

import (
"fmt"
Expand Down
4 changes: 2 additions & 2 deletions control.go → cgroup1/control.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@
limitations under the License.
*/

package cgroups
package cgroup1

import (
"os"

v1 "github.com/containerd/cgroups/v2/stats/v1"
v1 "github.com/containerd/cgroups/v2/cgroup1/stats"
specs "github.com/opencontainers/runtime-spec/specs-go"
)

Expand Down
4 changes: 2 additions & 2 deletions cpu.go → cgroup1/cpu.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@
limitations under the License.
*/

package cgroups
package cgroup1

import (
"bufio"
"os"
"path/filepath"
"strconv"

v1 "github.com/containerd/cgroups/v2/stats/v1"
v1 "github.com/containerd/cgroups/v2/cgroup1/stats"
specs "github.com/opencontainers/runtime-spec/specs-go"
)

Expand Down
4 changes: 2 additions & 2 deletions cpuacct.go → cgroup1/cpuacct.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
limitations under the License.
*/

package cgroups
package cgroup1

import (
"bufio"
Expand All @@ -24,7 +24,7 @@ import (
"strconv"
"strings"

v1 "github.com/containerd/cgroups/v2/stats/v1"
v1 "github.com/containerd/cgroups/v2/cgroup1/stats"
)

const nanosecondsInSecond = 1000000000
Expand Down
2 changes: 1 addition & 1 deletion cpuacct_test.go → cgroup1/cpuacct_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
limitations under the License.
*/

package cgroups
package cgroup1

import (
"os"
Expand Down
2 changes: 1 addition & 1 deletion cpuset.go → cgroup1/cpuset.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
limitations under the License.
*/

package cgroups
package cgroup1

import (
"bytes"
Expand Down
2 changes: 1 addition & 1 deletion devices.go → cgroup1/devices.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
limitations under the License.
*/

package cgroups
package cgroup1

import (
"fmt"
Expand Down
2 changes: 1 addition & 1 deletion errors.go → cgroup1/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
limitations under the License.
*/

package cgroups
package cgroup1

import (
"errors"
Expand Down
2 changes: 1 addition & 1 deletion freezer.go → cgroup1/freezer.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
limitations under the License.
*/

package cgroups
package cgroup1

import (
"os"
Expand Down
2 changes: 1 addition & 1 deletion hierarchy.go → cgroup1/hierarchy.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
limitations under the License.
*/

package cgroups
package cgroup1

// Hierarchy enables both unified and split hierarchy for cgroups
type Hierarchy func() ([]Subsystem, error)
4 changes: 2 additions & 2 deletions hugetlb.go → cgroup1/hugetlb.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@
limitations under the License.
*/

package cgroups
package cgroup1

import (
"os"
"path/filepath"
"strconv"
"strings"

v1 "github.com/containerd/cgroups/v2/stats/v1"
v1 "github.com/containerd/cgroups/v2/cgroup1/stats"
specs "github.com/opencontainers/runtime-spec/specs-go"
)

Expand Down
4 changes: 2 additions & 2 deletions memory.go → cgroup1/memory.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
limitations under the License.
*/

package cgroups
package cgroup1

import (
"bufio"
Expand All @@ -25,7 +25,7 @@ import (
"strconv"
"strings"

v1 "github.com/containerd/cgroups/v2/stats/v1"
v1 "github.com/containerd/cgroups/v2/cgroup1/stats"
specs "github.com/opencontainers/runtime-spec/specs-go"
"golang.org/x/sys/unix"
)
Expand Down
4 changes: 2 additions & 2 deletions memory_test.go → cgroup1/memory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
limitations under the License.
*/

package cgroups
package cgroup1

import (
"fmt"
Expand All @@ -23,7 +23,7 @@ import (
"strings"
"testing"

v1 "github.com/containerd/cgroups/v2/stats/v1"
v1 "github.com/containerd/cgroups/v2/cgroup1/stats"
)

const memoryData = `cache 1
Expand Down
2 changes: 1 addition & 1 deletion mock_test.go → cgroup1/mock_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
limitations under the License.
*/

package cgroups
package cgroup1

import (
"os"
Expand Down
2 changes: 1 addition & 1 deletion named.go → cgroup1/named.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
limitations under the License.
*/

package cgroups
package cgroup1

import "path/filepath"

Expand Down
2 changes: 1 addition & 1 deletion named_test.go → cgroup1/named_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
limitations under the License.
*/

package cgroups
package cgroup1

import "testing"

Expand Down
2 changes: 1 addition & 1 deletion net_cls.go → cgroup1/net_cls.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
limitations under the License.
*/

package cgroups
package cgroup1

import (
"os"
Expand Down
2 changes: 1 addition & 1 deletion net_prio.go → cgroup1/net_prio.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
limitations under the License.
*/

package cgroups
package cgroup1

import (
"fmt"
Expand Down
Loading