From b85a8fbb7130b3efcadb0d5953c13cc1e6347b1c Mon Sep 17 00:00:00 2001 From: Joe Betz Date: Tue, 7 Nov 2017 07:07:21 -0800 Subject: [PATCH] Reapply cherry-pick #55064 This reverts commit e2f456b3a8ca39f340de3e73cc2a717ed68f01f0. --- pkg/api/validation/validation.go | 16 ------------ pkg/api/validation/validation_test.go | 36 --------------------------- 2 files changed, 52 deletions(-) diff --git a/pkg/api/validation/validation.go b/pkg/api/validation/validation.go index a6e623a6ec11..e19c6958f724 100644 --- a/pkg/api/validation/validation.go +++ b/pkg/api/validation/validation.go @@ -3152,22 +3152,6 @@ func ValidateService(service *api.Service) field.ErrorList { ports[key] = true } - // Check for duplicate TargetPort - portsPath = specPath.Child("ports") - targetPorts := make(map[api.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 := api.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 _, ok := service.Annotations[api.AnnotationLoadBalancerSourceRangesKey] if len(service.Spec.LoadBalancerSourceRanges) > 0 || ok { diff --git a/pkg/api/validation/validation_test.go b/pkg/api/validation/validation_test.go index 1df78dc1d9fa..b70fa9bf7551 100644 --- a/pkg/api/validation/validation_test.go +++ b/pkg/api/validation/validation_test.go @@ -7050,42 +7050,6 @@ func TestValidateService(t *testing.T) { }, numErrs: 0, }, - { - name: "invalid duplicate targetports (number with same protocol)", - tweakSvc: func(s *api.Service) { - s.Spec.Type = api.ServiceTypeClusterIP - s.Spec.Ports = append(s.Spec.Ports, api.ServicePort{Name: "q", Port: 1, Protocol: "TCP", TargetPort: intstr.FromInt(8080)}) - s.Spec.Ports = append(s.Spec.Ports, api.ServicePort{Name: "r", Port: 2, Protocol: "TCP", TargetPort: intstr.FromInt(8080)}) - }, - numErrs: 1, - }, - { - name: "invalid duplicate targetports (name with same protocol)", - tweakSvc: func(s *api.Service) { - s.Spec.Type = api.ServiceTypeClusterIP - s.Spec.Ports = append(s.Spec.Ports, api.ServicePort{Name: "q", Port: 1, Protocol: "TCP", TargetPort: intstr.FromString("http")}) - s.Spec.Ports = append(s.Spec.Ports, api.ServicePort{Name: "r", Port: 2, Protocol: "TCP", TargetPort: intstr.FromString("http")}) - }, - numErrs: 1, - }, - { - name: "valid duplicate targetports (number with different protocols)", - tweakSvc: func(s *api.Service) { - s.Spec.Type = api.ServiceTypeClusterIP - s.Spec.Ports = append(s.Spec.Ports, api.ServicePort{Name: "q", Port: 1, Protocol: "TCP", TargetPort: intstr.FromInt(8080)}) - s.Spec.Ports = append(s.Spec.Ports, api.ServicePort{Name: "r", Port: 2, Protocol: "UDP", TargetPort: intstr.FromInt(8080)}) - }, - numErrs: 0, - }, - { - name: "valid duplicate targetports (name with different protocols)", - tweakSvc: func(s *api.Service) { - s.Spec.Type = api.ServiceTypeClusterIP - s.Spec.Ports = append(s.Spec.Ports, api.ServicePort{Name: "q", Port: 1, Protocol: "TCP", TargetPort: intstr.FromString("http")}) - s.Spec.Ports = append(s.Spec.Ports, api.ServicePort{Name: "r", Port: 2, Protocol: "UDP", TargetPort: intstr.FromString("http")}) - }, - numErrs: 0, - }, { name: "valid type - cluster", tweakSvc: func(s *api.Service) {