diff -Nru cadvisor-0.35.0+ds1/debian/changelog cadvisor-0.35.0+ds1/debian/changelog --- cadvisor-0.35.0+ds1/debian/changelog 2020-06-23 15:50:56.000000000 -0300 +++ cadvisor-0.35.0+ds1/debian/changelog 2020-07-15 11:56:04.000000000 -0300 @@ -1,3 +1,12 @@ +cadvisor (0.35.0+ds1-4ubuntu2) groovy; urgency=medium + + * Add containerd support back (See LP 1884663) + - Drop d/p/0008-disable-containerd.patch + - Add dependency on golang-github-containerd-containerd-dev, + golang-github-containerd-ttrpc-dev, golang-github-containerd-typeurl-dev + + -- Lucas Kanashiro Wed, 15 Jul 2020 11:56:04 -0300 + cadvisor (0.35.0+ds1-4ubuntu1) groovy; urgency=medium * d/p/0008-disable-containerd.patch: golang-github-containerd-containerd-dev diff -Nru cadvisor-0.35.0+ds1/debian/control cadvisor-0.35.0+ds1/debian/control --- cadvisor-0.35.0+ds1/debian/control 2020-06-23 15:50:56.000000000 -0300 +++ cadvisor-0.35.0+ds1/debian/control 2020-07-15 11:56:04.000000000 -0300 @@ -8,6 +8,9 @@ dh-golang, golang-any, golang-github-blang-semver-dev, + golang-github-containerd-containerd-dev, + golang-github-containerd-ttrpc-dev, + golang-github-containerd-typeurl-dev, golang-github-docker-go-connections-dev, golang-github-docker-go-units-dev, golang-github-garyburd-redigo-dev, @@ -45,6 +48,9 @@ Package: golang-github-google-cadvisor-dev Architecture: all Depends: golang-github-blang-semver-dev, + golang-github-containerd-containerd-dev, + golang-github-containerd-ttrpc-dev, + golang-github-containerd-typeurl-dev, golang-github-docker-go-connections-dev, golang-github-docker-go-units-dev, golang-github-garyburd-redigo-dev, diff -Nru cadvisor-0.35.0+ds1/debian/patches/0008-disable-containerd.patch cadvisor-0.35.0+ds1/debian/patches/0008-disable-containerd.patch --- cadvisor-0.35.0+ds1/debian/patches/0008-disable-containerd.patch 2020-06-23 15:50:56.000000000 -0300 +++ cadvisor-0.35.0+ds1/debian/patches/0008-disable-containerd.patch 1969-12-31 21:00:00.000000000 -0300 @@ -1,941 +0,0 @@ -Description: Disable containerd support - The golang-github-containerd-containerd-dev package is buggy at the moment - because of its vendorized dependencies. See LP #1884663. -Author: Lucas Kanashiro -Forwarded: not-needed -Ubuntu-Bug: 1884663 -Last-Updated: 2020-06-23 - ---- a/container/containerd/client.go -+++ /dev/null -@@ -1,138 +0,0 @@ --// Copyright 2017 Google Inc. All Rights Reserved. --// --// 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 containerd -- --import ( -- "context" -- "fmt" -- "net" -- "sync" -- "time" -- -- containersapi "github.com/containerd/containerd/api/services/containers/v1" -- tasksapi "github.com/containerd/containerd/api/services/tasks/v1" -- versionapi "github.com/containerd/containerd/api/services/version/v1" -- "github.com/containerd/containerd/containers" -- "github.com/containerd/containerd/pkg/dialer" -- "github.com/containerd/containerd/errdefs" -- ptypes "github.com/gogo/protobuf/types" -- "google.golang.org/grpc" --) -- --type client struct { -- containerService containersapi.ContainersClient -- taskService tasksapi.TasksClient -- versionService versionapi.VersionClient --} -- --type containerdClient interface { -- LoadContainer(ctx context.Context, id string) (*containers.Container, error) -- TaskPid(ctx context.Context, id string) (uint32, error) -- Version(ctx context.Context) (string, error) --} -- --var once sync.Once --var ctrdClient containerdClient = nil -- --const ( -- maxBackoffDelay = 3 * time.Second -- connectionTimeout = 2 * time.Second --) -- --// Client creates a containerd client --func Client(address, namespace string) (containerdClient, error) { -- var retErr error -- once.Do(func() { -- tryConn, err := net.DialTimeout("unix", address, connectionTimeout) -- if err != nil { -- retErr = fmt.Errorf("containerd: cannot unix dial containerd api service: %v", err) -- return -- } -- tryConn.Close() -- -- gopts := []grpc.DialOption{ -- grpc.WithInsecure(), -- grpc.WithDialer(dialer.Dialer), -- grpc.WithBlock(), -- grpc.WithBackoffMaxDelay(maxBackoffDelay), -- grpc.WithTimeout(connectionTimeout), -- } -- unary, stream := newNSInterceptors(namespace) -- gopts = append(gopts, -- grpc.WithUnaryInterceptor(unary), -- grpc.WithStreamInterceptor(stream), -- ) -- -- conn, err := grpc.Dial(dialer.DialAddress(address), gopts...) -- if err != nil { -- retErr = err -- return -- } -- ctrdClient = &client{ -- containerService: containersapi.NewContainersClient(conn), -- taskService: tasksapi.NewTasksClient(conn), -- versionService: versionapi.NewVersionClient(conn), -- } -- }) -- return ctrdClient, retErr --} -- --func (c *client) LoadContainer(ctx context.Context, id string) (*containers.Container, error) { -- r, err := c.containerService.Get(ctx, &containersapi.GetContainerRequest{ -- ID: id, -- }) -- if err != nil { -- return nil, errdefs.FromGRPC(err) -- } -- return containerFromProto(r.Container), nil --} -- --func (c *client) TaskPid(ctx context.Context, id string) (uint32, error) { -- response, err := c.taskService.Get(ctx, &tasksapi.GetRequest{ -- ContainerID: id, -- }) -- if err != nil { -- return 0, errdefs.FromGRPC(err) -- } -- return response.Process.Pid, nil --} -- --func (c *client) Version(ctx context.Context) (string, error) { -- response, err := c.versionService.Version(ctx, &ptypes.Empty{}) -- if err != nil { -- return "", errdefs.FromGRPC(err) -- } -- return response.Version, nil --} -- --func containerFromProto(containerpb containersapi.Container) *containers.Container { -- var runtime containers.RuntimeInfo -- if containerpb.Runtime != nil { -- runtime = containers.RuntimeInfo{ -- Name: containerpb.Runtime.Name, -- Options: containerpb.Runtime.Options, -- } -- } -- return &containers.Container{ -- ID: containerpb.ID, -- Labels: containerpb.Labels, -- Image: containerpb.Image, -- Runtime: runtime, -- Spec: containerpb.Spec, -- Snapshotter: containerpb.Snapshotter, -- SnapshotKey: containerpb.SnapshotKey, -- Extensions: containerpb.Extensions, -- } --} ---- a/container/containerd/client_test.go -+++ /dev/null -@@ -1,53 +0,0 @@ --// Copyright 2017 Google Inc. All Rights Reserved. --// --// 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 containerd -- --import ( -- "context" -- "fmt" -- -- "github.com/containerd/containerd/containers" --) -- --type containerdClientMock struct { -- cntrs map[string]*containers.Container -- returnErr error --} -- --func (c *containerdClientMock) LoadContainer(ctx context.Context, id string) (*containers.Container, error) { -- if c.returnErr != nil { -- return nil, c.returnErr -- } -- cntr, ok := c.cntrs[id] -- if !ok { -- return nil, fmt.Errorf("unable to find container %q", id) -- } -- return cntr, nil --} -- --func (c *containerdClientMock) Version(ctx context.Context) (string, error) { -- return "test-v0.0.0", nil --} -- --func (c *containerdClientMock) TaskPid(ctx context.Context, id string) (uint32, error) { -- return 2389, nil --} -- --func mockcontainerdClient(cntrs map[string]*containers.Container, returnErr error) containerdClient { -- return &containerdClientMock{ -- cntrs: cntrs, -- returnErr: returnErr, -- } --} ---- a/container/containerd/factory.go -+++ /dev/null -@@ -1,149 +0,0 @@ --// Copyright 2017 Google Inc. All Rights Reserved. --// --// 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 containerd -- --import ( -- "flag" -- "fmt" -- "path" -- "regexp" -- "strings" -- -- "golang.org/x/net/context" -- "k8s.io/klog" -- -- "github.com/google/cadvisor/container" -- "github.com/google/cadvisor/container/libcontainer" -- "github.com/google/cadvisor/fs" -- info "github.com/google/cadvisor/info/v1" -- "github.com/google/cadvisor/watcher" --) -- --var ArgContainerdEndpoint = flag.String("containerd", "/run/containerd/containerd.sock", "containerd endpoint") --var ArgContainerdNamespace = flag.String("containerd-namespace", "k8s.io", "containerd namespace") -- --// The namespace under which containerd aliases are unique. --const k8sContainerdNamespace = "containerd" -- --// Regexp that identifies containerd cgroups, containers started with --// --cgroup-parent have another prefix than 'containerd' --var containerdCgroupRegexp = regexp.MustCompile(`([a-z0-9]{64})`) -- --type containerdFactory struct { -- machineInfoFactory info.MachineInfoFactory -- client containerdClient -- version string -- // Information about the mounted cgroup subsystems. -- cgroupSubsystems libcontainer.CgroupSubsystems -- // Information about mounted filesystems. -- fsInfo fs.FsInfo -- includedMetrics container.MetricSet --} -- --func (self *containerdFactory) String() string { -- return k8sContainerdNamespace --} -- --func (self *containerdFactory) NewContainerHandler(name string, inHostNamespace bool) (handler container.ContainerHandler, err error) { -- client, err := Client(*ArgContainerdEndpoint, *ArgContainerdNamespace) -- if err != nil { -- return -- } -- -- metadataEnvs := []string{} -- return newContainerdContainerHandler( -- client, -- name, -- self.machineInfoFactory, -- self.fsInfo, -- &self.cgroupSubsystems, -- inHostNamespace, -- metadataEnvs, -- self.includedMetrics, -- ) --} -- --// Returns the containerd ID from the full container name. --func ContainerNameToContainerdID(name string) string { -- id := path.Base(name) -- if matches := containerdCgroupRegexp.FindStringSubmatch(id); matches != nil { -- return matches[1] -- } -- return id --} -- --// isContainerName returns true if the cgroup with associated name --// corresponds to a containerd container. --func isContainerName(name string) bool { -- // TODO: May be check with HasPrefix ContainerdNamespace -- if strings.HasSuffix(name, ".mount") { -- return false -- } -- return containerdCgroupRegexp.MatchString(path.Base(name)) --} -- --// Containerd can handle and accept all containerd created containers --func (self *containerdFactory) CanHandleAndAccept(name string) (bool, bool, error) { -- // if the container is not associated with containerd, we can't handle it or accept it. -- if !isContainerName(name) { -- return false, false, nil -- } -- // Check if the container is known to containerd and it is running. -- id := ContainerNameToContainerdID(name) -- // If container and task lookup in containerd fails then we assume -- // that the container state is not known to containerd -- ctx := context.Background() -- _, err := self.client.LoadContainer(ctx, id) -- if err != nil { -- return false, false, fmt.Errorf("failed to load container: %v", err) -- } -- -- return true, true, nil --} -- --func (self *containerdFactory) DebugInfo() map[string][]string { -- return map[string][]string{} --} -- --// Register root container before running this function! --func Register(factory info.MachineInfoFactory, fsInfo fs.FsInfo, includedMetrics container.MetricSet) error { -- client, err := Client(*ArgContainerdEndpoint, *ArgContainerdNamespace) -- if err != nil { -- return fmt.Errorf("unable to create containerd client: %v", err) -- } -- -- containerdVersion, err := client.Version(context.Background()) -- if err != nil { -- return fmt.Errorf("failed to fetch containerd client version: %v", err) -- } -- -- cgroupSubsystems, err := libcontainer.GetCgroupSubsystems(includedMetrics) -- if err != nil { -- return fmt.Errorf("failed to get cgroup subsystems: %v", err) -- } -- -- klog.V(1).Infof("Registering containerd factory") -- f := &containerdFactory{ -- cgroupSubsystems: cgroupSubsystems, -- client: client, -- fsInfo: fsInfo, -- machineInfoFactory: factory, -- version: containerdVersion, -- includedMetrics: includedMetrics, -- } -- -- container.RegisterContainerHandlerFactory(f, []watcher.ContainerWatchSource{watcher.Raw}) -- return nil --} ---- a/container/containerd/factory_test.go -+++ /dev/null -@@ -1,76 +0,0 @@ --// Copyright 2017 Google Inc. All Rights Reserved. --// --// 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 containerd -- --import ( -- "testing" -- -- "github.com/containerd/containerd/containers" -- "github.com/containerd/typeurl" -- specs "github.com/opencontainers/runtime-spec/specs-go" -- "github.com/stretchr/testify/assert" -- -- containerlibcontainer "github.com/google/cadvisor/container/libcontainer" --) -- --func TestIsContainerName(t *testing.T) { -- tests := []struct { -- name string -- expected bool -- }{ -- { -- name: "/system.slice/run-containerd-io.containerd.runtime.v1.linux-k8s.io-14ae50f1d3ada102aec3ab00168fdafb2dc0986d79ca9e8d5b75581fa89e9fea-rootfs.mount", -- expected: false, -- }, -- { -- name: "/kubepods/besteffort/podd76e26fba3bf2bfd215eb29011d55250/40af7cdcbe507acad47a5a62025743ad3ddc6ab93b77b21363aa1c1d641047c9", -- expected: true, -- }, -- } -- for _, test := range tests { -- if actual := isContainerName(test.name); actual != test.expected { -- t.Errorf("%s: expected: %v, actual: %v", test.name, test.expected, actual) -- } -- } --} -- --func TestCanHandleAndAccept(t *testing.T) { -- as := assert.New(t) -- testContainers := make(map[string]*containers.Container) -- testContainer := &containers.Container{ -- ID: "40af7cdcbe507acad47a5a62025743ad3ddc6ab93b77b21363aa1c1d641047c9", -- Labels: map[string]string{"io.cri-containerd.kind": "sandbox"}, -- } -- spec := &specs.Spec{Root: &specs.Root{Path: "/test/"}, Process: &specs.Process{}} -- testContainer.Spec, _ = typeurl.MarshalAny(spec) -- testContainers["40af7cdcbe507acad47a5a62025743ad3ddc6ab93b77b21363aa1c1d641047c9"] = testContainer -- -- f := &containerdFactory{ -- client: mockcontainerdClient(testContainers, nil), -- cgroupSubsystems: containerlibcontainer.CgroupSubsystems{}, -- fsInfo: nil, -- machineInfoFactory: nil, -- includedMetrics: nil, -- } -- for k, v := range map[string]bool{ -- "/kubepods/besteffort/podd76e26fba3bf2bfd215eb29011d55250/40af7cdcbe507acad47a5a62025743ad3ddc6ab93b77b21363aa1c1d641047c9": true, -- "/system.slice/run-containerd-io.containerd.runtime.v1.linux-k8s.io-14ae50f1d3ada102aec3ab00168fdafb2dc0986d79ca9e8d5b75581fa89e9fea-rootfs.mount": false, -- } { -- b1, b2, err := f.CanHandleAndAccept(k) -- as.Nil(err) -- as.Equal(b1, v) -- as.Equal(b2, v) -- } --} ---- a/container/containerd/grpc.go -+++ /dev/null -@@ -1,49 +0,0 @@ --// Copyright 2017 Google Inc. All Rights Reserved. --// --// 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. -- --//This code has been taken from containerd repo to avoid large library import --package containerd -- --import ( -- "github.com/containerd/containerd/namespaces" -- "golang.org/x/net/context" -- "google.golang.org/grpc" --) -- --type namespaceInterceptor struct { -- namespace string --} -- --func (ni namespaceInterceptor) unary(ctx context.Context, method string, req, reply interface{}, cc *grpc.ClientConn, invoker grpc.UnaryInvoker, opts ...grpc.CallOption) error { -- _, ok := namespaces.Namespace(ctx) -- if !ok { -- ctx = namespaces.WithNamespace(ctx, ni.namespace) -- } -- return invoker(ctx, method, req, reply, cc, opts...) --} -- --func (ni namespaceInterceptor) stream(ctx context.Context, desc *grpc.StreamDesc, cc *grpc.ClientConn, method string, streamer grpc.Streamer, opts ...grpc.CallOption) (grpc.ClientStream, error) { -- _, ok := namespaces.Namespace(ctx) -- if !ok { -- ctx = namespaces.WithNamespace(ctx, ni.namespace) -- } -- return streamer(ctx, desc, cc, method, opts...) --} -- --func newNSInterceptors(ns string) (grpc.UnaryClientInterceptor, grpc.StreamClientInterceptor) { -- ni := namespaceInterceptor{ -- namespace: ns, -- } -- return grpc.UnaryClientInterceptor(ni.unary), grpc.StreamClientInterceptor(ni.stream) --} ---- a/container/containerd/handler.go -+++ /dev/null -@@ -1,246 +0,0 @@ --// Copyright 2017 Google Inc. All Rights Reserved. --// --// 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. -- --// Handler for containerd containers. --package containerd -- --import ( -- "encoding/json" -- "fmt" -- "strings" -- "time" -- -- "github.com/containerd/containerd/errdefs" -- cgroupfs "github.com/opencontainers/runc/libcontainer/cgroups/fs" -- libcontainerconfigs "github.com/opencontainers/runc/libcontainer/configs" -- "golang.org/x/net/context" -- -- "github.com/google/cadvisor/container" -- "github.com/google/cadvisor/container/common" -- containerlibcontainer "github.com/google/cadvisor/container/libcontainer" -- "github.com/google/cadvisor/fs" -- info "github.com/google/cadvisor/info/v1" -- specs "github.com/opencontainers/runtime-spec/specs-go" --) -- --type containerdContainerHandler struct { -- machineInfoFactory info.MachineInfoFactory -- // Absolute path to the cgroup hierarchies of this container. -- // (e.g.: "cpu" -> "/sys/fs/cgroup/cpu/test") -- cgroupPaths map[string]string -- fsInfo fs.FsInfo -- // Metadata associated with the container. -- reference info.ContainerReference -- envs map[string]string -- labels map[string]string -- // Image name used for this container. -- image string -- // Filesystem handler. -- includedMetrics container.MetricSet -- -- libcontainerHandler *containerlibcontainer.Handler --} -- --var _ container.ContainerHandler = &containerdContainerHandler{} -- --// newContainerdContainerHandler returns a new container.ContainerHandler --func newContainerdContainerHandler( -- client containerdClient, -- name string, -- machineInfoFactory info.MachineInfoFactory, -- fsInfo fs.FsInfo, -- cgroupSubsystems *containerlibcontainer.CgroupSubsystems, -- inHostNamespace bool, -- metadataEnvs []string, -- includedMetrics container.MetricSet, --) (container.ContainerHandler, error) { -- // Create the cgroup paths. -- cgroupPaths := common.MakeCgroupPaths(cgroupSubsystems.MountPoints, name) -- -- // Generate the equivalent cgroup manager for this container. -- cgroupManager := &cgroupfs.Manager{ -- Cgroups: &libcontainerconfigs.Cgroup{ -- Name: name, -- }, -- Paths: cgroupPaths, -- } -- -- id := ContainerNameToContainerdID(name) -- // We assume that if load fails then the container is not known to containerd. -- ctx := context.Background() -- cntr, err := client.LoadContainer(ctx, id) -- if err != nil { -- return nil, err -- } -- -- var spec specs.Spec -- if err := json.Unmarshal(cntr.Spec.Value, &spec); err != nil { -- return nil, err -- } -- -- // Cgroup is created during task creation. When cadvisor sees the cgroup, -- // task may not be fully created yet. Use a retry+backoff to tolerant the -- // race condition. -- // TODO(random-liu): Use cri-containerd client to talk with cri-containerd -- // instead. cri-containerd has some internal synchronization to make sure -- // `ContainerStatus` only returns result after `StartContainer` finishes. -- var taskPid uint32 -- backoff := 100 * time.Millisecond -- retry := 5 -- for { -- taskPid, err = client.TaskPid(ctx, id) -- if err == nil { -- break -- } -- retry-- -- if !errdefs.IsNotFound(err) || retry == 0 { -- return nil, err -- } -- time.Sleep(backoff) -- backoff *= 2 -- } -- -- rootfs := "/" -- if !inHostNamespace { -- rootfs = "/rootfs" -- } -- -- containerReference := info.ContainerReference{ -- Id: id, -- Name: name, -- Namespace: k8sContainerdNamespace, -- Aliases: []string{id, name}, -- } -- -- libcontainerHandler := containerlibcontainer.NewHandler(cgroupManager, rootfs, int(taskPid), includedMetrics) -- -- handler := &containerdContainerHandler{ -- machineInfoFactory: machineInfoFactory, -- cgroupPaths: cgroupPaths, -- fsInfo: fsInfo, -- envs: make(map[string]string), -- labels: cntr.Labels, -- includedMetrics: includedMetrics, -- reference: containerReference, -- libcontainerHandler: libcontainerHandler, -- } -- // Add the name and bare ID as aliases of the container. -- handler.image = cntr.Image -- for _, envVar := range spec.Process.Env { -- if envVar != "" { -- splits := strings.SplitN(envVar, "=", 2) -- if len(splits) == 2 { -- handler.envs[splits[0]] = splits[1] -- } -- } -- } -- -- return handler, nil --} -- --func (self *containerdContainerHandler) ContainerReference() (info.ContainerReference, error) { -- return self.reference, nil --} -- --func (self *containerdContainerHandler) needNet() bool { -- // Since containerd does not handle networking ideally we need to return based -- // on includedMetrics list. Here the assumption is the presence of cri-containerd -- // label -- if self.includedMetrics.Has(container.NetworkUsageMetrics) { -- //TODO change it to exported cri-containerd constants -- return self.labels["io.cri-containerd.kind"] == "sandbox" -- } -- return false --} -- --func (self *containerdContainerHandler) GetSpec() (info.ContainerSpec, error) { -- // TODO: Since we dont collect disk usage stats for containerd, we set hasFilesystem -- // to false. Revisit when we support disk usage stats for containerd -- hasFilesystem := false -- spec, err := common.GetSpec(self.cgroupPaths, self.machineInfoFactory, self.needNet(), hasFilesystem) -- spec.Labels = self.labels -- spec.Envs = self.envs -- spec.Image = self.image -- -- return spec, err --} -- --func (self *containerdContainerHandler) getFsStats(stats *info.ContainerStats) error { -- mi, err := self.machineInfoFactory.GetMachineInfo() -- if err != nil { -- return err -- } -- -- if self.includedMetrics.Has(container.DiskIOMetrics) { -- common.AssignDeviceNamesToDiskStats((*common.MachineInfoNamer)(mi), &stats.DiskIo) -- } -- return nil --} -- --func (self *containerdContainerHandler) GetStats() (*info.ContainerStats, error) { -- stats, err := self.libcontainerHandler.GetStats() -- if err != nil { -- return stats, err -- } -- // Clean up stats for containers that don't have their own network - this -- // includes containers running in Kubernetes pods that use the network of the -- // infrastructure container. This stops metrics being reported multiple times -- // for each container in a pod. -- if !self.needNet() { -- stats.Network = info.NetworkStats{} -- } -- -- // Get filesystem stats. -- err = self.getFsStats(stats) -- return stats, err --} -- --func (self *containerdContainerHandler) ListContainers(listType container.ListType) ([]info.ContainerReference, error) { -- return []info.ContainerReference{}, nil --} -- --func (self *containerdContainerHandler) GetCgroupPath(resource string) (string, error) { -- path, ok := self.cgroupPaths[resource] -- if !ok { -- return "", fmt.Errorf("could not find path for resource %q for container %q\n", resource, self.reference.Name) -- } -- return path, nil --} -- --func (self *containerdContainerHandler) GetContainerLabels() map[string]string { -- return self.labels --} -- --func (self *containerdContainerHandler) ListProcesses(listType container.ListType) ([]int, error) { -- return self.libcontainerHandler.GetProcesses() --} -- --func (self *containerdContainerHandler) Exists() bool { -- return common.CgroupExists(self.cgroupPaths) --} -- --func (self *containerdContainerHandler) Type() container.ContainerType { -- return container.ContainerTypeContainerd --} -- --func (self *containerdContainerHandler) Start() { --} -- --func (self *containerdContainerHandler) Cleanup() { --} -- --func (self *containerdContainerHandler) GetContainerIPAddress() string { -- // containerd doesnt take care of networking.So it doesnt maintain networking states -- return "" --} ---- a/container/containerd/handler_test.go -+++ /dev/null -@@ -1,108 +0,0 @@ --// Copyright 2017 Google Inc. All Rights Reserved. --// --// 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. -- --// Handler for containerd containers. --package containerd -- --import ( -- "testing" -- -- "github.com/containerd/containerd/containers" -- "github.com/containerd/typeurl" -- "github.com/google/cadvisor/container" -- containerlibcontainer "github.com/google/cadvisor/container/libcontainer" -- "github.com/google/cadvisor/fs" -- info "github.com/google/cadvisor/info/v1" -- specs "github.com/opencontainers/runtime-spec/specs-go" -- "github.com/stretchr/testify/assert" --) -- --func init() { -- typeurl.Register(&specs.Spec{}, "types.contianerd.io/opencontainers/runtime-spec", "v1", "Spec") --} -- --func TestHandler(t *testing.T) { -- as := assert.New(t) -- type testCase struct { -- client containerdClient -- name string -- machineInfoFactory info.MachineInfoFactory -- fsInfo fs.FsInfo -- cgroupSubsystems *containerlibcontainer.CgroupSubsystems -- inHostNamespace bool -- metadataEnvs []string -- includedMetrics container.MetricSet -- storageDir string -- -- hasErr bool -- errContains string -- checkReference *info.ContainerReference -- } -- testContainers := make(map[string]*containers.Container) -- testContainer := &containers.Container{ -- ID: "40af7cdcbe507acad47a5a62025743ad3ddc6ab93b77b21363aa1c1d641047c9", -- Labels: map[string]string{"io.cri-containerd.kind": "sandbox"}, -- } -- spec := &specs.Spec{Root: &specs.Root{Path: "/test/"}, Process: &specs.Process{}} -- testContainer.Spec, _ = typeurl.MarshalAny(spec) -- testContainers["40af7cdcbe507acad47a5a62025743ad3ddc6ab93b77b21363aa1c1d641047c9"] = testContainer -- for _, ts := range []testCase{ -- { -- mockcontainerdClient(nil, nil), -- "/kubepods/pod068e8fa0-9213-11e7-a01f-507b9d4141fa/40af7cdcbe507acad47a5a62025743ad3ddc6ab93b77b21363aa1c1d641047c9", -- nil, -- nil, -- &containerlibcontainer.CgroupSubsystems{}, -- false, -- nil, -- nil, -- "", -- true, -- "unable to find container \"40af7cdcbe507acad47a5a62025743ad3ddc6ab93b77b21363aa1c1d641047c9\"", -- nil, -- }, -- { -- mockcontainerdClient(testContainers, nil), -- "/kubepods/pod068e8fa0-9213-11e7-a01f-507b9d4141fa/40af7cdcbe507acad47a5a62025743ad3ddc6ab93b77b21363aa1c1d641047c9", -- nil, -- nil, -- &containerlibcontainer.CgroupSubsystems{}, -- false, -- nil, -- nil, -- "", -- false, -- "", -- &info.ContainerReference{ -- Id: "40af7cdcbe507acad47a5a62025743ad3ddc6ab93b77b21363aa1c1d641047c9", -- Name: "/kubepods/pod068e8fa0-9213-11e7-a01f-507b9d4141fa/40af7cdcbe507acad47a5a62025743ad3ddc6ab93b77b21363aa1c1d641047c9", -- Aliases: []string{"40af7cdcbe507acad47a5a62025743ad3ddc6ab93b77b21363aa1c1d641047c9", "/kubepods/pod068e8fa0-9213-11e7-a01f-507b9d4141fa/40af7cdcbe507acad47a5a62025743ad3ddc6ab93b77b21363aa1c1d641047c9"}, -- Namespace: k8sContainerdNamespace, -- }, -- }, -- } { -- handler, err := newContainerdContainerHandler(ts.client, ts.name, ts.machineInfoFactory, ts.fsInfo, ts.cgroupSubsystems, ts.inHostNamespace, ts.metadataEnvs, ts.includedMetrics) -- if ts.hasErr { -- as.NotNil(err) -- if ts.errContains != "" { -- as.Contains(err.Error(), ts.errContains) -- } -- } -- if ts.checkReference != nil { -- cr, err := handler.ContainerReference() -- as.Nil(err) -- as.Equal(*ts.checkReference, cr) -- } -- } --} ---- a/container/containerd/install/install.go -+++ /dev/null -@@ -1,29 +0,0 @@ --// Copyright 2019 Google Inc. All Rights Reserved. --// --// 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. -- --// The install package registers containerd.NewPlugin() as the "containerd" container provider when imported --package install -- --import ( -- "github.com/google/cadvisor/container" -- "github.com/google/cadvisor/container/containerd" -- "k8s.io/klog" --) -- --func init() { -- err := container.RegisterPlugin("containerd", containerd.NewPlugin()) -- if err != nil { -- klog.Fatalf("Failed to register containerd plugin: %v", err) -- } --} ---- a/container/containerd/plugin.go -+++ /dev/null -@@ -1,38 +0,0 @@ --// Copyright 2019 Google Inc. All Rights Reserved. --// --// 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 containerd -- --import ( -- "github.com/google/cadvisor/container" -- "github.com/google/cadvisor/fs" -- info "github.com/google/cadvisor/info/v1" -- "github.com/google/cadvisor/watcher" --) -- --// NewPlugin returns an implementation of container.Plugin suitable for passing to container.RegisterPlugin() --func NewPlugin() container.Plugin { -- return &plugin{} --} -- --type plugin struct{} -- --func (p *plugin) InitializeFSContext(context *fs.Context) error { -- return nil --} -- --func (p *plugin) Register(factory info.MachineInfoFactory, fsInfo fs.FsInfo, includedMetrics container.MetricSet) (watcher.ContainerWatcher, error) { -- err := Register(factory, fsInfo, includedMetrics) -- return nil, err --} ---- a/container/container.go -+++ b/container/container.go -@@ -34,7 +34,6 @@ - ContainerTypeDocker - ContainerTypeSystemd - ContainerTypeCrio -- ContainerTypeContainerd - ContainerTypeMesos - ) - ---- a/container/install/install.go -+++ b/container/install/install.go -@@ -16,7 +16,6 @@ - package install - - import ( -- _ "github.com/google/cadvisor/container/containerd/install" - _ "github.com/google/cadvisor/container/crio/install" - _ "github.com/google/cadvisor/container/docker/install" - _ "github.com/google/cadvisor/container/mesos/install" diff -Nru cadvisor-0.35.0+ds1/debian/patches/series cadvisor-0.35.0+ds1/debian/patches/series --- cadvisor-0.35.0+ds1/debian/patches/series 2020-06-23 15:50:56.000000000 -0300 +++ cadvisor-0.35.0+ds1/debian/patches/series 2020-07-15 11:56:01.000000000 -0300 @@ -5,4 +5,3 @@ 0005-fix-removed-prometheus.Handler.patch 0006-backport-mipsx-and-riscv64-fix.patch 0007-fix-topology-test.patch -0008-disable-containerd.patch