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
This commit is contained in:
feihujiang 2015-04-29 10:08:42 +08:00
parent be15e84e83
commit 4bb594b34d
2 changed files with 5 additions and 3 deletions

View File

@ -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)
}
}

View File

@ -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,
},