bug fix for hostport-syncer

pull/6/head
Minhan Xia 2017-02-17 13:51:11 -08:00
parent 6d5b2ef49e
commit 6b34343946
2 changed files with 10 additions and 8 deletions

View File

@ -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

View File

@ -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