Skip to content

Commit e86d02b

Browse files
committed
Copy ParseCgroupFileUnified and Drop rest of containerd/cgroups
Signed-off-by: Davanum Srinivas <[email protected]>
1 parent 365b457 commit e86d02b

Some content is hidden

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

43 files changed

+116
-11024
lines changed
File renamed without changes.

go.mod

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ require (
1919
github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5
2020
github.com/blang/semver/v4 v4.0.0
2121
github.com/container-storage-interface/spec v1.9.0
22-
github.com/containerd/cgroups v1.1.0
2322
github.com/coredns/corefile-migration v1.0.24
2423
github.com/coreos/go-oidc v2.2.1+incompatible
2524
github.com/coreos/go-systemd/v22 v22.5.0

go.sum

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,8 +180,6 @@ github.com/cockroachdb/datadriven v1.0.2 h1:H9MtNqVoVhvd9nCBwOyDjUEdZCREqbIdCJD9
180180
github.com/cockroachdb/datadriven v1.0.2/go.mod h1:a9RdTaap04u637JoCzcUoIcDmvwSUtcUFtT/C3kJlTU=
181181
github.com/container-storage-interface/spec v1.9.0 h1:zKtX4STsq31Knz3gciCYCi1SXtO2HJDecIjDVboYavY=
182182
github.com/container-storage-interface/spec v1.9.0/go.mod h1:ZfDu+3ZRyeVqxZM0Ds19MVLkN2d1XJ5MAfi1L3VjlT0=
183-
github.com/containerd/cgroups v1.1.0 h1:v8rEWFl6EoqHB+swVNjVoCJE8o3jX7e8nqBGPLaDFBM=
184-
github.com/containerd/cgroups v1.1.0/go.mod h1:6ppBcbh/NOOUU+dMKrykgaBnK9lCIBxHqJDGwsa1mIw=
185183
github.com/containerd/console v1.0.3/go.mod h1:7LqA/THxQ86k76b8c/EMSiaJ3h1eZkMkXar0TQ1gf3U=
186184
github.com/containerd/containerd/api v1.7.19 h1:VWbJL+8Ap4Ju2mx9c9qS1uFSB1OVYr5JJrW2yT5vFoA=
187185
github.com/containerd/containerd/api v1.7.19/go.mod h1:fwGavl3LNwAV5ilJ0sbrABL44AQxmNjDRcwheXDb6Ig=

hack/unwanted-dependencies.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
"github.com/PuerkitoBio/urlesc": "unmaintained, archive mode",
1212
"github.com/armon/consul-api": "MPL license not in CNCF allowlist",
1313
"github.com/bketelsen/crypt": "unused, crypto",
14+
"github.com/containerd/cgroups": "standardize on single cgroups library from runc, refer #128157",
1415
"github.com/form3tech-oss/jwt-go": "unmaintained, archive mode",
1516
"github.com/getsentry/raven-go": "unmaintained, archive mode",
1617
"github.com/go-bindata/go-bindata": "refer to #99829",
@@ -130,7 +131,6 @@
130131
"github.com/grpc-ecosystem/go-grpc-middleware"
131132
],
132133
"github.com/gogo/protobuf": [
133-
"github.com/containerd/cgroups",
134134
"github.com/containerd/containerd/api",
135135
"github.com/containerd/ttrpc",
136136
"github.com/google/cadvisor",

pkg/kubelet/kuberuntime/kuberuntime_container_linux.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ import (
2929
"sync"
3030
"time"
3131

32-
"github.com/containerd/cgroups"
3332
cadvisorv1 "github.com/google/cadvisor/info/v1"
3433
libcontainercgroups "github.com/opencontainers/runc/libcontainer/cgroups"
3534

@@ -45,6 +44,7 @@ import (
4544
kubecontainer "k8s.io/kubernetes/pkg/kubelet/container"
4645
"k8s.io/kubernetes/pkg/kubelet/qos"
4746
kubelettypes "k8s.io/kubernetes/pkg/kubelet/types"
47+
cgroups "k8s.io/kubernetes/third_party/forked/cgroups"
4848
)
4949

5050
var defaultPageSize = int64(os.Getpagesize())

LICENSES/vendor/github.com/containerd/cgroups/LICENSE renamed to third_party/forked/cgroups/LICENSE

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
= vendor/github.com/containerd/cgroups licensed under: =
2-
31
Apache License
42
Version 2.0, January 2004
53
http://www.apache.org/licenses/
@@ -201,5 +199,3 @@
201199
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
202200
See the License for the specific language governing permissions and
203201
limitations under the License.
204-
205-
= vendor/github.com/containerd/cgroups/LICENSE 86d3f3a95c324c9479bd8986968f4327
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/*
2+
Copyright 2024 The Kubernetes Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package cgroups
18+
19+
import (
20+
"bufio"
21+
"fmt"
22+
"io"
23+
"os"
24+
"strings"
25+
)
26+
27+
// ParseCgroupFileUnified returns legacy subsystem paths as the first value,
28+
// and returns the unified path as the second value.
29+
func ParseCgroupFileUnified(path string) (map[string]string, string, error) {
30+
f, err := os.Open(path)
31+
if err != nil {
32+
return nil, "", err
33+
}
34+
defer f.Close()
35+
return parseCgroupFromReaderUnified(f)
36+
}
37+
38+
func parseCgroupFromReaderUnified(r io.Reader) (map[string]string, string, error) {
39+
var (
40+
cgroups = make(map[string]string)
41+
unified = ""
42+
s = bufio.NewScanner(r)
43+
)
44+
for s.Scan() {
45+
var (
46+
text = s.Text()
47+
parts = strings.SplitN(text, ":", 3)
48+
)
49+
if len(parts) < 3 {
50+
return nil, unified, fmt.Errorf("invalid cgroup entry: %q", text)
51+
}
52+
for _, subs := range strings.Split(parts[1], ",") {
53+
if subs == "" {
54+
unified = parts[2]
55+
} else {
56+
cgroups[subs] = parts[2]
57+
}
58+
}
59+
}
60+
if err := s.Err(); err != nil {
61+
return nil, unified, err
62+
}
63+
return cgroups, unified, nil
64+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
Copyright The containerd Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package cgroups
18+
19+
import (
20+
"strings"
21+
"testing"
22+
)
23+
24+
func TestParseCgroupFromReaderUnified(t *testing.T) {
25+
const data = `10:devices:/user.slice
26+
9:net_cls,net_prio:/
27+
8:blkio:/
28+
7:freezer:/
29+
6:perf_event:/
30+
5:cpuset:/
31+
4:memory:/
32+
3:pids:/user.slice/user-1000.slice/[email protected]
33+
2:cpu,cpuacct:/
34+
1:name=systemd:/user.slice/user-1000.slice/[email protected]/gnome-terminal-server.service
35+
0::/user.slice/user-1000.slice/[email protected]/gnome-terminal-server.service`
36+
r := strings.NewReader(data)
37+
paths, unified, err := parseCgroupFromReaderUnified(r)
38+
if err != nil {
39+
t.Fatal(err)
40+
}
41+
for subsystem, path := range paths {
42+
if subsystem == "" {
43+
t.Fatalf("empty subsystem for %q", path)
44+
}
45+
}
46+
unifiedExpected := "/user.slice/user-1000.slice/[email protected]/gnome-terminal-server.service"
47+
if unified != unifiedExpected {
48+
t.Fatalf("expected %q, got %q", unifiedExpected, unified)
49+
}
50+
}

vendor/github.com/containerd/cgroups/.gitignore

Lines changed: 0 additions & 2 deletions
This file was deleted.

vendor/github.com/containerd/cgroups/Makefile

Lines changed: 0 additions & 24 deletions
This file was deleted.

0 commit comments

Comments
 (0)