mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-01 07:47:56 +00:00
Merge pull request #7486 from feihujiang/master
Duplicate service port name can't be validated
This commit is contained in:
commit
81aab06e3d
@ -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,
|
||||
},
|
||||
|
Loading…
Reference in New Issue
Block a user