Commit 4e39dd4b authored by k8s-merge-robot's avatar k8s-merge-robot

Merge pull request #16925 from mikedanese/headless-fix-1

Auto commit by PR queue bot
parents 0abc12ce 09295cd6
......@@ -1228,7 +1228,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 {
......
......@@ -1798,6 +1798,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) {
s.Spec.Ports[0].Name = ""
......
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