mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-27 13:37:30 +00:00
Revert "Validate if service has duplicate targetPort"
This reverts commit ce54d9072b
.
This commit is contained in:
parent
338ee7f5d5
commit
117edceadc
@ -3184,22 +3184,6 @@ func ValidateService(service *core.Service) field.ErrorList {
|
|||||||
ports[key] = true
|
ports[key] = true
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check for duplicate TargetPort
|
|
||||||
portsPath = specPath.Child("ports")
|
|
||||||
targetPorts := make(map[core.ServicePort]bool)
|
|
||||||
for i, port := range service.Spec.Ports {
|
|
||||||
if (port.TargetPort.Type == intstr.Int && port.TargetPort.IntVal == 0) || (port.TargetPort.Type == intstr.String && port.TargetPort.StrVal == "") {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
portPath := portsPath.Index(i)
|
|
||||||
key := core.ServicePort{Protocol: port.Protocol, TargetPort: port.TargetPort}
|
|
||||||
_, found := targetPorts[key]
|
|
||||||
if found {
|
|
||||||
allErrs = append(allErrs, field.Duplicate(portPath.Child("targetPort"), port.TargetPort))
|
|
||||||
}
|
|
||||||
targetPorts[key] = true
|
|
||||||
}
|
|
||||||
|
|
||||||
// Validate SourceRange field and annotation
|
// Validate SourceRange field and annotation
|
||||||
_, ok := service.Annotations[core.AnnotationLoadBalancerSourceRangesKey]
|
_, ok := service.Annotations[core.AnnotationLoadBalancerSourceRangesKey]
|
||||||
if len(service.Spec.LoadBalancerSourceRanges) > 0 || ok {
|
if len(service.Spec.LoadBalancerSourceRanges) > 0 || ok {
|
||||||
|
@ -7113,42 +7113,6 @@ func TestValidateService(t *testing.T) {
|
|||||||
},
|
},
|
||||||
numErrs: 0,
|
numErrs: 0,
|
||||||
},
|
},
|
||||||
{
|
|
||||||
name: "invalid duplicate targetports (number with same protocol)",
|
|
||||||
tweakSvc: func(s *core.Service) {
|
|
||||||
s.Spec.Type = core.ServiceTypeClusterIP
|
|
||||||
s.Spec.Ports = append(s.Spec.Ports, core.ServicePort{Name: "q", Port: 1, Protocol: "TCP", TargetPort: intstr.FromInt(8080)})
|
|
||||||
s.Spec.Ports = append(s.Spec.Ports, core.ServicePort{Name: "r", Port: 2, Protocol: "TCP", TargetPort: intstr.FromInt(8080)})
|
|
||||||
},
|
|
||||||
numErrs: 1,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "invalid duplicate targetports (name with same protocol)",
|
|
||||||
tweakSvc: func(s *core.Service) {
|
|
||||||
s.Spec.Type = core.ServiceTypeClusterIP
|
|
||||||
s.Spec.Ports = append(s.Spec.Ports, core.ServicePort{Name: "q", Port: 1, Protocol: "TCP", TargetPort: intstr.FromString("http")})
|
|
||||||
s.Spec.Ports = append(s.Spec.Ports, core.ServicePort{Name: "r", Port: 2, Protocol: "TCP", TargetPort: intstr.FromString("http")})
|
|
||||||
},
|
|
||||||
numErrs: 1,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "valid duplicate targetports (number with different protocols)",
|
|
||||||
tweakSvc: func(s *core.Service) {
|
|
||||||
s.Spec.Type = core.ServiceTypeClusterIP
|
|
||||||
s.Spec.Ports = append(s.Spec.Ports, core.ServicePort{Name: "q", Port: 1, Protocol: "TCP", TargetPort: intstr.FromInt(8080)})
|
|
||||||
s.Spec.Ports = append(s.Spec.Ports, core.ServicePort{Name: "r", Port: 2, Protocol: "UDP", TargetPort: intstr.FromInt(8080)})
|
|
||||||
},
|
|
||||||
numErrs: 0,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "valid duplicate targetports (name with different protocols)",
|
|
||||||
tweakSvc: func(s *core.Service) {
|
|
||||||
s.Spec.Type = core.ServiceTypeClusterIP
|
|
||||||
s.Spec.Ports = append(s.Spec.Ports, core.ServicePort{Name: "q", Port: 1, Protocol: "TCP", TargetPort: intstr.FromString("http")})
|
|
||||||
s.Spec.Ports = append(s.Spec.Ports, core.ServicePort{Name: "r", Port: 2, Protocol: "UDP", TargetPort: intstr.FromString("http")})
|
|
||||||
},
|
|
||||||
numErrs: 0,
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
name: "valid type - cluster",
|
name: "valid type - cluster",
|
||||||
tweakSvc: func(s *core.Service) {
|
tweakSvc: func(s *core.Service) {
|
||||||
|
Loading…
Reference in New Issue
Block a user