Commit 4bb594b3 authored by feihujiang's avatar feihujiang

Duplicate service port name can't be validated

Duplicate service port name can't be validated Duplicate service port name can't be validated Duplicate service port name can't be validated
parent be15e84e
......@@ -1028,6 +1028,8 @@ func validateServicePort(sp *api.ServicePort, requireName bool, allNames *util.S
allErrs = append(allErrs, errs.NewFieldInvalid("name", sp.Name, dns1123LabelErrorMsg))
} else if allNames.Has(sp.Name) {
allErrs = append(allErrs, errs.NewFieldDuplicate("name", sp.Name))
} else {
allNames.Insert(sp.Name)
}
}
......
......@@ -1682,7 +1682,7 @@ func TestValidateService(t *testing.T) {
name: "dup port name",
tweakSvc: func(s *api.Service) {
s.Spec.Ports[0].Name = "p"
s.Spec.Ports = append(s.Spec.Ports, api.ServicePort{Name: "p", Port: 12345})
s.Spec.Ports = append(s.Spec.Ports, api.ServicePort{Name: "p", Port: 12345, Protocol: "TCP"})
},
numErrs: 1,
},
......@@ -1698,7 +1698,7 @@ func TestValidateService(t *testing.T) {
name: "invalid load balancer protocol 2",
tweakSvc: func(s *api.Service) {
s.Spec.CreateExternalLoadBalancer = true
s.Spec.Ports = append(s.Spec.Ports, api.ServicePort{Name: "p", Port: 12345, Protocol: "UDP"})
s.Spec.Ports = append(s.Spec.Ports, api.ServicePort{Name: "q", Port: 12345, Protocol: "UDP"})
},
numErrs: 1,
},
......@@ -1750,7 +1750,7 @@ func TestValidateService(t *testing.T) {
name: "valid external load balancer 2 ports",
tweakSvc: func(s *api.Service) {
s.Spec.CreateExternalLoadBalancer = true
s.Spec.Ports = append(s.Spec.Ports, api.ServicePort{Name: "p", Port: 12345, Protocol: "TCP"})
s.Spec.Ports = append(s.Spec.Ports, api.ServicePort{Name: "q", Port: 12345, Protocol: "TCP"})
},
numErrs: 0,
},
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment