mirror of
https://github.com/vmware-tanzu/velero.git
synced 2026-01-10 15:07:29 +00:00
Distinguish between different unnamed node ports when preserving
Signed-off-by: Scott Seago <sseago@redhat.com>
This commit is contained in:
1
changelogs/unreleased/4026-sseago
Normal file
1
changelogs/unreleased/4026-sseago
Normal file
@@ -0,0 +1 @@
|
||||
Distinguish between different unnamed node ports when preserving
|
||||
@@ -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{})
|
||||
@@ -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))
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -196,6 +196,9 @@ func TestServiceActionExecute(t *testing.T) {
|
||||
{
|
||||
NodePort: 8080,
|
||||
},
|
||||
{
|
||||
NodePort: 9090,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -212,6 +215,7 @@ func TestServiceActionExecute(t *testing.T) {
|
||||
{
|
||||
NodePort: 8080,
|
||||
},
|
||||
{},
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user