mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-05 18:24:07 +00:00
Adding cAdvisor API to get image usage information.
This commit is contained in:
parent
879a39bcc4
commit
303a1f7ea1
@ -18,6 +18,7 @@ package cadvisor
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
cadvisorApi "github.com/google/cadvisor/info/v1"
|
cadvisorApi "github.com/google/cadvisor/info/v1"
|
||||||
|
cadvisorApi2 "github.com/google/cadvisor/info/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Fake cAdvisor implementation.
|
// Fake cAdvisor implementation.
|
||||||
@ -37,3 +38,7 @@ func (c *Fake) DockerContainer(name string, req *cadvisorApi.ContainerInfoReques
|
|||||||
func (c *Fake) MachineInfo() (*cadvisorApi.MachineInfo, error) {
|
func (c *Fake) MachineInfo() (*cadvisorApi.MachineInfo, error) {
|
||||||
return new(cadvisorApi.MachineInfo), nil
|
return new(cadvisorApi.MachineInfo), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *Fake) DockerImagesFsInfo() (cadvisorApi2.FsInfo, error) {
|
||||||
|
return cadvisorApi2.FsInfo{}, nil
|
||||||
|
}
|
||||||
|
@ -25,8 +25,10 @@ import (
|
|||||||
|
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
|
||||||
"github.com/golang/glog"
|
"github.com/golang/glog"
|
||||||
|
cadvisorFs "github.com/google/cadvisor/fs"
|
||||||
cadvisorHttp "github.com/google/cadvisor/http"
|
cadvisorHttp "github.com/google/cadvisor/http"
|
||||||
cadvisorApi "github.com/google/cadvisor/info/v1"
|
cadvisorApi "github.com/google/cadvisor/info/v1"
|
||||||
|
cadvisorApi2 "github.com/google/cadvisor/info/v2"
|
||||||
"github.com/google/cadvisor/manager"
|
"github.com/google/cadvisor/manager"
|
||||||
"github.com/google/cadvisor/storage/memory"
|
"github.com/google/cadvisor/storage/memory"
|
||||||
"github.com/google/cadvisor/utils/sysfs"
|
"github.com/google/cadvisor/utils/sysfs"
|
||||||
@ -110,3 +112,19 @@ func (self *cadvisorClient) ContainerInfo(name string, req *cadvisorApi.Containe
|
|||||||
func (self *cadvisorClient) MachineInfo() (*cadvisorApi.MachineInfo, error) {
|
func (self *cadvisorClient) MachineInfo() (*cadvisorApi.MachineInfo, error) {
|
||||||
return self.GetMachineInfo()
|
return self.GetMachineInfo()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (self *cadvisorClient) DockerImagesFsInfo() (cadvisorApi2.FsInfo, error) {
|
||||||
|
res, err := self.GetFsInfo(cadvisorFs.LabelDockerImages)
|
||||||
|
if err != nil {
|
||||||
|
return cadvisorApi2.FsInfo{}, err
|
||||||
|
}
|
||||||
|
if len(res) == 0 {
|
||||||
|
return cadvisorApi2.FsInfo{}, fmt.Errorf("failed to find information for the filesystem containing Docker images")
|
||||||
|
}
|
||||||
|
// TODO(vmarmol): Handle this better when Docker has more than one image filesystem.
|
||||||
|
if len(res) > 1 {
|
||||||
|
glog.Warningf("More than one Docker images filesystem: %#v. Only using the first one", res)
|
||||||
|
}
|
||||||
|
|
||||||
|
return res[0], nil
|
||||||
|
}
|
||||||
|
@ -18,6 +18,7 @@ package cadvisor
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
cadvisorApi "github.com/google/cadvisor/info/v1"
|
cadvisorApi "github.com/google/cadvisor/info/v1"
|
||||||
|
cadvisorApi2 "github.com/google/cadvisor/info/v2"
|
||||||
"github.com/stretchr/testify/mock"
|
"github.com/stretchr/testify/mock"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -44,3 +45,8 @@ func (c *Mock) MachineInfo() (*cadvisorApi.MachineInfo, error) {
|
|||||||
args := c.Called()
|
args := c.Called()
|
||||||
return args.Get(0).(*cadvisorApi.MachineInfo), args.Error(1)
|
return args.Get(0).(*cadvisorApi.MachineInfo), args.Error(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *Mock) DockerImagesFsInfo() (cadvisorApi2.FsInfo, error) {
|
||||||
|
args := c.Called()
|
||||||
|
return args.Get(0).(cadvisorApi2.FsInfo), args.Error(1)
|
||||||
|
}
|
||||||
|
@ -22,6 +22,7 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
|
|
||||||
cadvisorApi "github.com/google/cadvisor/info/v1"
|
cadvisorApi "github.com/google/cadvisor/info/v1"
|
||||||
|
cadvisorApi2 "github.com/google/cadvisor/info/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
type cadvisorUnsupported struct {
|
type cadvisorUnsupported struct {
|
||||||
@ -46,3 +47,7 @@ func (self *cadvisorUnsupported) ContainerInfo(name string, req *cadvisorApi.Con
|
|||||||
func (self *cadvisorUnsupported) MachineInfo() (*cadvisorApi.MachineInfo, error) {
|
func (self *cadvisorUnsupported) MachineInfo() (*cadvisorApi.MachineInfo, error) {
|
||||||
return nil, unsupportedErr
|
return nil, unsupportedErr
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (self *cadvisorUnsupported) DockerImagesFsInfo() (cadvisorApi2.FsInfo, error) {
|
||||||
|
return cadvisorApi2.FsInfo{}, unsupportedErr
|
||||||
|
}
|
||||||
|
@ -18,6 +18,7 @@ package cadvisor
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
cadvisorApi "github.com/google/cadvisor/info/v1"
|
cadvisorApi "github.com/google/cadvisor/info/v1"
|
||||||
|
cadvisorApi2 "github.com/google/cadvisor/info/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Interface is an abstract interface for testability. It abstracts the interface to cAdvisor.
|
// Interface is an abstract interface for testability. It abstracts the interface to cAdvisor.
|
||||||
@ -25,4 +26,7 @@ type Interface interface {
|
|||||||
DockerContainer(name string, req *cadvisorApi.ContainerInfoRequest) (cadvisorApi.ContainerInfo, error)
|
DockerContainer(name string, req *cadvisorApi.ContainerInfoRequest) (cadvisorApi.ContainerInfo, error)
|
||||||
ContainerInfo(name string, req *cadvisorApi.ContainerInfoRequest) (*cadvisorApi.ContainerInfo, error)
|
ContainerInfo(name string, req *cadvisorApi.ContainerInfoRequest) (*cadvisorApi.ContainerInfo, error)
|
||||||
MachineInfo() (*cadvisorApi.MachineInfo, error)
|
MachineInfo() (*cadvisorApi.MachineInfo, error)
|
||||||
|
|
||||||
|
// Returns usage information about the filesystem holding Docker images.
|
||||||
|
DockerImagesFsInfo() (cadvisorApi2.FsInfo, error)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user