Skip to content

Commit

Permalink
Merge pull request openshift#917 from pecameron/bz1506378
Browse files Browse the repository at this point in the history
Fix the check for "pod has HostPorts"
  • Loading branch information
eparis authored Oct 26, 2017
2 parents 363ae75 + 1b56ebe commit a66f627
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions pkg/sdn/plugin/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,15 @@ func (m *podManager) getPod(request *cniserver.PodRequest) *kubehostport.PodPort
return nil
}

func hasHostPorts(pod *kubehostport.PodPortMapping) bool {
for _, mapping := range pod.PortMappings {
if mapping.HostPort != 0 {
return true
}
}
return false
}

// Return a list of Kubernetes RunningPod objects for hostport operations
func (m *podManager) shouldSyncHostports(newPod *kubehostport.PodPortMapping) []*kubehostport.PodPortMapping {
if m.hostportSyncer == nil {
Expand All @@ -165,11 +174,11 @@ func (m *podManager) shouldSyncHostports(newPod *kubehostport.PodPortMapping) []
mappings := make([]*kubehostport.PodPortMapping, 0)
for _, runningPod := range m.runningPods {
mappings = append(mappings, runningPod.podPortMapping)
if !newActiveHostports && len(runningPod.podPortMapping.PortMappings) > 0 {
if !newActiveHostports && hasHostPorts(runningPod.podPortMapping) {
newActiveHostports = true
}
}
if newPod != nil && len(newPod.PortMappings) > 0 {
if newPod != nil && hasHostPorts(newPod) {
newActiveHostports = true
}

Expand Down

0 comments on commit a66f627

Please sign in to comment.