mirror of https://github.com/k3s-io/k3s
Merge pull request #73804 from Random-Liu/remove-unused-functions
Remove unused function from the legacy runtime interface.pull/564/head
commit
0480214903
|
@ -98,17 +98,6 @@ type Runtime interface {
|
||||||
// GetPodStatus retrieves the status of the pod, including the
|
// GetPodStatus retrieves the status of the pod, including the
|
||||||
// information of all containers in the pod that are visible in Runtime.
|
// information of all containers in the pod that are visible in Runtime.
|
||||||
GetPodStatus(uid types.UID, name, namespace string) (*PodStatus, error)
|
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.
|
// TODO(vmarmol): Unify pod and containerID args.
|
||||||
// GetContainerLogs returns logs of a specific container. By
|
// GetContainerLogs returns logs of a specific container. By
|
||||||
// default, it returns a snapshot of the container log. Set 'follow' to true to
|
// default, it returns a snapshot of the container log. Set 'follow' to true to
|
||||||
|
|
|
@ -345,31 +345,6 @@ func (f *FakeRuntime) RemoveImage(image ImageSpec) error {
|
||||||
return f.Err
|
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 {
|
func (f *FakeRuntime) GarbageCollect(gcPolicy ContainerGCPolicy, ready bool, evictNonDeletedPods bool) error {
|
||||||
f.Lock()
|
f.Lock()
|
||||||
defer f.Unlock()
|
defer f.Unlock()
|
||||||
|
|
|
@ -132,16 +132,6 @@ func (r *Mock) PortForward(pod *Pod, port uint16, stream io.ReadWriteCloser) err
|
||||||
return args.Error(0)
|
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 {
|
func (r *Mock) GarbageCollect(gcPolicy ContainerGCPolicy, ready bool, evictNonDeletedPods bool) error {
|
||||||
args := r.Called(gcPolicy, ready, evictNonDeletedPods)
|
args := r.Called(gcPolicy, ready, evictNonDeletedPods)
|
||||||
return args.Error(0)
|
return args.Error(0)
|
||||||
|
|
|
@ -121,16 +121,14 @@ func tearDownPlugin(tmpDir string) {
|
||||||
type fakeNetworkHost struct {
|
type fakeNetworkHost struct {
|
||||||
networktest.FakePortMappingGetter
|
networktest.FakePortMappingGetter
|
||||||
kubeClient clientset.Interface
|
kubeClient clientset.Interface
|
||||||
runtime kubecontainer.Runtime
|
pods []*containertest.FakePod
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewFakeHost(kubeClient clientset.Interface, pods []*containertest.FakePod, ports map[string][]*hostport.PortMapping) *fakeNetworkHost {
|
func NewFakeHost(kubeClient clientset.Interface, pods []*containertest.FakePod, ports map[string][]*hostport.PortMapping) *fakeNetworkHost {
|
||||||
host := &fakeNetworkHost{
|
host := &fakeNetworkHost{
|
||||||
networktest.FakePortMappingGetter{PortMaps: ports},
|
networktest.FakePortMappingGetter{PortMaps: ports},
|
||||||
kubeClient,
|
kubeClient,
|
||||||
&containertest.FakeRuntime{
|
pods,
|
||||||
AllPodList: pods,
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
return host
|
return host
|
||||||
}
|
}
|
||||||
|
@ -143,12 +141,15 @@ func (fnh *fakeNetworkHost) GetKubeClient() clientset.Interface {
|
||||||
return fnh.kubeClient
|
return fnh.kubeClient
|
||||||
}
|
}
|
||||||
|
|
||||||
func (fnh *fakeNetworkHost) GetRuntime() kubecontainer.Runtime {
|
|
||||||
return fnh.runtime
|
|
||||||
}
|
|
||||||
|
|
||||||
func (fnh *fakeNetworkHost) GetNetNS(containerID string) (string, error) {
|
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 {
|
func (fnh *fakeNetworkHost) SupportsLegacyFeatures() bool {
|
||||||
|
|
|
@ -221,7 +221,6 @@ func TestTearDownWithoutRuntime(t *testing.T) {
|
||||||
for _, tc := range testCases {
|
for _, tc := range testCases {
|
||||||
fhost := nettest.NewFakeHost(nil)
|
fhost := nettest.NewFakeHost(nil)
|
||||||
fhost.Legacy = false
|
fhost.Legacy = false
|
||||||
fhost.Runtime = nil
|
|
||||||
mockcni := &mock_cni.MockCNI{}
|
mockcni := &mock_cni.MockCNI{}
|
||||||
|
|
||||||
fexec := &fakeexec.FakeExec{
|
fexec := &fakeexec.FakeExec{
|
||||||
|
|
|
@ -16,7 +16,6 @@ go_library(
|
||||||
deps = [
|
deps = [
|
||||||
"//pkg/kubelet/apis/config:go_default_library",
|
"//pkg/kubelet/apis/config:go_default_library",
|
||||||
"//pkg/kubelet/container: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:go_default_library",
|
||||||
"//pkg/kubelet/dockershim/network/hostport:go_default_library",
|
"//pkg/kubelet/dockershim/network/hostport:go_default_library",
|
||||||
"//staging/src/k8s.io/api/core/v1:go_default_library",
|
"//staging/src/k8s.io/api/core/v1:go_default_library",
|
||||||
|
|
|
@ -22,8 +22,6 @@ package testing
|
||||||
import (
|
import (
|
||||||
"k8s.io/api/core/v1"
|
"k8s.io/api/core/v1"
|
||||||
clientset "k8s.io/client-go/kubernetes"
|
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"
|
"k8s.io/kubernetes/pkg/kubelet/dockershim/network/hostport"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -32,11 +30,10 @@ type fakeNetworkHost struct {
|
||||||
FakePortMappingGetter
|
FakePortMappingGetter
|
||||||
kubeClient clientset.Interface
|
kubeClient clientset.Interface
|
||||||
Legacy bool
|
Legacy bool
|
||||||
Runtime *containertest.FakeRuntime
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewFakeHost(kubeClient clientset.Interface) *fakeNetworkHost {
|
func NewFakeHost(kubeClient clientset.Interface) *fakeNetworkHost {
|
||||||
host := &fakeNetworkHost{kubeClient: kubeClient, Legacy: true, Runtime: &containertest.FakeRuntime{}}
|
host := &fakeNetworkHost{kubeClient: kubeClient, Legacy: true}
|
||||||
return host
|
return host
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -48,10 +45,6 @@ func (fnh *fakeNetworkHost) GetKubeClient() clientset.Interface {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (nh *fakeNetworkHost) GetRuntime() kubecontainer.Runtime {
|
|
||||||
return nh.Runtime
|
|
||||||
}
|
|
||||||
|
|
||||||
func (nh *fakeNetworkHost) SupportsLegacyFeatures() bool {
|
func (nh *fakeNetworkHost) SupportsLegacyFeatures() bool {
|
||||||
return nh.Legacy
|
return nh.Legacy
|
||||||
}
|
}
|
||||||
|
|
|
@ -914,31 +914,11 @@ func (m *kubeGenericRuntimeManager) GetPodStatus(uid kubetypes.UID, name, namesp
|
||||||
}, nil
|
}, 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.
|
// GarbageCollect removes dead containers using the specified container gc policy.
|
||||||
func (m *kubeGenericRuntimeManager) GarbageCollect(gcPolicy kubecontainer.ContainerGCPolicy, allSourcesReady bool, evictNonDeletedPods bool) error {
|
func (m *kubeGenericRuntimeManager) GarbageCollect(gcPolicy kubecontainer.ContainerGCPolicy, allSourcesReady bool, evictNonDeletedPods bool) error {
|
||||||
return m.containerGC.GarbageCollect(gcPolicy, allSourcesReady, evictNonDeletedPods)
|
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
|
// UpdatePodCIDR is just a passthrough method to update the runtimeConfig of the shim
|
||||||
// with the podCIDR supplied by the kubelet.
|
// with the podCIDR supplied by the kubelet.
|
||||||
func (m *kubeGenericRuntimeManager) UpdatePodCIDR(podCIDR string) error {
|
func (m *kubeGenericRuntimeManager) UpdatePodCIDR(podCIDR string) error {
|
||||||
|
|
|
@ -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) {
|
func TestKillPod(t *testing.T) {
|
||||||
fakeRuntime, _, m, err := createTestRuntimeManager()
|
fakeRuntime, _, m, err := createTestRuntimeManager()
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
Loading…
Reference in New Issue