From 9f1ecfd0230c630373c650fa34dadde50663187b Mon Sep 17 00:00:00 2001 From: Kinara Shah Date: Thu, 24 Oct 2024 17:19:16 -0700 Subject: [PATCH] add container file system usage --- core/imagefs_linux.go | 13 +++++++++++-- core/stats.go | 11 +++++++++++ network/hostport/hostport_manager.go | 2 +- streaming/server.go | 4 ++-- streaming/server_test.go | 2 +- streaming/streaming.go | 2 +- 6 files changed, 27 insertions(+), 7 deletions(-) diff --git a/core/imagefs_linux.go b/core/imagefs_linux.go index 6e1f6e859..dc90dba25 100644 --- a/core/imagefs_linux.go +++ b/core/imagefs_linux.go @@ -76,7 +76,16 @@ func (ds *dockerService) imageFsInfo() (*runtimeapi.ImageFsInfoResponse, error) InodesUsed: &runtimeapi.UInt64Value{ Value: iNodesUsed, }, - }, - }, + }}, + ContainerFilesystems: []*runtimeapi.FilesystemUsage{ + { + Timestamp: time.Now().UnixNano(), + FsId: &runtimeapi.FilesystemIdentifier{ + Mountpoint: ds.dockerRootDir, + }, + UsedBytes: &runtimeapi.UInt64Value{ + Value: ds.containerStatsCache.getWriteableLayer(), + }, + }}, }, nil } diff --git a/core/stats.go b/core/stats.go index 2ea41fe8f..0c0155a47 100644 --- a/core/stats.go +++ b/core/stats.go @@ -115,6 +115,17 @@ func (cs *cstats) getContainerRWSize() uint64 { return cs.rwLayerSize } +func (c *containerStatsCache) getWriteableLayer() uint64 { + c.RLock() + defer c.RUnlock() + + var totalLayerSize uint64 + for _, stat := range c.stats { + totalLayerSize += stat.rwLayerSize + } + return totalLayerSize +} + func (c *containerStatsCache) getStats(containerID string) *cstats { c.RLock() defer c.RUnlock() diff --git a/network/hostport/hostport_manager.go b/network/hostport/hostport_manager.go index eff622a58..06ed4287f 100644 --- a/network/hostport/hostport_manager.go +++ b/network/hostport/hostport_manager.go @@ -32,7 +32,7 @@ import ( "github.com/sirupsen/logrus" v1 "k8s.io/api/core/v1" utilerrors "k8s.io/apimachinery/pkg/util/errors" - "k8s.io/kubernetes/pkg/util/conntrack" + "k8s.io/kubernetes/pkg/proxy/conntrack" utiliptables "k8s.io/kubernetes/pkg/util/iptables" "k8s.io/utils/exec" utilnet "k8s.io/utils/net" diff --git a/streaming/server.go b/streaming/server.go index afb4516a8..10b4444bb 100644 --- a/streaming/server.go +++ b/streaming/server.go @@ -36,8 +36,8 @@ import ( remotecommandconsts "k8s.io/apimachinery/pkg/util/remotecommand" "k8s.io/client-go/tools/remotecommand" runtimeapi "k8s.io/cri-api/pkg/apis/runtime/v1" - "k8s.io/kubernetes/pkg/kubelet/cri/streaming/portforward" - remotecommandserver "k8s.io/kubernetes/pkg/kubelet/cri/streaming/remotecommand" + "k8s.io/kubelet/pkg/cri/streaming/portforward" + remotecommandserver "k8s.io/kubelet/pkg/cri/streaming/remotecommand" ) // Server is the library interface to serve the stream requests. diff --git a/streaming/server_test.go b/streaming/server_test.go index 351d5c291..877b71667 100644 --- a/streaming/server_test.go +++ b/streaming/server_test.go @@ -36,7 +36,7 @@ import ( restclient "k8s.io/client-go/rest" "k8s.io/client-go/transport/spdy" runtimeapi "k8s.io/cri-api/pkg/apis/runtime/v1" - kubeletportforward "k8s.io/kubernetes/pkg/kubelet/cri/streaming/portforward" + kubeletportforward "k8s.io/kubelet/pkg/cri/streaming/portforward" ) const ( diff --git a/streaming/streaming.go b/streaming/streaming.go index a8da16f64..31d39a7d8 100644 --- a/streaming/streaming.go +++ b/streaming/streaming.go @@ -29,7 +29,7 @@ import ( dockertypes "github.com/docker/docker/api/types" dockercontainer "github.com/docker/docker/api/types/container" - "k8s.io/kubernetes/pkg/kubelet/cri/streaming" + "k8s.io/kubelet/pkg/cri/streaming" "github.com/Mirantis/cri-dockerd/libdocker" )