mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-27 21:47:07 +00:00
Merge pull request #20600 from freehan/servicevalidation
Auto commit by PR queue bot
This commit is contained in:
commit
aac20ed69d
@ -1653,12 +1653,18 @@ func ValidateService(service *api.Service) field.ErrorList {
|
|||||||
|
|
||||||
if service.Spec.Type == api.ServiceTypeLoadBalancer {
|
if service.Spec.Type == api.ServiceTypeLoadBalancer {
|
||||||
portsPath := specPath.Child("ports")
|
portsPath := specPath.Child("ports")
|
||||||
|
includeProtocols := sets.NewString()
|
||||||
for i := range service.Spec.Ports {
|
for i := range service.Spec.Ports {
|
||||||
portPath := portsPath.Index(i)
|
portPath := portsPath.Index(i)
|
||||||
if !supportedPortProtocols.Has(string(service.Spec.Ports[i].Protocol)) {
|
if !supportedPortProtocols.Has(string(service.Spec.Ports[i].Protocol)) {
|
||||||
allErrs = append(allErrs, field.Invalid(portPath.Child("protocol"), service.Spec.Ports[i].Protocol, "cannot create an external load balancer with non-TCP/UDP ports"))
|
allErrs = append(allErrs, field.Invalid(portPath.Child("protocol"), service.Spec.Ports[i].Protocol, "cannot create an external load balancer with non-TCP/UDP ports"))
|
||||||
|
} else {
|
||||||
|
includeProtocols.Insert(string(service.Spec.Ports[i].Protocol))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if includeProtocols.Len() > 1 {
|
||||||
|
allErrs = append(allErrs, field.Invalid(portsPath, service.Spec.Ports, "cannot create an external load balancer with mix protocols"))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if service.Spec.Type == api.ServiceTypeClusterIP {
|
if service.Spec.Type == api.ServiceTypeClusterIP {
|
||||||
|
@ -2580,10 +2580,18 @@ func TestValidateService(t *testing.T) {
|
|||||||
name: "valid load balancer protocol UDP 2",
|
name: "valid load balancer protocol UDP 2",
|
||||||
tweakSvc: func(s *api.Service) {
|
tweakSvc: func(s *api.Service) {
|
||||||
s.Spec.Type = api.ServiceTypeLoadBalancer
|
s.Spec.Type = api.ServiceTypeLoadBalancer
|
||||||
s.Spec.Ports = append(s.Spec.Ports, api.ServicePort{Name: "q", Port: 12345, Protocol: "UDP", TargetPort: intstr.FromInt(12345)})
|
s.Spec.Ports[0] = api.ServicePort{Name: "q", Port: 12345, Protocol: "UDP", TargetPort: intstr.FromInt(12345)}
|
||||||
},
|
},
|
||||||
numErrs: 0,
|
numErrs: 0,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "invalid load balancer with mix protocol",
|
||||||
|
tweakSvc: func(s *api.Service) {
|
||||||
|
s.Spec.Type = api.ServiceTypeLoadBalancer
|
||||||
|
s.Spec.Ports = append(s.Spec.Ports, api.ServicePort{Name: "q", Port: 12345, Protocol: "UDP", TargetPort: intstr.FromInt(12345)})
|
||||||
|
},
|
||||||
|
numErrs: 1,
|
||||||
|
},
|
||||||
{
|
{
|
||||||
name: "valid 1",
|
name: "valid 1",
|
||||||
tweakSvc: func(s *api.Service) {
|
tweakSvc: func(s *api.Service) {
|
||||||
|
Loading…
Reference in New Issue
Block a user