mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-19 08:40:42 +00:00
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
|
// TODO: Change ContainerID to a Pod ID since the namespace is shared
|
||||||
// by all containers in the pod.
|
// by all containers in the pod.
|
||||||
GetNetNS(containerID ContainerID) (string, error)
|
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
|
||||||
|
@ -368,6 +368,14 @@ func (f *FakeRuntime) GetNetNS(containerID ContainerID) (string, error) {
|
|||||||
return "", f.Err
|
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 {
|
func (f *FakeRuntime) GarbageCollect(gcPolicy ContainerGCPolicy, ready bool) error {
|
||||||
f.Lock()
|
f.Lock()
|
||||||
defer f.Unlock()
|
defer f.Unlock()
|
||||||
|
@ -133,6 +133,11 @@ func (r *Mock) GetNetNS(containerID ContainerID) (string, error) {
|
|||||||
return "", args.Error(0)
|
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 {
|
func (r *Mock) GarbageCollect(gcPolicy ContainerGCPolicy, ready bool) error {
|
||||||
args := r.Called(gcPolicy, ready)
|
args := r.Called(gcPolicy, ready)
|
||||||
return args.Error(0)
|
return args.Error(0)
|
||||||
|
@ -2318,6 +2318,16 @@ func (dm *DockerManager) GetNetNS(containerID kubecontainer.ContainerID) (string
|
|||||||
return netnsPath, nil
|
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
|
// Garbage collection of dead containers
|
||||||
func (dm *DockerManager) GarbageCollect(gcPolicy kubecontainer.ContainerGCPolicy, allSourcesReady bool) error {
|
func (dm *DockerManager) GarbageCollect(gcPolicy kubecontainer.ContainerGCPolicy, allSourcesReady bool) error {
|
||||||
return dm.containerGC.GarbageCollect(gcPolicy, allSourcesReady)
|
return dm.containerGC.GarbageCollect(gcPolicy, allSourcesReady)
|
||||||
|
@ -34,7 +34,6 @@ import (
|
|||||||
"k8s.io/kubernetes/pkg/api"
|
"k8s.io/kubernetes/pkg/api"
|
||||||
"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"
|
||||||
utildbus "k8s.io/kubernetes/pkg/util/dbus"
|
utildbus "k8s.io/kubernetes/pkg/util/dbus"
|
||||||
@ -495,11 +494,11 @@ func (plugin *kubenetNetworkPlugin) getRunningPods() ([]*hostport.RunningPod, er
|
|||||||
}
|
}
|
||||||
runningPods := make([]*hostport.RunningPod, 0)
|
runningPods := make([]*hostport.RunningPod, 0)
|
||||||
for _, p := range pods {
|
for _, p := range pods {
|
||||||
for _, c := range p.Containers {
|
containerID, err := plugin.host.GetRuntime().GetPodContainerID(p)
|
||||||
if c.Name != dockertools.PodInfraContainerName {
|
if err != nil {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
ipString, ok := plugin.podIPs[c.ID]
|
ipString, ok := plugin.podIPs[containerID]
|
||||||
if !ok {
|
if !ok {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
@ -514,7 +513,6 @@ func (plugin *kubenetNetworkPlugin) getRunningPods() ([]*hostport.RunningPod, er
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return runningPods, nil
|
return runningPods, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1785,6 +1785,10 @@ func (r *Runtime) GetNetNS(containerID kubecontainer.ContainerID) (string, error
|
|||||||
return netnsPathFromName(makePodNetnsName(kubetypes.UID(containerID.ID))), nil
|
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) {
|
func podDetailsFromServiceFile(serviceFilePath string) (string, string, string, bool, error) {
|
||||||
f, err := os.Open(serviceFilePath)
|
f, err := os.Open(serviceFilePath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user