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:
Dan Williams 2016-05-02 19:49:02 -05:00
parent 55e6eb2ce3
commit 9b85d20c73
5 changed files with 28 additions and 17 deletions

View File

@ -97,6 +97,12 @@ type Runtime interface {
RemoveImage(image ImageSpec) error RemoveImage(image ImageSpec) error
// Returns Image statistics. // Returns Image statistics.
ImageStats() (*ImageStats, error) 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. // 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

View File

@ -338,6 +338,14 @@ func (f *FakeRuntime) PortForward(pod *Pod, port uint16, stream io.ReadWriteClos
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")
return "", f.Err
}
func (f *FakeRuntime) GarbageCollect(gcPolicy ContainerGCPolicy) error { func (f *FakeRuntime) GarbageCollect(gcPolicy ContainerGCPolicy) error {
f.Lock() f.Lock()
defer f.Unlock() defer f.Unlock()

View File

@ -128,6 +128,11 @@ 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) GarbageCollect(gcPolicy ContainerGCPolicy) error { func (r *Mock) GarbageCollect(gcPolicy ContainerGCPolicy) error {
args := r.Called(gcPolicy) args := r.Called(gcPolicy)
return args.Error(0) return args.Error(0)

View File

@ -34,7 +34,6 @@ import (
"github.com/golang/glog" "github.com/golang/glog"
"k8s.io/kubernetes/pkg/apis/componentconfig" "k8s.io/kubernetes/pkg/apis/componentconfig"
kubecontainer "k8s.io/kubernetes/pkg/kubelet/container" kubecontainer "k8s.io/kubernetes/pkg/kubelet/container"
"k8s.io/kubernetes/pkg/kubelet/dockertools"
"k8s.io/kubernetes/pkg/kubelet/network" "k8s.io/kubernetes/pkg/kubelet/network"
"k8s.io/kubernetes/pkg/util/bandwidth" "k8s.io/kubernetes/pkg/util/bandwidth"
utilexec "k8s.io/kubernetes/pkg/util/exec" 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) return fmt.Errorf("Kubenet cannot SetUpPod: %v", err)
} }
runtime, ok := plugin.host.GetRuntime().(*dockertools.DockerManager) netnsPath, err := plugin.host.GetRuntime().GetNetNS(id)
if !ok {
return fmt.Errorf("Kubenet execution called on non-docker runtime")
}
netnsPath, err := runtime.GetNetNS(id)
if err != nil { if err != nil {
return fmt.Errorf("Kubenet failed to retrieve network namespace path: %v", err) 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") return fmt.Errorf("Kubenet needs a PodCIDR to tear down pods")
} }
runtime, ok := plugin.host.GetRuntime().(*dockertools.DockerManager) netnsPath, err := plugin.host.GetRuntime().GetNetNS(id)
if !ok {
return fmt.Errorf("Kubenet execution called on non-docker runtime")
}
netnsPath, err := runtime.GetNetNS(id)
if err != nil { if err != nil {
return err return err
} }
@ -373,12 +364,8 @@ func (plugin *kubenetNetworkPlugin) GetPodNetworkStatus(namespace string, name s
return &network.PodNetworkStatus{IP: ip}, nil return &network.PodNetworkStatus{IP: ip}, nil
} }
} }
// TODO: remove type conversion once kubenet supports multiple runtime
runtime, ok := plugin.host.GetRuntime().(*dockertools.DockerManager) netnsPath, err := plugin.host.GetRuntime().GetNetNS(id)
if !ok {
return nil, fmt.Errorf("Kubenet execution called on non-docker runtime")
}
netnsPath, err := runtime.GetNetNS(id)
if err != nil { if err != nil {
return nil, fmt.Errorf("Kubenet failed to retrieve network namespace path: %v", err) return nil, fmt.Errorf("Kubenet failed to retrieve network namespace path: %v", err)
} }

View File

@ -1488,6 +1488,11 @@ func podIsActive(pod *rktapi.Pod) bool {
pod.State == rktapi.PodState_POD_STATE_RUNNING 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. // GarbageCollect collects the pods/containers.
// After one GC iteration: // After one GC iteration:
// - The deleted pods will be removed. // - The deleted pods will be removed.