Skip to content

Commit cc78c6c

Browse files
author
Kazuyoshi Kato
authored
Merge pull request #255 from kzys/cgroup1
Add cgroup1/ to make cgroup1 and cgroup2 symmmetric
2 parents 75ab0f6 + a78a2fc commit cc78c6c

43 files changed

Lines changed: 725 additions & 697 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,4 @@ cgutil:
2323
proto:
2424
protobuild --quiet ${PACKAGES}
2525
# Keep them Go-idiomatic and backward-compatible with the gogo/protobuf era.
26-
go-fix-acronym -w -a '(Cpu|Tcp|Rss)' $(shell find stats/v1/ cgroup2/stats/ -name '*.pb.go')
26+
go-fix-acronym -w -a '(Cpu|Tcp|Rss)' $(shell find cgroup1/stats/ cgroup2/stats/ -name '*.pb.go')

Protobuild.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ generators = ["go"]
1515

1616
# Aggregrate the API descriptors to lock down API changes.
1717
[[descriptors]]
18-
prefix = "github.com/containerd/cgroups/stats/v1"
19-
target = "stats/v1/metrics.pb.txt"
18+
prefix = "github.com/containerd/cgroups/cgroup1/stats"
19+
target = "cgroup1/stats/metrics.pb.txt"
2020
ignore_files = [
2121
"google/protobuf/descriptor.proto",
2222
]

README.md

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ uses the v1 implementation of cgroups.
2525

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

3838

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

5050
```go
51-
control, err = cgroups.Load(cgroups.V1, cgroups.StaticPath("/test"))
51+
control, err = cgroup1.Load(cgroup1.Default, cgroups.StaticPath("/test"))
5252
```
5353

5454
### Add a process to the cgroup
5555

5656
```go
57-
if err := control.Add(cgroups.Process{Pid:1234}); err != nil {
57+
if err := control.Add(cgroup1.Process{Pid:1234}); err != nil {
5858
}
5959
```
6060

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

8686
```go
87-
processes, err := control.Processes(cgroups.Devices, recursive)
87+
processes, err := control.Processes(cgroup1.Devices, recursive)
8888
```
8989

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

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

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

119119
```go
120-
event := cgroups.MemoryThresholdEvent(50 * 1024 * 1024, false)
120+
event := cgroup1.MemoryThresholdEvent(50 * 1024 * 1024, false)
121121
efd, err := control.RegisterMemoryEvent(event)
122122
```
123123

124124
```go
125-
event := cgroups.MemoryPressureEvent(cgroups.MediumPressure, cgroups.DefaultMode)
125+
event := cgroup1.MemoryPressureEvent(cgroup1.MediumPressure, cgroup1.DefaultMode)
126126
efd, err := control.RegisterMemoryEvent(event)
127127
```
128128

129129
```go
130130
efd, err := control.OOMEventFD()
131131
// or by using RegisterMemoryEvent
132-
event := cgroups.OOMEvent()
132+
event := cgroup1.OOMEvent()
133133
efd, err := control.RegisterMemoryEvent(event)
134134
```
135135

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

154154
```go
155155
import (
156-
cgroupsv2 "github.com/containerd/cgroups/v2"
156+
"github.com/containerd/cgroups/v2/cgroup2"
157157
specs "github.com/opencontainers/runtime-spec/specs-go"
158158
)
159159

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

171171
```go
172-
m, err := cgroupsv2.LoadSystemd("/", "my-cgroup-abc.slice")
172+
m, err := cgroup2.LoadSystemd("/", "my-cgroup-abc.slice")
173173
if err != nil {
174174
return err
175175
}
@@ -178,7 +178,7 @@ if err != nil {
178178
### Delete a cgroup
179179

180180
```go
181-
m, err := cgroupsv2.LoadSystemd("/", "my-cgroup-abc.slice")
181+
m, err := cgroup2.LoadSystemd("/", "my-cgroup-abc.slice")
182182
if err != nil {
183183
return err
184184
}

blkio.go renamed to cgroup1/blkio.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
limitations under the License.
1515
*/
1616

17-
package cgroups
17+
package cgroup1
1818

1919
import (
2020
"bufio"
@@ -25,7 +25,8 @@ import (
2525
"strconv"
2626
"strings"
2727

28-
v1 "github.com/containerd/cgroups/v2/stats/v1"
28+
v1 "github.com/containerd/cgroups/v2/cgroup1/stats"
29+
2930
specs "github.com/opencontainers/runtime-spec/specs-go"
3031
)
3132

blkio_test.go renamed to cgroup1/blkio_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@
1414
limitations under the License.
1515
*/
1616

17-
package cgroups
17+
package cgroup1
1818

1919
import (
2020
"os"
2121
"strings"
2222
"testing"
2323

24-
v1 "github.com/containerd/cgroups/v2/stats/v1"
24+
v1 "github.com/containerd/cgroups/v2/cgroup1/stats"
2525
)
2626

2727
const data = `major minor #blocks name

cgroup.go renamed to cgroup1/cgroup.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
limitations under the License.
1515
*/
1616

17-
package cgroups
17+
package cgroup1
1818

1919
import (
2020
"errors"
@@ -28,7 +28,7 @@ import (
2828
"syscall"
2929
"time"
3030

31-
v1 "github.com/containerd/cgroups/v2/stats/v1"
31+
v1 "github.com/containerd/cgroups/v2/cgroup1/stats"
3232

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

cgroup_test.go renamed to cgroup1/cgroup_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
limitations under the License.
1515
*/
1616

17-
package cgroups
17+
package cgroup1
1818

1919
import (
2020
"fmt"

control.go renamed to cgroup1/control.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@
1414
limitations under the License.
1515
*/
1616

17-
package cgroups
17+
package cgroup1
1818

1919
import (
2020
"os"
2121

22-
v1 "github.com/containerd/cgroups/v2/stats/v1"
22+
v1 "github.com/containerd/cgroups/v2/cgroup1/stats"
2323
specs "github.com/opencontainers/runtime-spec/specs-go"
2424
)
2525

cpu.go renamed to cgroup1/cpu.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,15 @@
1414
limitations under the License.
1515
*/
1616

17-
package cgroups
17+
package cgroup1
1818

1919
import (
2020
"bufio"
2121
"os"
2222
"path/filepath"
2323
"strconv"
2424

25-
v1 "github.com/containerd/cgroups/v2/stats/v1"
25+
v1 "github.com/containerd/cgroups/v2/cgroup1/stats"
2626
specs "github.com/opencontainers/runtime-spec/specs-go"
2727
)
2828

cpuacct.go renamed to cgroup1/cpuacct.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
limitations under the License.
1515
*/
1616

17-
package cgroups
17+
package cgroup1
1818

1919
import (
2020
"bufio"
@@ -24,7 +24,7 @@ import (
2424
"strconv"
2525
"strings"
2626

27-
v1 "github.com/containerd/cgroups/v2/stats/v1"
27+
v1 "github.com/containerd/cgroups/v2/cgroup1/stats"
2828
)
2929

3030
const nanosecondsInSecond = 1000000000

0 commit comments

Comments
 (0)