Skip to content

Commit

Permalink
Copy ParseCgroupFileUnified and Drop rest of containerd/cgroups
Browse files Browse the repository at this point in the history
Signed-off-by: Davanum Srinivas <davanum@gmail.com>
  • Loading branch information
dims committed Oct 31, 2024
1 parent 365b457 commit e86d02b
Show file tree
Hide file tree
Showing 43 changed files with 116 additions and 11,024 deletions.
File renamed without changes.
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ require (
github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5
github.com/blang/semver/v4 v4.0.0
github.com/container-storage-interface/spec v1.9.0
github.com/containerd/cgroups v1.1.0
github.com/coredns/corefile-migration v1.0.24
github.com/coreos/go-oidc v2.2.1+incompatible
github.com/coreos/go-systemd/v22 v22.5.0
Expand Down
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,6 @@ github.com/cockroachdb/datadriven v1.0.2 h1:H9MtNqVoVhvd9nCBwOyDjUEdZCREqbIdCJD9
github.com/cockroachdb/datadriven v1.0.2/go.mod h1:a9RdTaap04u637JoCzcUoIcDmvwSUtcUFtT/C3kJlTU=
github.com/container-storage-interface/spec v1.9.0 h1:zKtX4STsq31Knz3gciCYCi1SXtO2HJDecIjDVboYavY=
github.com/container-storage-interface/spec v1.9.0/go.mod h1:ZfDu+3ZRyeVqxZM0Ds19MVLkN2d1XJ5MAfi1L3VjlT0=
github.com/containerd/cgroups v1.1.0 h1:v8rEWFl6EoqHB+swVNjVoCJE8o3jX7e8nqBGPLaDFBM=
github.com/containerd/cgroups v1.1.0/go.mod h1:6ppBcbh/NOOUU+dMKrykgaBnK9lCIBxHqJDGwsa1mIw=
github.com/containerd/console v1.0.3/go.mod h1:7LqA/THxQ86k76b8c/EMSiaJ3h1eZkMkXar0TQ1gf3U=
github.com/containerd/containerd/api v1.7.19 h1:VWbJL+8Ap4Ju2mx9c9qS1uFSB1OVYr5JJrW2yT5vFoA=
github.com/containerd/containerd/api v1.7.19/go.mod h1:fwGavl3LNwAV5ilJ0sbrABL44AQxmNjDRcwheXDb6Ig=
Expand Down
2 changes: 1 addition & 1 deletion hack/unwanted-dependencies.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"github.com/PuerkitoBio/urlesc": "unmaintained, archive mode",
"github.com/armon/consul-api": "MPL license not in CNCF allowlist",
"github.com/bketelsen/crypt": "unused, crypto",
"github.com/containerd/cgroups": "standardize on single cgroups library from runc, refer #128157",
"github.com/form3tech-oss/jwt-go": "unmaintained, archive mode",
"github.com/getsentry/raven-go": "unmaintained, archive mode",
"github.com/go-bindata/go-bindata": "refer to #99829",
Expand Down Expand Up @@ -130,7 +131,6 @@
"github.com/grpc-ecosystem/go-grpc-middleware"
],
"github.com/gogo/protobuf": [
"github.com/containerd/cgroups",
"github.com/containerd/containerd/api",
"github.com/containerd/ttrpc",
"github.com/google/cadvisor",
Expand Down
2 changes: 1 addition & 1 deletion pkg/kubelet/kuberuntime/kuberuntime_container_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import (
"sync"
"time"

"github.com/containerd/cgroups"
cadvisorv1 "github.com/google/cadvisor/info/v1"
libcontainercgroups "github.com/opencontainers/runc/libcontainer/cgroups"

Expand All @@ -45,6 +44,7 @@ import (
kubecontainer "k8s.io/kubernetes/pkg/kubelet/container"
"k8s.io/kubernetes/pkg/kubelet/qos"
kubelettypes "k8s.io/kubernetes/pkg/kubelet/types"
cgroups "k8s.io/kubernetes/third_party/forked/cgroups"
)

var defaultPageSize = int64(os.Getpagesize())
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
= vendor/github.com/containerd/cgroups licensed under: =

Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
Expand Down Expand Up @@ -201,5 +199,3 @@
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

= vendor/github.com/containerd/cgroups/LICENSE 86d3f3a95c324c9479bd8986968f4327
64 changes: 64 additions & 0 deletions third_party/forked/cgroups/parse.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*
Copyright 2024 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package cgroups

import (
"bufio"
"fmt"
"io"
"os"
"strings"
)

// ParseCgroupFileUnified returns legacy subsystem paths as the first value,
// and returns the unified path as the second value.
func ParseCgroupFileUnified(path string) (map[string]string, string, error) {
f, err := os.Open(path)
if err != nil {
return nil, "", err
}
defer f.Close()
return parseCgroupFromReaderUnified(f)
}

func parseCgroupFromReaderUnified(r io.Reader) (map[string]string, string, error) {
var (
cgroups = make(map[string]string)
unified = ""
s = bufio.NewScanner(r)
)
for s.Scan() {
var (
text = s.Text()
parts = strings.SplitN(text, ":", 3)
)
if len(parts) < 3 {
return nil, unified, fmt.Errorf("invalid cgroup entry: %q", text)
}
for _, subs := range strings.Split(parts[1], ",") {
if subs == "" {
unified = parts[2]
} else {
cgroups[subs] = parts[2]
}
}
}
if err := s.Err(); err != nil {
return nil, unified, err
}
return cgroups, unified, nil
}
50 changes: 50 additions & 0 deletions third_party/forked/cgroups/parse_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
Copyright The containerd Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package cgroups

import (
"strings"
"testing"
)

func TestParseCgroupFromReaderUnified(t *testing.T) {
const data = `10:devices:/user.slice
9:net_cls,net_prio:/
8:blkio:/
7:freezer:/
6:perf_event:/
5:cpuset:/
4:memory:/
3:pids:/user.slice/user-1000.slice/user@1000.service
2:cpu,cpuacct:/
1:name=systemd:/user.slice/user-1000.slice/user@1000.service/gnome-terminal-server.service
0::/user.slice/user-1000.slice/user@1000.service/gnome-terminal-server.service`
r := strings.NewReader(data)
paths, unified, err := parseCgroupFromReaderUnified(r)
if err != nil {
t.Fatal(err)
}
for subsystem, path := range paths {
if subsystem == "" {
t.Fatalf("empty subsystem for %q", path)
}
}
unifiedExpected := "/user.slice/user-1000.slice/user@1000.service/gnome-terminal-server.service"
if unified != unifiedExpected {
t.Fatalf("expected %q, got %q", unifiedExpected, unified)
}
}
2 changes: 0 additions & 2 deletions vendor/github.com/containerd/cgroups/.gitignore

This file was deleted.

24 changes: 0 additions & 24 deletions vendor/github.com/containerd/cgroups/Makefile

This file was deleted.

46 changes: 0 additions & 46 deletions vendor/github.com/containerd/cgroups/Protobuild.toml

This file was deleted.

Loading

0 comments on commit e86d02b

Please sign in to comment.