Commit c119c254 authored by Kubernetes Submit Queue's avatar Kubernetes Submit Queue Committed by GitHub

Merge pull request #43259 from thockin/nodeport-allocation-polarity

Automatic merge from submit-queue Fix polarity of a test in NodePort allocation The result of this was that an update to a Service would release the NodePort temporarily (the repair loop would fix it in a minute). During that window, another Service could get allocated that Port. Fixes #43233
parents 4dffb617 cb95c479
...@@ -93,9 +93,6 @@ func (rs *REST) Create(ctx genericapirequest.Context, obj runtime.Object) (runti ...@@ -93,9 +93,6 @@ func (rs *REST) Create(ctx genericapirequest.Context, obj runtime.Object) (runti
} }
}() }()
nodePortOp := portallocator.StartOperation(rs.serviceNodePorts)
defer nodePortOp.Finish()
if api.IsServiceIPRequested(service) { if api.IsServiceIPRequested(service) {
// Allocate next available. // Allocate next available.
ip, err := rs.serviceIPs.AllocateNext() ip, err := rs.serviceIPs.AllocateNext()
...@@ -117,6 +114,9 @@ func (rs *REST) Create(ctx genericapirequest.Context, obj runtime.Object) (runti ...@@ -117,6 +114,9 @@ func (rs *REST) Create(ctx genericapirequest.Context, obj runtime.Object) (runti
releaseServiceIP = true releaseServiceIP = true
} }
nodePortOp := portallocator.StartOperation(rs.serviceNodePorts)
defer nodePortOp.Finish()
assignNodePorts := shouldAssignNodePorts(service) assignNodePorts := shouldAssignNodePorts(service)
svcPortToNodePort := map[int]int{} svcPortToNodePort := map[int]int{}
for i := range service.Spec.Ports { for i := range service.Spec.Ports {
...@@ -436,7 +436,7 @@ func (rs *REST) Update(ctx genericapirequest.Context, name string, objInfo rest. ...@@ -436,7 +436,7 @@ func (rs *REST) Update(ctx genericapirequest.Context, name string, objInfo rest.
// The comparison loops are O(N^2), but we don't expect N to be huge // The comparison loops are O(N^2), but we don't expect N to be huge
// (there's a hard-limit at 2^16, because they're ports; and even 4 ports would be a lot) // (there's a hard-limit at 2^16, because they're ports; and even 4 ports would be a lot)
for _, oldNodePort := range oldNodePorts { for _, oldNodePort := range oldNodePorts {
if !contains(newNodePorts, oldNodePort) { if contains(newNodePorts, oldNodePort) {
continue continue
} }
nodePortOp.ReleaseDeferred(oldNodePort) nodePortOp.ReleaseDeferred(oldNodePort)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment