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

go.mod

-1
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

-2
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

+1-1
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

+1-1
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

-4
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

third_party/forked/cgroups/parse.go

+64
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+
}
+50
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

-2
This file was deleted.

vendor/github.com/containerd/cgroups/Makefile

-24
This file was deleted.

vendor/github.com/containerd/cgroups/Protobuild.toml

-46
This file was deleted.

0 commit comments

Comments
 (0)