Allow an empty service
This commit is contained in:
@@ -438,9 +438,12 @@ func ValidateService(service *api.Service, lister ServiceLister, ctx api.Context
|
||||
} else if !supportedPortProtocols.Has(strings.ToUpper(string(service.Spec.Protocol))) {
|
||||
allErrs = append(allErrs, errs.NewFieldNotSupported("spec.protocol", service.Spec.Protocol))
|
||||
}
|
||||
if labels.Set(service.Spec.Selector).AsSelector().Empty() {
|
||||
allErrs = append(allErrs, errs.NewFieldRequired("spec.selector", service.Spec.Selector))
|
||||
|
||||
if service.Spec.Selector != nil {
|
||||
allErrs = append(allErrs, validateLabels(service.Spec.Selector, "spec.selector")...)
|
||||
}
|
||||
allErrs = append(allErrs, validateLabels(service.Labels, "labels")...)
|
||||
|
||||
if service.Spec.CreateExternalLoadBalancer {
|
||||
services, err := lister.ListServices(ctx)
|
||||
if err != nil {
|
||||
@@ -456,8 +459,6 @@ func ValidateService(service *api.Service, lister ServiceLister, ctx api.Context
|
||||
}
|
||||
}
|
||||
}
|
||||
allErrs = append(allErrs, validateLabels(service.Labels, "labels")...)
|
||||
allErrs = append(allErrs, validateLabels(service.Spec.Selector, "selector")...)
|
||||
return allErrs
|
||||
}
|
||||
|
||||
|
@@ -710,8 +710,8 @@ func TestValidateService(t *testing.T) {
|
||||
Port: 8675,
|
||||
},
|
||||
},
|
||||
// Should fail because the selector is missing.
|
||||
numErrs: 1,
|
||||
// Should be ok because the selector is missing.
|
||||
numErrs: 0,
|
||||
},
|
||||
{
|
||||
name: "valid 1",
|
||||
@@ -824,12 +824,25 @@ func TestValidateService(t *testing.T) {
|
||||
"NoUppercaseOrSpecialCharsLike=Equals": "bar",
|
||||
},
|
||||
},
|
||||
Spec: api.ServiceSpec{
|
||||
Port: 8675,
|
||||
},
|
||||
},
|
||||
numErrs: 1,
|
||||
},
|
||||
{
|
||||
name: "invalid selector",
|
||||
svc: api.Service{
|
||||
ObjectMeta: api.ObjectMeta{
|
||||
Name: "abc123",
|
||||
Namespace: api.NamespaceDefault,
|
||||
},
|
||||
Spec: api.ServiceSpec{
|
||||
Port: 8675,
|
||||
Selector: map[string]string{"foo": "bar", "NoUppercaseOrSpecialCharsLike=Equals": "bar"},
|
||||
},
|
||||
},
|
||||
numErrs: 2,
|
||||
numErrs: 1,
|
||||
},
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user