From 6b34343946eb50d58c73aa361bee938dfc770a6c Mon Sep 17 00:00:00 2001 From: Minhan Xia Date: Fri, 17 Feb 2017 13:51:11 -0800 Subject: [PATCH] bug fix for hostport-syncer --- pkg/kubelet/network/hostport/hostport_syncer.go | 8 +++++--- pkg/kubelet/network/kubenet/kubenet_linux.go | 10 +++++----- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/pkg/kubelet/network/hostport/hostport_syncer.go b/pkg/kubelet/network/hostport/hostport_syncer.go index bba67095dd8..c72c9e16e3d 100644 --- a/pkg/kubelet/network/hostport/hostport_syncer.go +++ b/pkg/kubelet/network/hostport/hostport_syncer.go @@ -114,9 +114,9 @@ func getPodFullName(pod *PodPortMapping) string { // gatherAllHostports returns all hostports that should be presented on node, // given the list of pods running on that node and ignoring host network // pods (which don't need hostport <-> container port mapping). -func gatherAllHostports(activePodPortMapping []*PodPortMapping) (map[*PortMapping]targetPod, error) { +func gatherAllHostports(activePodPortMappings []*PodPortMapping) (map[*PortMapping]targetPod, error) { podHostportMap := make(map[*PortMapping]targetPod) - for _, pm := range activePodPortMapping { + for _, pm := range activePodPortMappings { if pm.IP.To4() == nil { return nil, fmt.Errorf("Invalid or missing pod %s IP", getPodFullName(pm)) } @@ -126,7 +126,9 @@ func gatherAllHostports(activePodPortMapping []*PodPortMapping) (map[*PortMappin } for _, port := range pm.PortMappings { - podHostportMap[port] = targetPod{podFullName: getPodFullName(pm), podIP: pm.IP.String()} + if port.HostPort != 0 { + podHostportMap[port] = targetPod{podFullName: getPodFullName(pm), podIP: pm.IP.String()} + } } } return podHostportMap, nil diff --git a/pkg/kubelet/network/kubenet/kubenet_linux.go b/pkg/kubelet/network/kubenet/kubenet_linux.go index 86454c8cad6..8ac40d44b7e 100644 --- a/pkg/kubelet/network/kubenet/kubenet_linux.go +++ b/pkg/kubelet/network/kubenet/kubenet_linux.go @@ -376,14 +376,14 @@ func (plugin *kubenetNetworkPlugin) setup(namespace string, name string, id kube } } - // Open any hostports the pod's containers want - activePodPortMapping, err := plugin.getPodPortMapping() + // Open any hostport the pod's containers want + activePodPortMappings, err := plugin.getPodPortMappings() if err != nil { return err } newPodPortMapping := constructPodPortMapping(pod, ip4) - if err := plugin.hostportSyncer.OpenPodHostportsAndSync(newPodPortMapping, BridgeName, activePodPortMapping); err != nil { + if err := plugin.hostportSyncer.OpenPodHostportsAndSync(newPodPortMapping, BridgeName, activePodPortMappings); err != nil { return err } } else { @@ -486,7 +486,7 @@ func (plugin *kubenetNetworkPlugin) teardown(namespace string, name string, id k // The host can choose to not support "legacy" features. The remote // shim doesn't support it (#35457), but the kubelet does. if plugin.host.SupportsLegacyFeatures() { - activePodPortMapping, err := plugin.getPodPortMapping() + activePodPortMapping, err := plugin.getPodPortMappings() if err == nil { err = plugin.hostportSyncer.SyncHostports(BridgeName, activePodPortMapping) } @@ -618,7 +618,7 @@ func (plugin *kubenetNetworkPlugin) getNonExitedPods() ([]*kubecontainer.Pod, er return ret, nil } -func (plugin *kubenetNetworkPlugin) getPodPortMapping() ([]*hostport.PodPortMapping, error) { +func (plugin *kubenetNetworkPlugin) getPodPortMappings() ([]*hostport.PodPortMapping, error) { pods, err := plugin.getNonExitedPods() if err != nil { return nil, err