mirror of https://github.com/k3s-io/k3s
Headless services should not need to declare ports
parent
0b183f43fd
commit
09295cd664
|
@ -1224,7 +1224,7 @@ func ValidateService(service *api.Service) errs.ValidationErrorList {
|
|||
allErrs := errs.ValidationErrorList{}
|
||||
allErrs = append(allErrs, ValidateObjectMeta(&service.ObjectMeta, true, ValidateServiceName).Prefix("metadata")...)
|
||||
|
||||
if len(service.Spec.Ports) == 0 {
|
||||
if len(service.Spec.Ports) == 0 && service.Spec.ClusterIP != api.ClusterIPNone {
|
||||
allErrs = append(allErrs, errs.NewFieldRequired("spec.ports"))
|
||||
}
|
||||
if service.Spec.Type == api.ServiceTypeLoadBalancer {
|
||||
|
|
|
@ -1792,6 +1792,14 @@ func TestValidateService(t *testing.T) {
|
|||
},
|
||||
numErrs: 1,
|
||||
},
|
||||
{
|
||||
name: "missing ports but headless",
|
||||
tweakSvc: func(s *api.Service) {
|
||||
s.Spec.Ports = nil
|
||||
s.Spec.ClusterIP = api.ClusterIPNone
|
||||
},
|
||||
numErrs: 0,
|
||||
},
|
||||
{
|
||||
name: "empty port[0] name",
|
||||
tweakSvc: func(s *api.Service) {
|
||||
|
|
Loading…
Reference in New Issue