Skip to content

Commit

Permalink
Distinguish between different unnamed node ports when preserving
Browse files Browse the repository at this point in the history
Signed-off-by: Scott Seago <[email protected]>
  • Loading branch information
sseago committed Aug 9, 2021
1 parent ed5809b commit 8d714d3
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
1 change: 1 addition & 0 deletions changelogs/unreleased/4026-sseago
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Distinguish between different unnamed node ports when preserving
13 changes: 10 additions & 3 deletions pkg/restore/service_action.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ func deleteNodePorts(service *corev1api.Service) error {
// to the last-applied-config annotation. We'll retain these values, and
// clear out any other (presumably auto-assigned) NodePort values.
explicitNodePorts := sets.NewString()
unnamedPortInts := sets.NewInt()
lastAppliedConfig, ok := service.Annotations[annotationLastAppliedConfig]
if ok {
appliedServiceUnstructured := new(map[string]interface{})
Expand Down Expand Up @@ -123,7 +124,7 @@ func deleteNodePorts(service *corev1api.Service) error {
portName, ok := p["name"]
if !ok {
// unnamed port
explicitNodePorts.Insert("")
unnamedPortInts.Insert(nodePortInt)
} else {
explicitNodePorts.Insert(portName.(string))
}
Expand All @@ -135,8 +136,14 @@ func deleteNodePorts(service *corev1api.Service) error {
}

for i, port := range service.Spec.Ports {
if !explicitNodePorts.Has(port.Name) {
service.Spec.Ports[i].NodePort = 0
if port.Name != "" {
if !explicitNodePorts.Has(port.Name) {
service.Spec.Ports[i].NodePort = 0
}
} else {
if !unnamedPortInts.Has(int(port.NodePort)) {
service.Spec.Ports[i].NodePort = 0
}
}
}

Expand Down
4 changes: 4 additions & 0 deletions pkg/restore/service_action_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,9 @@ func TestServiceActionExecute(t *testing.T) {
{
NodePort: 8080,
},
{
NodePort: 9090,
},
},
},
},
Expand All @@ -212,6 +215,7 @@ func TestServiceActionExecute(t *testing.T) {
{
NodePort: 8080,
},
{},
},
},
},
Expand Down

0 comments on commit 8d714d3

Please sign in to comment.