mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-31 15:25:57 +00:00
Merge pull request #122330 from dims/remove-unused-code-in-kubelet
Remove unused code in kubelet - DockerContainer / ContainerInfo / SubcontainerInfo / WatchEvents
This commit is contained in:
commit
e6acd1caf5
@ -34,7 +34,6 @@ import (
|
||||
|
||||
"github.com/google/cadvisor/cache/memory"
|
||||
cadvisormetrics "github.com/google/cadvisor/container"
|
||||
"github.com/google/cadvisor/events"
|
||||
cadvisorapi "github.com/google/cadvisor/info/v1"
|
||||
cadvisorapiv2 "github.com/google/cadvisor/info/v2"
|
||||
"github.com/google/cadvisor/manager"
|
||||
@ -129,10 +128,6 @@ func (cc *cadvisorClient) Start() error {
|
||||
return cc.Manager.Start()
|
||||
}
|
||||
|
||||
func (cc *cadvisorClient) ContainerInfo(name string, req *cadvisorapi.ContainerInfoRequest) (*cadvisorapi.ContainerInfo, error) {
|
||||
return cc.GetContainerInfo(name, req)
|
||||
}
|
||||
|
||||
func (cc *cadvisorClient) ContainerInfoV2(name string, options cadvisorapiv2.RequestOptions) (map[string]cadvisorapiv2.ContainerInfo, error) {
|
||||
return cc.GetContainerInfoV2(name, options)
|
||||
}
|
||||
@ -141,19 +136,6 @@ func (cc *cadvisorClient) VersionInfo() (*cadvisorapi.VersionInfo, error) {
|
||||
return cc.GetVersionInfo()
|
||||
}
|
||||
|
||||
func (cc *cadvisorClient) SubcontainerInfo(name string, req *cadvisorapi.ContainerInfoRequest) (map[string]*cadvisorapi.ContainerInfo, error) {
|
||||
infos, err := cc.SubcontainersInfo(name, req)
|
||||
if err != nil && len(infos) == 0 {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
result := make(map[string]*cadvisorapi.ContainerInfo, len(infos))
|
||||
for _, info := range infos {
|
||||
result[info.Name] = info
|
||||
}
|
||||
return result, err
|
||||
}
|
||||
|
||||
func (cc *cadvisorClient) MachineInfo() (*cadvisorapi.MachineInfo, error) {
|
||||
return cc.GetMachineInfo()
|
||||
}
|
||||
@ -193,7 +175,3 @@ func (cc *cadvisorClient) ContainerFsInfo() (cadvisorapiv2.FsInfo, error) {
|
||||
}
|
||||
return cc.getFsInfo(label)
|
||||
}
|
||||
|
||||
func (cc *cadvisorClient) WatchEvents(request *events.Request) (*events.EventChannel, error) {
|
||||
return cc.WatchForEvents(request)
|
||||
}
|
||||
|
@ -22,7 +22,6 @@ package cadvisor
|
||||
import (
|
||||
"errors"
|
||||
|
||||
"github.com/google/cadvisor/events"
|
||||
cadvisorapi "github.com/google/cadvisor/info/v1"
|
||||
cadvisorapiv2 "github.com/google/cadvisor/info/v2"
|
||||
)
|
||||
@ -43,14 +42,6 @@ func (cu *cadvisorUnsupported) Start() error {
|
||||
return errUnsupported
|
||||
}
|
||||
|
||||
func (cu *cadvisorUnsupported) DockerContainer(name string, req *cadvisorapi.ContainerInfoRequest) (cadvisorapi.ContainerInfo, error) {
|
||||
return cadvisorapi.ContainerInfo{}, errUnsupported
|
||||
}
|
||||
|
||||
func (cu *cadvisorUnsupported) ContainerInfo(name string, req *cadvisorapi.ContainerInfoRequest) (*cadvisorapi.ContainerInfo, error) {
|
||||
return nil, errUnsupported
|
||||
}
|
||||
|
||||
func (cu *cadvisorUnsupported) ContainerInfoV2(name string, options cadvisorapiv2.RequestOptions) (map[string]cadvisorapiv2.ContainerInfo, error) {
|
||||
return nil, errUnsupported
|
||||
}
|
||||
@ -59,10 +50,6 @@ func (cu *cadvisorUnsupported) GetRequestedContainersInfo(containerName string,
|
||||
return nil, errUnsupported
|
||||
}
|
||||
|
||||
func (cu *cadvisorUnsupported) SubcontainerInfo(name string, req *cadvisorapi.ContainerInfoRequest) (map[string]*cadvisorapi.ContainerInfo, error) {
|
||||
return nil, errUnsupported
|
||||
}
|
||||
|
||||
func (cu *cadvisorUnsupported) MachineInfo() (*cadvisorapi.MachineInfo, error) {
|
||||
return nil, errUnsupported
|
||||
}
|
||||
@ -83,10 +70,6 @@ func (cu *cadvisorUnsupported) ContainerFsInfo() (cadvisorapiv2.FsInfo, error) {
|
||||
return cadvisorapiv2.FsInfo{}, errUnsupported
|
||||
}
|
||||
|
||||
func (cu *cadvisorUnsupported) WatchEvents(request *events.Request) (*events.EventChannel, error) {
|
||||
return nil, errUnsupported
|
||||
}
|
||||
|
||||
func (cu *cadvisorUnsupported) GetDirFsInfo(path string) (cadvisorapiv2.FsInfo, error) {
|
||||
return cadvisorapiv2.FsInfo{}, nil
|
||||
}
|
||||
|
@ -20,7 +20,6 @@ limitations under the License.
|
||||
package cadvisor
|
||||
|
||||
import (
|
||||
"github.com/google/cadvisor/events"
|
||||
cadvisorapi "github.com/google/cadvisor/info/v1"
|
||||
cadvisorapiv2 "github.com/google/cadvisor/info/v2"
|
||||
"k8s.io/kubernetes/pkg/kubelet/winstats"
|
||||
@ -46,14 +45,6 @@ func (cu *cadvisorClient) Start() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (cu *cadvisorClient) DockerContainer(name string, req *cadvisorapi.ContainerInfoRequest) (cadvisorapi.ContainerInfo, error) {
|
||||
return cadvisorapi.ContainerInfo{}, nil
|
||||
}
|
||||
|
||||
func (cu *cadvisorClient) ContainerInfo(name string, req *cadvisorapi.ContainerInfoRequest) (*cadvisorapi.ContainerInfo, error) {
|
||||
return &cadvisorapi.ContainerInfo{}, nil
|
||||
}
|
||||
|
||||
// ContainerInfoV2 is only expected to be used for the root container. Returns info for all containers in the node.
|
||||
func (cu *cadvisorClient) ContainerInfoV2(name string, options cadvisorapiv2.RequestOptions) (map[string]cadvisorapiv2.ContainerInfo, error) {
|
||||
return cu.winStatsClient.WinContainerInfos()
|
||||
@ -63,10 +54,6 @@ func (cu *cadvisorClient) GetRequestedContainersInfo(containerName string, optio
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (cu *cadvisorClient) SubcontainerInfo(name string, req *cadvisorapi.ContainerInfoRequest) (map[string]*cadvisorapi.ContainerInfo, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (cu *cadvisorClient) MachineInfo() (*cadvisorapi.MachineInfo, error) {
|
||||
return cu.winStatsClient.WinMachineInfo()
|
||||
}
|
||||
@ -87,10 +74,6 @@ func (cu *cadvisorClient) RootFsInfo() (cadvisorapiv2.FsInfo, error) {
|
||||
return cu.GetDirFsInfo(cu.rootPath)
|
||||
}
|
||||
|
||||
func (cu *cadvisorClient) WatchEvents(request *events.Request) (*events.EventChannel, error) {
|
||||
return &events.EventChannel{}, nil
|
||||
}
|
||||
|
||||
func (cu *cadvisorClient) GetDirFsInfo(path string) (cadvisorapiv2.FsInfo, error) {
|
||||
return cu.winStatsClient.GetDirFsInfo(path)
|
||||
}
|
||||
|
@ -17,7 +17,6 @@ limitations under the License.
|
||||
package testing
|
||||
|
||||
import (
|
||||
"github.com/google/cadvisor/events"
|
||||
cadvisorapi "github.com/google/cadvisor/info/v1"
|
||||
cadvisorapiv2 "github.com/google/cadvisor/info/v2"
|
||||
"k8s.io/kubernetes/pkg/kubelet/cadvisor"
|
||||
@ -46,11 +45,6 @@ func (c *Fake) Start() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// ContainerInfo is a fake implementation of Interface.ContainerInfo.
|
||||
func (c *Fake) ContainerInfo(name string, req *cadvisorapi.ContainerInfoRequest) (*cadvisorapi.ContainerInfo, error) {
|
||||
return new(cadvisorapi.ContainerInfo), nil
|
||||
}
|
||||
|
||||
// ContainerInfoV2 is a fake implementation of Interface.ContainerInfoV2.
|
||||
func (c *Fake) ContainerInfoV2(name string, options cadvisorapiv2.RequestOptions) (map[string]cadvisorapiv2.ContainerInfo, error) {
|
||||
return map[string]cadvisorapiv2.ContainerInfo{}, nil
|
||||
@ -61,16 +55,6 @@ func (c *Fake) GetRequestedContainersInfo(containerName string, options cadvisor
|
||||
return map[string]*cadvisorapi.ContainerInfo{}, nil
|
||||
}
|
||||
|
||||
// SubcontainerInfo is a fake implementation of Interface.SubcontainerInfo.
|
||||
func (c *Fake) SubcontainerInfo(name string, req *cadvisorapi.ContainerInfoRequest) (map[string]*cadvisorapi.ContainerInfo, error) {
|
||||
return map[string]*cadvisorapi.ContainerInfo{}, nil
|
||||
}
|
||||
|
||||
// DockerContainer is a fake implementation of Interface.DockerContainer.
|
||||
func (c *Fake) DockerContainer(name string, req *cadvisorapi.ContainerInfoRequest) (cadvisorapi.ContainerInfo, error) {
|
||||
return cadvisorapi.ContainerInfo{}, nil
|
||||
}
|
||||
|
||||
// MachineInfo is a fake implementation of Interface.MachineInfo.
|
||||
func (c *Fake) MachineInfo() (*cadvisorapi.MachineInfo, error) {
|
||||
// Simulate a machine with 1 core and 3.75GB of memory.
|
||||
@ -106,11 +90,6 @@ func (c *Fake) ContainerFsInfo() (cadvisorapiv2.FsInfo, error) {
|
||||
return cadvisorapiv2.FsInfo{}, nil
|
||||
}
|
||||
|
||||
// WatchEvents is a fake implementation of Interface.WatchEvents.
|
||||
func (c *Fake) WatchEvents(request *events.Request) (*events.EventChannel, error) {
|
||||
return new(events.EventChannel), nil
|
||||
}
|
||||
|
||||
// GetDirFsInfo is a fake implementation of Interface.GetDirFsInfo.
|
||||
func (c *Fake) GetDirFsInfo(path string) (cadvisorapiv2.FsInfo, error) {
|
||||
return cadvisorapiv2.FsInfo{}, nil
|
||||
|
@ -24,7 +24,6 @@ import (
|
||||
reflect "reflect"
|
||||
|
||||
gomock "github.com/golang/mock/gomock"
|
||||
events "github.com/google/cadvisor/events"
|
||||
v1 "github.com/google/cadvisor/info/v1"
|
||||
v2 "github.com/google/cadvisor/info/v2"
|
||||
)
|
||||
@ -67,21 +66,6 @@ func (mr *MockInterfaceMockRecorder) ContainerFsInfo() *gomock.Call {
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ContainerFsInfo", reflect.TypeOf((*MockInterface)(nil).ContainerFsInfo))
|
||||
}
|
||||
|
||||
// ContainerInfo mocks base method.
|
||||
func (m *MockInterface) ContainerInfo(name string, req *v1.ContainerInfoRequest) (*v1.ContainerInfo, error) {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "ContainerInfo", name, req)
|
||||
ret0, _ := ret[0].(*v1.ContainerInfo)
|
||||
ret1, _ := ret[1].(error)
|
||||
return ret0, ret1
|
||||
}
|
||||
|
||||
// ContainerInfo indicates an expected call of ContainerInfo.
|
||||
func (mr *MockInterfaceMockRecorder) ContainerInfo(name, req interface{}) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ContainerInfo", reflect.TypeOf((*MockInterface)(nil).ContainerInfo), name, req)
|
||||
}
|
||||
|
||||
// ContainerInfoV2 mocks base method.
|
||||
func (m *MockInterface) ContainerInfoV2(name string, options v2.RequestOptions) (map[string]v2.ContainerInfo, error) {
|
||||
m.ctrl.T.Helper()
|
||||
@ -97,21 +81,6 @@ func (mr *MockInterfaceMockRecorder) ContainerInfoV2(name, options interface{})
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ContainerInfoV2", reflect.TypeOf((*MockInterface)(nil).ContainerInfoV2), name, options)
|
||||
}
|
||||
|
||||
// DockerContainer mocks base method.
|
||||
func (m *MockInterface) DockerContainer(name string, req *v1.ContainerInfoRequest) (v1.ContainerInfo, error) {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "DockerContainer", name, req)
|
||||
ret0, _ := ret[0].(v1.ContainerInfo)
|
||||
ret1, _ := ret[1].(error)
|
||||
return ret0, ret1
|
||||
}
|
||||
|
||||
// DockerContainer indicates an expected call of DockerContainer.
|
||||
func (mr *MockInterfaceMockRecorder) DockerContainer(name, req interface{}) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DockerContainer", reflect.TypeOf((*MockInterface)(nil).DockerContainer), name, req)
|
||||
}
|
||||
|
||||
// GetDirFsInfo mocks base method.
|
||||
func (m *MockInterface) GetDirFsInfo(path string) (v2.FsInfo, error) {
|
||||
m.ctrl.T.Helper()
|
||||
@ -201,21 +170,6 @@ func (mr *MockInterfaceMockRecorder) Start() *gomock.Call {
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Start", reflect.TypeOf((*MockInterface)(nil).Start))
|
||||
}
|
||||
|
||||
// SubcontainerInfo mocks base method.
|
||||
func (m *MockInterface) SubcontainerInfo(name string, req *v1.ContainerInfoRequest) (map[string]*v1.ContainerInfo, error) {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "SubcontainerInfo", name, req)
|
||||
ret0, _ := ret[0].(map[string]*v1.ContainerInfo)
|
||||
ret1, _ := ret[1].(error)
|
||||
return ret0, ret1
|
||||
}
|
||||
|
||||
// SubcontainerInfo indicates an expected call of SubcontainerInfo.
|
||||
func (mr *MockInterfaceMockRecorder) SubcontainerInfo(name, req interface{}) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SubcontainerInfo", reflect.TypeOf((*MockInterface)(nil).SubcontainerInfo), name, req)
|
||||
}
|
||||
|
||||
// VersionInfo mocks base method.
|
||||
func (m *MockInterface) VersionInfo() (*v1.VersionInfo, error) {
|
||||
m.ctrl.T.Helper()
|
||||
@ -231,21 +185,6 @@ func (mr *MockInterfaceMockRecorder) VersionInfo() *gomock.Call {
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "VersionInfo", reflect.TypeOf((*MockInterface)(nil).VersionInfo))
|
||||
}
|
||||
|
||||
// WatchEvents mocks base method.
|
||||
func (m *MockInterface) WatchEvents(request *events.Request) (*events.EventChannel, error) {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "WatchEvents", request)
|
||||
ret0, _ := ret[0].(*events.EventChannel)
|
||||
ret1, _ := ret[1].(error)
|
||||
return ret0, ret1
|
||||
}
|
||||
|
||||
// WatchEvents indicates an expected call of WatchEvents.
|
||||
func (mr *MockInterfaceMockRecorder) WatchEvents(request interface{}) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "WatchEvents", reflect.TypeOf((*MockInterface)(nil).WatchEvents), request)
|
||||
}
|
||||
|
||||
// MockImageFsInfoProvider is a mock of ImageFsInfoProvider interface.
|
||||
type MockImageFsInfoProvider struct {
|
||||
ctrl *gomock.Controller
|
||||
|
@ -18,7 +18,6 @@ limitations under the License.
|
||||
package cadvisor
|
||||
|
||||
import (
|
||||
"github.com/google/cadvisor/events"
|
||||
cadvisorapi "github.com/google/cadvisor/info/v1"
|
||||
cadvisorapiv2 "github.com/google/cadvisor/info/v2"
|
||||
)
|
||||
@ -26,11 +25,8 @@ import (
|
||||
// Interface is an abstract interface for testability. It abstracts the interface to cAdvisor.
|
||||
type Interface interface {
|
||||
Start() error
|
||||
DockerContainer(name string, req *cadvisorapi.ContainerInfoRequest) (cadvisorapi.ContainerInfo, error)
|
||||
ContainerInfo(name string, req *cadvisorapi.ContainerInfoRequest) (*cadvisorapi.ContainerInfo, error)
|
||||
ContainerInfoV2(name string, options cadvisorapiv2.RequestOptions) (map[string]cadvisorapiv2.ContainerInfo, error)
|
||||
GetRequestedContainersInfo(containerName string, options cadvisorapiv2.RequestOptions) (map[string]*cadvisorapi.ContainerInfo, error)
|
||||
SubcontainerInfo(name string, req *cadvisorapi.ContainerInfoRequest) (map[string]*cadvisorapi.ContainerInfo, error)
|
||||
MachineInfo() (*cadvisorapi.MachineInfo, error)
|
||||
|
||||
VersionInfo() (*cadvisorapi.VersionInfo, error)
|
||||
@ -45,9 +41,6 @@ type Interface interface {
|
||||
// KEP 4191 can separate the image filesystem
|
||||
ContainerFsInfo() (cadvisorapiv2.FsInfo, error)
|
||||
|
||||
// Get events streamed through passedChannel that fit the request.
|
||||
WatchEvents(request *events.Request) (*events.EventChannel, error)
|
||||
|
||||
// Get filesystem information for the filesystem that contains the given file.
|
||||
GetDirFsInfo(path string) (cadvisorapiv2.FsInfo, error)
|
||||
}
|
||||
|
@ -1361,16 +1361,6 @@ func (kl *Kubelet) RootFsStats() (*statsapi.FsStats, error) {
|
||||
return kl.StatsProvider.RootFsStats()
|
||||
}
|
||||
|
||||
// GetContainerInfo is delegated to StatsProvider, which implements stats.Provider interface
|
||||
func (kl *Kubelet) GetContainerInfo(ctx context.Context, podFullName string, uid types.UID, containerName string, req *cadvisorapi.ContainerInfoRequest) (*cadvisorapi.ContainerInfo, error) {
|
||||
return kl.StatsProvider.GetContainerInfo(ctx, podFullName, uid, containerName, req)
|
||||
}
|
||||
|
||||
// GetRawContainerInfo is delegated to StatsProvider, which implements stats.Provider interface
|
||||
func (kl *Kubelet) GetRawContainerInfo(containerName string, req *cadvisorapi.ContainerInfoRequest, subcontainers bool) (map[string]*cadvisorapi.ContainerInfo, error) {
|
||||
return kl.StatsProvider.GetRawContainerInfo(containerName, req, subcontainers)
|
||||
}
|
||||
|
||||
// RlimitStats is delegated to StatsProvider, which implements stats.Provider interface
|
||||
func (kl *Kubelet) RlimitStats() (*statsapi.RlimitStats, error) {
|
||||
return kl.StatsProvider.RlimitStats()
|
||||
|
@ -1480,71 +1480,6 @@ func TestDeleteOrphanedMirrorPods(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetContainerInfoForMirrorPods(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
// pods contain one static and one mirror pod with the same name but
|
||||
// different UIDs.
|
||||
pods := []*v1.Pod{
|
||||
{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
UID: "1234",
|
||||
Name: "qux",
|
||||
Namespace: "ns",
|
||||
Annotations: map[string]string{
|
||||
kubetypes.ConfigSourceAnnotationKey: "file",
|
||||
},
|
||||
},
|
||||
Spec: v1.PodSpec{
|
||||
Containers: []v1.Container{
|
||||
{Name: "foo"},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
UID: "5678",
|
||||
Name: "qux",
|
||||
Namespace: "ns",
|
||||
Annotations: map[string]string{
|
||||
kubetypes.ConfigSourceAnnotationKey: "api",
|
||||
kubetypes.ConfigMirrorAnnotationKey: "mirror",
|
||||
},
|
||||
},
|
||||
Spec: v1.PodSpec{
|
||||
Containers: []v1.Container{
|
||||
{Name: "foo"},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
testKubelet := newTestKubelet(t, false /* controllerAttachDetachEnabled */)
|
||||
defer testKubelet.Cleanup()
|
||||
fakeRuntime := testKubelet.fakeRuntime
|
||||
cadvisorReq := &cadvisorapi.ContainerInfoRequest{}
|
||||
kubelet := testKubelet.kubelet
|
||||
|
||||
fakeRuntime.PodList = []*containertest.FakePod{
|
||||
{Pod: &kubecontainer.Pod{
|
||||
ID: "1234",
|
||||
Name: "qux",
|
||||
Namespace: "ns",
|
||||
Containers: []*kubecontainer.Container{
|
||||
{
|
||||
Name: "foo",
|
||||
ID: kubecontainer.ContainerID{Type: "test", ID: "ab2cdf"},
|
||||
},
|
||||
},
|
||||
}},
|
||||
}
|
||||
|
||||
kubelet.podManager.SetPods(pods)
|
||||
// Use the mirror pod UID to retrieve the stats.
|
||||
stats, err := kubelet.GetContainerInfo(ctx, "qux_ns", "5678", "foo", cadvisorReq)
|
||||
assert.NoError(t, err)
|
||||
require.NotNil(t, stats)
|
||||
}
|
||||
|
||||
func TestNetworkErrorsWithoutHostNetwork(t *testing.T) {
|
||||
testKubelet := newTestKubelet(t, false /* controllerAttachDetachEnabled */)
|
||||
defer testKubelet.Cleanup()
|
||||
|
@ -75,8 +75,6 @@ const (
|
||||
|
||||
type fakeKubelet struct {
|
||||
podByNameFunc func(namespace, name string) (*v1.Pod, bool)
|
||||
containerInfoFunc func(ctx context.Context, podFullName string, uid types.UID, containerName string, req *cadvisorapi.ContainerInfoRequest) (*cadvisorapi.ContainerInfo, error)
|
||||
rawInfoFunc func(query *cadvisorapi.ContainerInfoRequest) (map[string]*cadvisorapi.ContainerInfo, error)
|
||||
machineInfoFunc func() (*cadvisorapi.MachineInfo, error)
|
||||
podsFunc func() []*v1.Pod
|
||||
runningPodsFunc func(ctx context.Context) ([]*v1.Pod, error)
|
||||
@ -110,14 +108,6 @@ func (fk *fakeKubelet) GetRequestedContainersInfo(containerName string, options
|
||||
return map[string]*cadvisorapi.ContainerInfo{}, nil
|
||||
}
|
||||
|
||||
func (fk *fakeKubelet) GetContainerInfo(ctx context.Context, podFullName string, uid types.UID, containerName string, req *cadvisorapi.ContainerInfoRequest) (*cadvisorapi.ContainerInfo, error) {
|
||||
return fk.containerInfoFunc(ctx, podFullName, uid, containerName, req)
|
||||
}
|
||||
|
||||
func (fk *fakeKubelet) GetRawContainerInfo(containerName string, req *cadvisorapi.ContainerInfoRequest, subcontainers bool) (map[string]*cadvisorapi.ContainerInfo, error) {
|
||||
return fk.rawInfoFunc(req)
|
||||
}
|
||||
|
||||
func (fk *fakeKubelet) GetCachedMachineInfo() (*cadvisorapi.MachineInfo, error) {
|
||||
return fk.machineInfoFunc()
|
||||
}
|
||||
|
@ -69,15 +69,6 @@ type Provider interface {
|
||||
// RootFsStats returns the stats of the node root filesystem.
|
||||
RootFsStats() (*statsapi.FsStats, error)
|
||||
|
||||
// The following stats are provided by cAdvisor for legacy usage.
|
||||
//
|
||||
// GetContainerInfo returns the information of the container with the
|
||||
// containerName managed by the pod with the uid.
|
||||
GetContainerInfo(ctx context.Context, podFullName string, uid types.UID, containerName string, req *cadvisorapi.ContainerInfoRequest) (*cadvisorapi.ContainerInfo, error)
|
||||
// GetRawContainerInfo returns the information of the container with the
|
||||
// containerName. If subcontainers is true, this function will return the
|
||||
// information of all the sub-containers as well.
|
||||
GetRawContainerInfo(containerName string, req *cadvisorapi.ContainerInfoRequest, subcontainers bool) (map[string]*cadvisorapi.ContainerInfo, error)
|
||||
// GetRequestedContainersInfo returns the information of the container with
|
||||
// the containerName, and with the specified cAdvisor options.
|
||||
GetRequestedContainersInfo(containerName string, options cadvisorv2.RequestOptions) (map[string]*cadvisorapi.ContainerInfo, error)
|
||||
|
@ -88,21 +88,6 @@ func (mr *MockProviderMockRecorder) GetCgroupStats(cgroupName, updateStats inter
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetCgroupStats", reflect.TypeOf((*MockProvider)(nil).GetCgroupStats), cgroupName, updateStats)
|
||||
}
|
||||
|
||||
// GetContainerInfo mocks base method.
|
||||
func (m *MockProvider) GetContainerInfo(ctx context.Context, podFullName string, uid types.UID, containerName string, req *v1.ContainerInfoRequest) (*v1.ContainerInfo, error) {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "GetContainerInfo", ctx, podFullName, uid, containerName, req)
|
||||
ret0, _ := ret[0].(*v1.ContainerInfo)
|
||||
ret1, _ := ret[1].(error)
|
||||
return ret0, ret1
|
||||
}
|
||||
|
||||
// GetContainerInfo indicates an expected call of GetContainerInfo.
|
||||
func (mr *MockProviderMockRecorder) GetContainerInfo(ctx, podFullName, uid, containerName, req interface{}) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetContainerInfo", reflect.TypeOf((*MockProvider)(nil).GetContainerInfo), ctx, podFullName, uid, containerName, req)
|
||||
}
|
||||
|
||||
// GetNode mocks base method.
|
||||
func (m *MockProvider) GetNode() (*v10.Node, error) {
|
||||
m.ctrl.T.Helper()
|
||||
@ -190,21 +175,6 @@ func (mr *MockProviderMockRecorder) GetPods() *gomock.Call {
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetPods", reflect.TypeOf((*MockProvider)(nil).GetPods))
|
||||
}
|
||||
|
||||
// GetRawContainerInfo mocks base method.
|
||||
func (m *MockProvider) GetRawContainerInfo(containerName string, req *v1.ContainerInfoRequest, subcontainers bool) (map[string]*v1.ContainerInfo, error) {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "GetRawContainerInfo", containerName, req, subcontainers)
|
||||
ret0, _ := ret[0].(map[string]*v1.ContainerInfo)
|
||||
ret1, _ := ret[1].(error)
|
||||
return ret0, ret1
|
||||
}
|
||||
|
||||
// GetRawContainerInfo indicates an expected call of GetRawContainerInfo.
|
||||
func (mr *MockProviderMockRecorder) GetRawContainerInfo(containerName, req, subcontainers interface{}) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetRawContainerInfo", reflect.TypeOf((*MockProvider)(nil).GetRawContainerInfo), containerName, req, subcontainers)
|
||||
}
|
||||
|
||||
// GetRequestedContainersInfo mocks base method.
|
||||
func (m *MockProvider) GetRequestedContainersInfo(containerName string, options v2.RequestOptions) (map[string]*v1.ContainerInfo, error) {
|
||||
m.ctrl.T.Helper()
|
||||
|
@ -20,7 +20,6 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
cadvisorapiv1 "github.com/google/cadvisor/info/v1"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/types"
|
||||
internalapi "k8s.io/cri-api/pkg/apis"
|
||||
@ -165,44 +164,6 @@ func (p *Provider) RootFsStats() (*statsapi.FsStats, error) {
|
||||
}, nil
|
||||
}
|
||||
|
||||
// GetContainerInfo returns stats (from cAdvisor) for a container.
|
||||
func (p *Provider) GetContainerInfo(ctx context.Context, podFullName string, podUID types.UID, containerName string, req *cadvisorapiv1.ContainerInfoRequest) (*cadvisorapiv1.ContainerInfo, error) {
|
||||
// Resolve and type convert back again.
|
||||
// We need the static pod UID but the kubecontainer API works with types.UID.
|
||||
podUID = types.UID(p.podManager.TranslatePodUID(podUID))
|
||||
|
||||
pods, err := p.runtimeCache.GetPods(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
pod := kubecontainer.Pods(pods).FindPod(podFullName, podUID)
|
||||
container := pod.FindContainerByName(containerName)
|
||||
if container == nil {
|
||||
return nil, kubecontainer.ErrContainerNotFound
|
||||
}
|
||||
|
||||
ci, err := p.cadvisor.DockerContainer(container.ID.ID, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &ci, nil
|
||||
}
|
||||
|
||||
// GetRawContainerInfo returns the stats (from cadvisor) for a non-Kubernetes
|
||||
// container.
|
||||
func (p *Provider) GetRawContainerInfo(containerName string, req *cadvisorapiv1.ContainerInfoRequest, subcontainers bool) (map[string]*cadvisorapiv1.ContainerInfo, error) {
|
||||
if subcontainers {
|
||||
return p.cadvisor.SubcontainerInfo(containerName, req)
|
||||
}
|
||||
containerInfo, err := p.cadvisor.ContainerInfo(containerName, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return map[string]*cadvisorapiv1.ContainerInfo{
|
||||
containerInfo.Name: containerInfo,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// HasDedicatedImageFs returns true if a dedicated image filesystem exists for storing images.
|
||||
// KEP Issue Number 4191: Enhanced this to allow for the containers to be separate from images.
|
||||
func (p *Provider) HasDedicatedImageFs(ctx context.Context) (bool, error) {
|
||||
|
@ -33,11 +33,9 @@ import (
|
||||
"k8s.io/apimachinery/pkg/types"
|
||||
statsapi "k8s.io/kubelet/pkg/apis/stats/v1alpha1"
|
||||
cadvisortest "k8s.io/kubernetes/pkg/kubelet/cadvisor/testing"
|
||||
kubecontainer "k8s.io/kubernetes/pkg/kubelet/container"
|
||||
kubecontainertest "k8s.io/kubernetes/pkg/kubelet/container/testing"
|
||||
kubepodtest "k8s.io/kubernetes/pkg/kubelet/pod/testing"
|
||||
serverstats "k8s.io/kubernetes/pkg/kubelet/server/stats"
|
||||
kubetypes "k8s.io/kubernetes/pkg/kubelet/types"
|
||||
"k8s.io/kubernetes/pkg/volume"
|
||||
)
|
||||
|
||||
@ -179,240 +177,6 @@ func TestRootFsStats(t *testing.T) {
|
||||
assert.Equal(*rootFsInfo.Inodes-*rootFsInfo.InodesFree, *stats.InodesUsed)
|
||||
}
|
||||
|
||||
func TestGetContainerInfo(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
cadvisorAPIFailure := fmt.Errorf("cAdvisor failure")
|
||||
runtimeError := fmt.Errorf("List containers error")
|
||||
tests := []struct {
|
||||
name string
|
||||
containerID string
|
||||
containerPath string
|
||||
cadvisorContainerInfo cadvisorapiv1.ContainerInfo
|
||||
runtimeError error
|
||||
podList []*kubecontainer.Pod
|
||||
requestedPodFullName string
|
||||
requestedPodUID types.UID
|
||||
requestedContainerName string
|
||||
expectDockerContainerCall bool
|
||||
mockError error
|
||||
expectedError error
|
||||
expectStats bool
|
||||
}{
|
||||
{
|
||||
name: "get container info",
|
||||
containerID: "ab2cdf",
|
||||
containerPath: "/docker/ab2cdf",
|
||||
cadvisorContainerInfo: cadvisorapiv1.ContainerInfo{
|
||||
ContainerReference: cadvisorapiv1.ContainerReference{
|
||||
Name: "/docker/ab2cdf",
|
||||
},
|
||||
},
|
||||
runtimeError: nil,
|
||||
podList: []*kubecontainer.Pod{
|
||||
{
|
||||
ID: "12345678",
|
||||
Name: "qux",
|
||||
Namespace: "ns",
|
||||
Containers: []*kubecontainer.Container{
|
||||
{
|
||||
Name: "foo",
|
||||
ID: kubecontainer.ContainerID{Type: "test", ID: "ab2cdf"},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
requestedPodFullName: "qux_ns",
|
||||
requestedPodUID: "",
|
||||
requestedContainerName: "foo",
|
||||
expectDockerContainerCall: true,
|
||||
mockError: nil,
|
||||
expectedError: nil,
|
||||
expectStats: true,
|
||||
},
|
||||
{
|
||||
name: "get container info when cadvisor failed",
|
||||
containerID: "ab2cdf",
|
||||
containerPath: "/docker/ab2cdf",
|
||||
cadvisorContainerInfo: cadvisorapiv1.ContainerInfo{},
|
||||
runtimeError: nil,
|
||||
podList: []*kubecontainer.Pod{
|
||||
{
|
||||
ID: "uuid",
|
||||
Name: "qux",
|
||||
Namespace: "ns",
|
||||
Containers: []*kubecontainer.Container{
|
||||
{
|
||||
Name: "foo",
|
||||
ID: kubecontainer.ContainerID{Type: "test", ID: "ab2cdf"},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
requestedPodFullName: "qux_ns",
|
||||
requestedPodUID: "uuid",
|
||||
requestedContainerName: "foo",
|
||||
expectDockerContainerCall: true,
|
||||
mockError: cadvisorAPIFailure,
|
||||
expectedError: cadvisorAPIFailure,
|
||||
expectStats: false,
|
||||
},
|
||||
{
|
||||
name: "get container info on non-existent container",
|
||||
containerID: "",
|
||||
containerPath: "",
|
||||
cadvisorContainerInfo: cadvisorapiv1.ContainerInfo{},
|
||||
runtimeError: nil,
|
||||
podList: []*kubecontainer.Pod{},
|
||||
requestedPodFullName: "qux",
|
||||
requestedPodUID: "",
|
||||
requestedContainerName: "foo",
|
||||
expectDockerContainerCall: false,
|
||||
mockError: nil,
|
||||
expectedError: kubecontainer.ErrContainerNotFound,
|
||||
expectStats: false,
|
||||
},
|
||||
{
|
||||
name: "get container info when container runtime failed",
|
||||
containerID: "",
|
||||
containerPath: "",
|
||||
cadvisorContainerInfo: cadvisorapiv1.ContainerInfo{},
|
||||
runtimeError: runtimeError,
|
||||
podList: []*kubecontainer.Pod{},
|
||||
requestedPodFullName: "qux",
|
||||
requestedPodUID: "",
|
||||
requestedContainerName: "foo",
|
||||
mockError: nil,
|
||||
expectedError: runtimeError,
|
||||
expectStats: false,
|
||||
},
|
||||
{
|
||||
name: "get container info with no containers",
|
||||
containerID: "",
|
||||
containerPath: "",
|
||||
cadvisorContainerInfo: cadvisorapiv1.ContainerInfo{},
|
||||
runtimeError: nil,
|
||||
podList: []*kubecontainer.Pod{},
|
||||
requestedPodFullName: "qux_ns",
|
||||
requestedPodUID: "",
|
||||
requestedContainerName: "foo",
|
||||
mockError: nil,
|
||||
expectedError: kubecontainer.ErrContainerNotFound,
|
||||
expectStats: false,
|
||||
},
|
||||
{
|
||||
name: "get container info with no matching containers",
|
||||
containerID: "",
|
||||
containerPath: "",
|
||||
cadvisorContainerInfo: cadvisorapiv1.ContainerInfo{},
|
||||
runtimeError: nil,
|
||||
podList: []*kubecontainer.Pod{
|
||||
{
|
||||
ID: "12345678",
|
||||
Name: "qux",
|
||||
Namespace: "ns",
|
||||
Containers: []*kubecontainer.Container{
|
||||
{
|
||||
Name: "bar",
|
||||
ID: kubecontainer.ContainerID{Type: "test", ID: "fakeID"},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
requestedPodFullName: "qux_ns",
|
||||
requestedPodUID: "",
|
||||
requestedContainerName: "foo",
|
||||
mockError: nil,
|
||||
expectedError: kubecontainer.ErrContainerNotFound,
|
||||
expectStats: false,
|
||||
},
|
||||
}
|
||||
|
||||
mockCtrl := gomock.NewController(t)
|
||||
defer mockCtrl.Finish()
|
||||
|
||||
for _, tc := range tests {
|
||||
var (
|
||||
mockCadvisor = cadvisortest.NewMockInterface(mockCtrl)
|
||||
mockPodManager = kubepodtest.NewMockManager(mockCtrl)
|
||||
mockRuntimeCache = kubecontainertest.NewMockRuntimeCache(mockCtrl)
|
||||
|
||||
cadvisorReq = &cadvisorapiv1.ContainerInfoRequest{}
|
||||
)
|
||||
|
||||
mockPodManager.EXPECT().TranslatePodUID(tc.requestedPodUID).Return(kubetypes.ResolvedPodUID(tc.requestedPodUID))
|
||||
mockRuntimeCache.EXPECT().GetPods(ctx).Return(tc.podList, tc.runtimeError)
|
||||
if tc.expectDockerContainerCall {
|
||||
mockCadvisor.EXPECT().DockerContainer(tc.containerID, cadvisorReq).Return(tc.cadvisorContainerInfo, tc.mockError)
|
||||
}
|
||||
|
||||
provider := newStatsProvider(mockCadvisor, mockPodManager, mockRuntimeCache, fakeContainerStatsProvider{})
|
||||
stats, err := provider.GetContainerInfo(ctx, tc.requestedPodFullName, tc.requestedPodUID, tc.requestedContainerName, cadvisorReq)
|
||||
assert.Equal(t, tc.expectedError, err)
|
||||
|
||||
if tc.expectStats {
|
||||
require.NotNil(t, stats)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetRawContainerInfoRoot(t *testing.T) {
|
||||
mockCtrl := gomock.NewController(t)
|
||||
defer mockCtrl.Finish()
|
||||
|
||||
var (
|
||||
mockCadvisor = cadvisortest.NewMockInterface(mockCtrl)
|
||||
mockPodManager = new(kubepodtest.MockManager)
|
||||
mockRuntimeCache = new(kubecontainertest.MockRuntimeCache)
|
||||
|
||||
cadvisorReq = &cadvisorapiv1.ContainerInfoRequest{}
|
||||
containerPath = "/"
|
||||
containerInfo = &cadvisorapiv1.ContainerInfo{
|
||||
ContainerReference: cadvisorapiv1.ContainerReference{
|
||||
Name: containerPath,
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
mockCadvisor.EXPECT().ContainerInfo(containerPath, cadvisorReq).Return(containerInfo, nil)
|
||||
|
||||
provider := newStatsProvider(mockCadvisor, mockPodManager, mockRuntimeCache, fakeContainerStatsProvider{})
|
||||
_, err := provider.GetRawContainerInfo(containerPath, cadvisorReq, false)
|
||||
assert.NoError(t, err)
|
||||
}
|
||||
|
||||
func TestGetRawContainerInfoSubcontainers(t *testing.T) {
|
||||
mockCtrl := gomock.NewController(t)
|
||||
defer mockCtrl.Finish()
|
||||
|
||||
var (
|
||||
mockCadvisor = cadvisortest.NewMockInterface(mockCtrl)
|
||||
mockPodManager = new(kubepodtest.MockManager)
|
||||
mockRuntimeCache = new(kubecontainertest.MockRuntimeCache)
|
||||
|
||||
cadvisorReq = &cadvisorapiv1.ContainerInfoRequest{}
|
||||
containerPath = "/kubelet"
|
||||
containerInfo = map[string]*cadvisorapiv1.ContainerInfo{
|
||||
containerPath: {
|
||||
ContainerReference: cadvisorapiv1.ContainerReference{
|
||||
Name: containerPath,
|
||||
},
|
||||
},
|
||||
"/kubelet/sub": {
|
||||
ContainerReference: cadvisorapiv1.ContainerReference{
|
||||
Name: "/kubelet/sub",
|
||||
},
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
mockCadvisor.EXPECT().SubcontainerInfo(containerPath, cadvisorReq).Return(containerInfo, nil)
|
||||
|
||||
provider := newStatsProvider(mockCadvisor, mockPodManager, mockRuntimeCache, fakeContainerStatsProvider{})
|
||||
result, err := provider.GetRawContainerInfo(containerPath, cadvisorReq, true)
|
||||
assert.NoError(t, err)
|
||||
assert.Len(t, result, 2)
|
||||
}
|
||||
|
||||
func TestHasDedicatedImageFs(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
mockCtrl := gomock.NewController(t)
|
||||
|
Loading…
Reference in New Issue
Block a user