e2e disable node port on loadbalancers

This commit is contained in:
Antonio Ojea
2021-11-18 09:45:26 +01:00
parent 2ea3d320b0
commit 020cf2d7aa
2 changed files with 147 additions and 4 deletions

View File

@@ -473,10 +473,7 @@ func (j *TestJig) sanityCheckService(svc *v1.Service, svcType v1.ServiceType) (*
}
}
expectNodePorts := false
if svcType != v1.ServiceTypeClusterIP && svcType != v1.ServiceTypeExternalName {
expectNodePorts = true
}
expectNodePorts := needsNodePorts(svc)
for i, port := range svc.Spec.Ports {
hasNodePort := (port.NodePort != 0)
if hasNodePort != expectNodePorts {
@@ -499,6 +496,24 @@ func (j *TestJig) sanityCheckService(svc *v1.Service, svcType v1.ServiceType) (*
return svc, nil
}
func needsNodePorts(svc *v1.Service) bool {
if svc == nil {
return false
}
// Type NodePort
if svc.Spec.Type == v1.ServiceTypeNodePort {
return true
}
if svc.Spec.Type != v1.ServiceTypeLoadBalancer {
return false
}
// Type LoadBalancer
if svc.Spec.AllocateLoadBalancerNodePorts == nil {
return true //back-compat
}
return *svc.Spec.AllocateLoadBalancerNodePorts
}
// UpdateService fetches a service, calls the update function on it, and
// then attempts to send the updated service. It tries up to 3 times in the
// face of timeouts and conflicts.