mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-25 12:43:23 +00:00
kubelet/runtime: add method to return pod network namespace path
Some runtimes (eg, Hypernetes) don't create network namespaces for pods, so network plugins must correctly handle any error returned from the runtime.
This commit is contained in:
parent
55e6eb2ce3
commit
9b85d20c73
@ -97,6 +97,12 @@ type Runtime interface {
|
||||
RemoveImage(image ImageSpec) error
|
||||
// Returns Image statistics.
|
||||
ImageStats() (*ImageStats, 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)
|
||||
// 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
|
||||
|
@ -338,6 +338,14 @@ func (f *FakeRuntime) PortForward(pod *Pod, port uint16, stream io.ReadWriteClos
|
||||
return f.Err
|
||||
}
|
||||
|
||||
func (f *FakeRuntime) GetNetNS(containerID ContainerID) (string, error) {
|
||||
f.Lock()
|
||||
defer f.Unlock()
|
||||
|
||||
f.CalledFunctions = append(f.CalledFunctions, "GetNetNS")
|
||||
return "", f.Err
|
||||
}
|
||||
|
||||
func (f *FakeRuntime) GarbageCollect(gcPolicy ContainerGCPolicy) error {
|
||||
f.Lock()
|
||||
defer f.Unlock()
|
||||
|
@ -128,6 +128,11 @@ 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) GarbageCollect(gcPolicy ContainerGCPolicy) error {
|
||||
args := r.Called(gcPolicy)
|
||||
return args.Error(0)
|
||||
|
@ -34,7 +34,6 @@ import (
|
||||
"github.com/golang/glog"
|
||||
"k8s.io/kubernetes/pkg/apis/componentconfig"
|
||||
kubecontainer "k8s.io/kubernetes/pkg/kubelet/container"
|
||||
"k8s.io/kubernetes/pkg/kubelet/dockertools"
|
||||
"k8s.io/kubernetes/pkg/kubelet/network"
|
||||
"k8s.io/kubernetes/pkg/util/bandwidth"
|
||||
utilexec "k8s.io/kubernetes/pkg/util/exec"
|
||||
@ -266,11 +265,7 @@ func (plugin *kubenetNetworkPlugin) SetUpPod(namespace string, name string, id k
|
||||
return fmt.Errorf("Kubenet cannot SetUpPod: %v", err)
|
||||
}
|
||||
|
||||
runtime, ok := plugin.host.GetRuntime().(*dockertools.DockerManager)
|
||||
if !ok {
|
||||
return fmt.Errorf("Kubenet execution called on non-docker runtime")
|
||||
}
|
||||
netnsPath, err := runtime.GetNetNS(id)
|
||||
netnsPath, err := plugin.host.GetRuntime().GetNetNS(id)
|
||||
if err != nil {
|
||||
return fmt.Errorf("Kubenet failed to retrieve network namespace path: %v", err)
|
||||
}
|
||||
@ -330,11 +325,7 @@ func (plugin *kubenetNetworkPlugin) TearDownPod(namespace string, name string, i
|
||||
return fmt.Errorf("Kubenet needs a PodCIDR to tear down pods")
|
||||
}
|
||||
|
||||
runtime, ok := plugin.host.GetRuntime().(*dockertools.DockerManager)
|
||||
if !ok {
|
||||
return fmt.Errorf("Kubenet execution called on non-docker runtime")
|
||||
}
|
||||
netnsPath, err := runtime.GetNetNS(id)
|
||||
netnsPath, err := plugin.host.GetRuntime().GetNetNS(id)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -373,12 +364,8 @@ func (plugin *kubenetNetworkPlugin) GetPodNetworkStatus(namespace string, name s
|
||||
return &network.PodNetworkStatus{IP: ip}, nil
|
||||
}
|
||||
}
|
||||
// TODO: remove type conversion once kubenet supports multiple runtime
|
||||
runtime, ok := plugin.host.GetRuntime().(*dockertools.DockerManager)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("Kubenet execution called on non-docker runtime")
|
||||
}
|
||||
netnsPath, err := runtime.GetNetNS(id)
|
||||
|
||||
netnsPath, err := plugin.host.GetRuntime().GetNetNS(id)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("Kubenet failed to retrieve network namespace path: %v", err)
|
||||
}
|
||||
|
@ -1488,6 +1488,11 @@ func podIsActive(pod *rktapi.Pod) bool {
|
||||
pod.State == rktapi.PodState_POD_STATE_RUNNING
|
||||
}
|
||||
|
||||
// GetNetNS returns the network namespace path for the given container
|
||||
func (r *Runtime) GetNetNS(containerID kubecontainer.ContainerID) (string, error) {
|
||||
return "", nil
|
||||
}
|
||||
|
||||
// GarbageCollect collects the pods/containers.
|
||||
// After one GC iteration:
|
||||
// - The deleted pods will be removed.
|
||||
|
Loading…
Reference in New Issue
Block a user