mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-16 07:13:53 +00:00
remove unused GetRawContainerInfo
Signed-off-by: Davanum Srinivas <davanum@gmail.com>
This commit is contained in:
parent
e2cf9692fc
commit
d621e09a52
@ -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()
|
||||
}
|
||||
|
@ -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,21 +164,6 @@ func (p *Provider) RootFsStats() (*statsapi.FsStats, error) {
|
||||
}, 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) {
|
||||
|
@ -177,64 +177,6 @@ func TestRootFsStats(t *testing.T) {
|
||||
assert.Equal(*rootFsInfo.Inodes-*rootFsInfo.InodesFree, *stats.InodesUsed)
|
||||
}
|
||||
|
||||
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