From 1a92e218e0500a59b5da715da59425de9fd47cef Mon Sep 17 00:00:00 2001 From: Lantao Liu Date: Wed, 6 Feb 2019 17:49:48 -0800 Subject: [PATCH] Remove unused function from the legacy runtime interface. Signed-off-by: Lantao Liu --- pkg/kubelet/container/runtime.go | 11 --- pkg/kubelet/container/testing/fake_runtime.go | 25 ------ pkg/kubelet/container/testing/runtime_mock.go | 10 --- .../dockershim/network/cni/cni_test.go | 19 ++--- .../network/kubenet/kubenet_linux_test.go | 1 - pkg/kubelet/dockershim/network/testing/BUILD | 1 - .../dockershim/network/testing/fake_host.go | 9 +-- .../kuberuntime/kuberuntime_manager.go | 20 ----- .../kuberuntime/kuberuntime_manager_test.go | 79 ------------------- 9 files changed, 11 insertions(+), 164 deletions(-) diff --git a/pkg/kubelet/container/runtime.go b/pkg/kubelet/container/runtime.go index 64ebad5f0a..cebd987858 100644 --- a/pkg/kubelet/container/runtime.go +++ b/pkg/kubelet/container/runtime.go @@ -98,17 +98,6 @@ type Runtime interface { // GetPodStatus retrieves the status of the pod, including the // information of all containers in the pod that are visible in Runtime. GetPodStatus(uid types.UID, name, namespace string) (*PodStatus, error) - // Returns the filesystem path of the pod's network namespace; if the - // runtime does not handle namespace creation itself, or cannot return - // the network namespace path, it should return an error. - // TODO: Change ContainerID to a Pod ID since the namespace is shared - // by all containers in the pod. - GetNetNS(containerID ContainerID) (string, error) - // Returns the container ID that represents the Pod, as passed to network - // plugins. For example, if the runtime uses an infra container, returns - // the infra container's ContainerID. - // TODO: Change ContainerID to a Pod ID, see GetNetNS() - GetPodContainerID(*Pod) (ContainerID, error) // TODO(vmarmol): Unify pod and containerID args. // GetContainerLogs returns logs of a specific container. By // default, it returns a snapshot of the container log. Set 'follow' to true to diff --git a/pkg/kubelet/container/testing/fake_runtime.go b/pkg/kubelet/container/testing/fake_runtime.go index 01cc606dc6..767f0a2bb8 100644 --- a/pkg/kubelet/container/testing/fake_runtime.go +++ b/pkg/kubelet/container/testing/fake_runtime.go @@ -345,31 +345,6 @@ func (f *FakeRuntime) RemoveImage(image ImageSpec) error { return f.Err } -func (f *FakeRuntime) GetNetNS(containerID ContainerID) (string, error) { - f.Lock() - defer f.Unlock() - - f.CalledFunctions = append(f.CalledFunctions, "GetNetNS") - - for _, fp := range f.AllPodList { - for _, c := range fp.Pod.Containers { - if c.ID == containerID { - return fp.NetnsPath, nil - } - } - } - - return "", f.Err -} - -func (f *FakeRuntime) GetPodContainerID(pod *Pod) (ContainerID, error) { - f.Lock() - defer f.Unlock() - - f.CalledFunctions = append(f.CalledFunctions, "GetPodContainerID") - return ContainerID{}, f.Err -} - func (f *FakeRuntime) GarbageCollect(gcPolicy ContainerGCPolicy, ready bool, evictNonDeletedPods bool) error { f.Lock() defer f.Unlock() diff --git a/pkg/kubelet/container/testing/runtime_mock.go b/pkg/kubelet/container/testing/runtime_mock.go index 5edc0d32c6..a9d455cfd0 100644 --- a/pkg/kubelet/container/testing/runtime_mock.go +++ b/pkg/kubelet/container/testing/runtime_mock.go @@ -132,16 +132,6 @@ func (r *Mock) PortForward(pod *Pod, port uint16, stream io.ReadWriteCloser) err return args.Error(0) } -func (r *Mock) GetNetNS(containerID ContainerID) (string, error) { - args := r.Called(containerID) - return "", args.Error(0) -} - -func (r *Mock) GetPodContainerID(pod *Pod) (ContainerID, error) { - args := r.Called(pod) - return ContainerID{}, args.Error(0) -} - func (r *Mock) GarbageCollect(gcPolicy ContainerGCPolicy, ready bool, evictNonDeletedPods bool) error { args := r.Called(gcPolicy, ready, evictNonDeletedPods) return args.Error(0) diff --git a/pkg/kubelet/dockershim/network/cni/cni_test.go b/pkg/kubelet/dockershim/network/cni/cni_test.go index 0fbe58ad71..241bd1fca5 100644 --- a/pkg/kubelet/dockershim/network/cni/cni_test.go +++ b/pkg/kubelet/dockershim/network/cni/cni_test.go @@ -121,16 +121,14 @@ func tearDownPlugin(tmpDir string) { type fakeNetworkHost struct { networktest.FakePortMappingGetter kubeClient clientset.Interface - runtime kubecontainer.Runtime + pods []*containertest.FakePod } func NewFakeHost(kubeClient clientset.Interface, pods []*containertest.FakePod, ports map[string][]*hostport.PortMapping) *fakeNetworkHost { host := &fakeNetworkHost{ networktest.FakePortMappingGetter{PortMaps: ports}, kubeClient, - &containertest.FakeRuntime{ - AllPodList: pods, - }, + pods, } return host } @@ -143,12 +141,15 @@ func (fnh *fakeNetworkHost) GetKubeClient() clientset.Interface { return fnh.kubeClient } -func (fnh *fakeNetworkHost) GetRuntime() kubecontainer.Runtime { - return fnh.runtime -} - func (fnh *fakeNetworkHost) GetNetNS(containerID string) (string, error) { - return fnh.GetRuntime().GetNetNS(kubecontainer.ContainerID{Type: "test", ID: containerID}) + for _, fp := range fnh.pods { + for _, c := range fp.Pod.Containers { + if c.ID.ID == containerID { + return fp.NetnsPath, nil + } + } + } + return "", fmt.Errorf("container %q not found", containerID) } func (fnh *fakeNetworkHost) SupportsLegacyFeatures() bool { diff --git a/pkg/kubelet/dockershim/network/kubenet/kubenet_linux_test.go b/pkg/kubelet/dockershim/network/kubenet/kubenet_linux_test.go index b7e036ff8a..0c50149a98 100644 --- a/pkg/kubelet/dockershim/network/kubenet/kubenet_linux_test.go +++ b/pkg/kubelet/dockershim/network/kubenet/kubenet_linux_test.go @@ -221,7 +221,6 @@ func TestTearDownWithoutRuntime(t *testing.T) { for _, tc := range testCases { fhost := nettest.NewFakeHost(nil) fhost.Legacy = false - fhost.Runtime = nil mockcni := &mock_cni.MockCNI{} fexec := &fakeexec.FakeExec{ diff --git a/pkg/kubelet/dockershim/network/testing/BUILD b/pkg/kubelet/dockershim/network/testing/BUILD index 5fb15b3d46..5000d26750 100644 --- a/pkg/kubelet/dockershim/network/testing/BUILD +++ b/pkg/kubelet/dockershim/network/testing/BUILD @@ -16,7 +16,6 @@ go_library( deps = [ "//pkg/kubelet/apis/config:go_default_library", "//pkg/kubelet/container:go_default_library", - "//pkg/kubelet/container/testing:go_default_library", "//pkg/kubelet/dockershim/network:go_default_library", "//pkg/kubelet/dockershim/network/hostport:go_default_library", "//staging/src/k8s.io/api/core/v1:go_default_library", diff --git a/pkg/kubelet/dockershim/network/testing/fake_host.go b/pkg/kubelet/dockershim/network/testing/fake_host.go index 71dbf1d072..c2e3b65cbe 100644 --- a/pkg/kubelet/dockershim/network/testing/fake_host.go +++ b/pkg/kubelet/dockershim/network/testing/fake_host.go @@ -22,8 +22,6 @@ package testing import ( "k8s.io/api/core/v1" clientset "k8s.io/client-go/kubernetes" - kubecontainer "k8s.io/kubernetes/pkg/kubelet/container" - containertest "k8s.io/kubernetes/pkg/kubelet/container/testing" "k8s.io/kubernetes/pkg/kubelet/dockershim/network/hostport" ) @@ -32,11 +30,10 @@ type fakeNetworkHost struct { FakePortMappingGetter kubeClient clientset.Interface Legacy bool - Runtime *containertest.FakeRuntime } func NewFakeHost(kubeClient clientset.Interface) *fakeNetworkHost { - host := &fakeNetworkHost{kubeClient: kubeClient, Legacy: true, Runtime: &containertest.FakeRuntime{}} + host := &fakeNetworkHost{kubeClient: kubeClient, Legacy: true} return host } @@ -48,10 +45,6 @@ func (fnh *fakeNetworkHost) GetKubeClient() clientset.Interface { return nil } -func (nh *fakeNetworkHost) GetRuntime() kubecontainer.Runtime { - return nh.Runtime -} - func (nh *fakeNetworkHost) SupportsLegacyFeatures() bool { return nh.Legacy } diff --git a/pkg/kubelet/kuberuntime/kuberuntime_manager.go b/pkg/kubelet/kuberuntime/kuberuntime_manager.go index 2d5fdf3071..355df37177 100644 --- a/pkg/kubelet/kuberuntime/kuberuntime_manager.go +++ b/pkg/kubelet/kuberuntime/kuberuntime_manager.go @@ -914,31 +914,11 @@ func (m *kubeGenericRuntimeManager) GetPodStatus(uid kubetypes.UID, name, namesp }, nil } -// Returns the filesystem path of the pod's network namespace. -// -// For CRI, container network is handled by the runtime completely and this -// function should never be called. -func (m *kubeGenericRuntimeManager) GetNetNS(_ kubecontainer.ContainerID) (string, error) { - return "", fmt.Errorf("not supported") -} - // GarbageCollect removes dead containers using the specified container gc policy. func (m *kubeGenericRuntimeManager) GarbageCollect(gcPolicy kubecontainer.ContainerGCPolicy, allSourcesReady bool, evictNonDeletedPods bool) error { return m.containerGC.GarbageCollect(gcPolicy, allSourcesReady, evictNonDeletedPods) } -// GetPodContainerID gets pod sandbox ID -func (m *kubeGenericRuntimeManager) GetPodContainerID(pod *kubecontainer.Pod) (kubecontainer.ContainerID, error) { - formattedPod := kubecontainer.FormatPod(pod) - if len(pod.Sandboxes) == 0 { - klog.Errorf("No sandboxes are found for pod %q", formattedPod) - return kubecontainer.ContainerID{}, fmt.Errorf("sandboxes for pod %q not found", formattedPod) - } - - // return sandboxID of the first sandbox since it is the latest one - return pod.Sandboxes[0].ID, nil -} - // UpdatePodCIDR is just a passthrough method to update the runtimeConfig of the shim // with the podCIDR supplied by the kubelet. func (m *kubeGenericRuntimeManager) UpdatePodCIDR(podCIDR string) error { diff --git a/pkg/kubelet/kuberuntime/kuberuntime_manager_test.go b/pkg/kubelet/kuberuntime/kuberuntime_manager_test.go index ffbb40329a..8d5a168867 100644 --- a/pkg/kubelet/kuberuntime/kuberuntime_manager_test.go +++ b/pkg/kubelet/kuberuntime/kuberuntime_manager_test.go @@ -388,85 +388,6 @@ func TestGetPods(t *testing.T) { } } -func TestGetPodContainerID(t *testing.T) { - fakeRuntime, _, m, err := createTestRuntimeManager() - assert.NoError(t, err) - - pod := &v1.Pod{ - ObjectMeta: metav1.ObjectMeta{ - UID: "12345678", - Name: "foo", - Namespace: "new", - }, - Spec: v1.PodSpec{ - Containers: []v1.Container{ - { - Name: "foo1", - Image: "busybox", - }, - { - Name: "foo2", - Image: "busybox", - }, - }, - }, - } - // Set fake sandbox and fake containers to fakeRuntime. - fakeSandbox, _ := makeAndSetFakePod(t, m, fakeRuntime, pod) - - // Convert fakeSandbox to kubecontainer.Container - sandbox, err := m.sandboxToKubeContainer(&runtimeapi.PodSandbox{ - Id: fakeSandbox.Id, - Metadata: fakeSandbox.Metadata, - State: fakeSandbox.State, - CreatedAt: fakeSandbox.CreatedAt, - Labels: fakeSandbox.Labels, - }) - assert.NoError(t, err) - - expectedPod := &kubecontainer.Pod{ - ID: pod.UID, - Name: pod.Name, - Namespace: pod.Namespace, - Containers: []*kubecontainer.Container{}, - Sandboxes: []*kubecontainer.Container{sandbox}, - } - actual, err := m.GetPodContainerID(expectedPod) - assert.Equal(t, fakeSandbox.Id, actual.ID) -} - -func TestGetNetNS(t *testing.T) { - fakeRuntime, _, m, err := createTestRuntimeManager() - assert.NoError(t, err) - - pod := &v1.Pod{ - ObjectMeta: metav1.ObjectMeta{ - UID: "12345678", - Name: "foo", - Namespace: "new", - }, - Spec: v1.PodSpec{ - Containers: []v1.Container{ - { - Name: "foo1", - Image: "busybox", - }, - { - Name: "foo2", - Image: "busybox", - }, - }, - }, - } - - // Set fake sandbox and fake containers to fakeRuntime. - sandbox, _ := makeAndSetFakePod(t, m, fakeRuntime, pod) - - actual, err := m.GetNetNS(kubecontainer.ContainerID{ID: sandbox.Id}) - assert.Equal(t, "", actual) - assert.Equal(t, "not supported", err.Error()) -} - func TestKillPod(t *testing.T) { fakeRuntime, _, m, err := createTestRuntimeManager() assert.NoError(t, err)