kubelet/kubenet: Fix getRunningPods() to support rkt pods
Don't assume there's an infra container.
This commit is contained in:
parent
db078dbea4
commit
a657d0587b
@ -108,6 +108,11 @@ type Runtime interface {
|
||||
// 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
|
||||
|
@ -368,6 +368,14 @@ func (f *FakeRuntime) GetNetNS(containerID ContainerID) (string, error) {
|
||||
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) error {
|
||||
f.Lock()
|
||||
defer f.Unlock()
|
||||
|
@ -133,6 +133,11 @@ func (r *Mock) GetNetNS(containerID ContainerID) (string, error) {
|
||||
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) error {
|
||||
args := r.Called(gcPolicy, ready)
|
||||
return args.Error(0)
|
||||
|
@ -2318,6 +2318,16 @@ func (dm *DockerManager) GetNetNS(containerID kubecontainer.ContainerID) (string
|
||||
return netnsPath, nil
|
||||
}
|
||||
|
||||
func (dm *DockerManager) GetPodContainerID(pod *kubecontainer.Pod) (kubecontainer.ContainerID, error) {
|
||||
for _, c := range pod.Containers {
|
||||
if c.Name == PodInfraContainerName {
|
||||
return c.ID, nil
|
||||
}
|
||||
}
|
||||
|
||||
return kubecontainer.ContainerID{}, fmt.Errorf("Pod %s unknown to docker.", kubecontainer.BuildPodFullName(pod.Name, pod.Namespace))
|
||||
}
|
||||
|
||||
// Garbage collection of dead containers
|
||||
func (dm *DockerManager) GarbageCollect(gcPolicy kubecontainer.ContainerGCPolicy, allSourcesReady bool) error {
|
||||
return dm.containerGC.GarbageCollect(gcPolicy, allSourcesReady)
|
||||
|
@ -34,7 +34,6 @@ import (
|
||||
"k8s.io/kubernetes/pkg/api"
|
||||
"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"
|
||||
utildbus "k8s.io/kubernetes/pkg/util/dbus"
|
||||
@ -495,24 +494,23 @@ func (plugin *kubenetNetworkPlugin) getRunningPods() ([]*hostport.RunningPod, er
|
||||
}
|
||||
runningPods := make([]*hostport.RunningPod, 0)
|
||||
for _, p := range pods {
|
||||
for _, c := range p.Containers {
|
||||
if c.Name != dockertools.PodInfraContainerName {
|
||||
continue
|
||||
}
|
||||
ipString, ok := plugin.podIPs[c.ID]
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
podIP := net.ParseIP(ipString)
|
||||
if podIP == nil {
|
||||
continue
|
||||
}
|
||||
if pod, ok := plugin.host.GetPodByName(p.Namespace, p.Name); ok {
|
||||
runningPods = append(runningPods, &hostport.RunningPod{
|
||||
Pod: pod,
|
||||
IP: podIP,
|
||||
})
|
||||
}
|
||||
containerID, err := plugin.host.GetRuntime().GetPodContainerID(p)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
ipString, ok := plugin.podIPs[containerID]
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
podIP := net.ParseIP(ipString)
|
||||
if podIP == nil {
|
||||
continue
|
||||
}
|
||||
if pod, ok := plugin.host.GetPodByName(p.Namespace, p.Name); ok {
|
||||
runningPods = append(runningPods, &hostport.RunningPod{
|
||||
Pod: pod,
|
||||
IP: podIP,
|
||||
})
|
||||
}
|
||||
}
|
||||
return runningPods, nil
|
||||
|
@ -1785,6 +1785,10 @@ func (r *Runtime) GetNetNS(containerID kubecontainer.ContainerID) (string, error
|
||||
return netnsPathFromName(makePodNetnsName(kubetypes.UID(containerID.ID))), nil
|
||||
}
|
||||
|
||||
func (r *Runtime) GetPodContainerID(pod *kubecontainer.Pod) (kubecontainer.ContainerID, error) {
|
||||
return kubecontainer.ContainerID{ID: string(pod.ID)}, nil
|
||||
}
|
||||
|
||||
func podDetailsFromServiceFile(serviceFilePath string) (string, string, string, bool, error) {
|
||||
f, err := os.Open(serviceFilePath)
|
||||
if err != nil {
|
||||
|
Loading…
Reference in New Issue
Block a user