mirror of
https://github.com/optim-enterprises-bv/kubernetes.git
synced 2025-11-03 03:38:15 +00:00
add hostip protocol to the hostport predicates and make unit test adapt to the code change
This commit is contained in:
@@ -890,7 +890,7 @@ func (s *ServiceAffinity) checkServiceAffinity(pod *v1.Pod, meta algorithm.Predi
|
||||
|
||||
// PodFitsHostPorts checks if a node has free ports for the requested pod ports.
|
||||
func PodFitsHostPorts(pod *v1.Pod, meta algorithm.PredicateMetadata, nodeInfo *schedulercache.NodeInfo) (bool, []algorithm.PredicateFailureReason, error) {
|
||||
var wantPorts map[int]bool
|
||||
var wantPorts map[string]bool
|
||||
if predicateMeta, ok := meta.(*predicateMetadata); ok {
|
||||
wantPorts = predicateMeta.podPorts
|
||||
} else {
|
||||
@@ -902,11 +902,45 @@ func PodFitsHostPorts(pod *v1.Pod, meta algorithm.PredicateMetadata, nodeInfo *s
|
||||
}
|
||||
|
||||
existingPorts := nodeInfo.UsedPorts()
|
||||
for wport := range wantPorts {
|
||||
if wport != 0 && existingPorts[wport] {
|
||||
return false, []algorithm.PredicateFailureReason{ErrPodNotFitsHostPorts}, nil
|
||||
|
||||
// try to see whether two hostPorts will conflict or not
|
||||
for existingPort := range existingPorts {
|
||||
existingHostPortInfo := decode(existingPort)
|
||||
|
||||
if existingHostPortInfo.hostIP == "0.0.0.0" {
|
||||
// loop through all the want hostPort to see if there exists a conflict
|
||||
for wantPort := range wantPorts {
|
||||
wantHostPortInfo := decode(wantPort)
|
||||
|
||||
// if there already exists one hostPort whose hostIP is 0.0.0.0, then the other want hostport (which has the same protocol and port) will not fit
|
||||
if wantHostPortInfo.hostPort == existingHostPortInfo.hostPort && wantHostPortInfo.protocol == existingHostPortInfo.protocol {
|
||||
return false, []algorithm.PredicateFailureReason{ErrPodNotFitsHostPorts}, nil
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for wantPort := range wantPorts {
|
||||
wantHostPortInfo := decode(wantPort)
|
||||
|
||||
if wantHostPortInfo.hostIP == "0.0.0.0" {
|
||||
// loop through all the existing hostPort to see if there exists a conflict
|
||||
for existingPort := range existingPorts {
|
||||
existingHostPortInfo := decode(existingPort)
|
||||
|
||||
// if there already exists one hostPort whose hostIP may be 127.0.0.1, then a hostPort (which wants 0.0.0.0 hostIP and has the same protocol and port) will not fit
|
||||
if wantHostPortInfo.hostPort == existingHostPortInfo.hostPort && wantHostPortInfo.protocol == existingHostPortInfo.protocol {
|
||||
return false, []algorithm.PredicateFailureReason{ErrPodNotFitsHostPorts}, nil
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// general check hostPort conflict procedure for hostIP is not 0.0.0.0
|
||||
if wantPort != "" && existingPorts[wantPort] {
|
||||
return false, []algorithm.PredicateFailureReason{ErrPodNotFitsHostPorts}, nil
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true, nil, nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user