Exclude service itself when checking conflict.

pull/6/head
Deyuan Deng 2014-11-15 10:40:40 -05:00
parent 29b73cc4b5
commit 241f3d702b
3 changed files with 11 additions and 2 deletions

View File

@ -431,7 +431,9 @@ func ValidateService(service *api.Service, lister ServiceLister, ctx api.Context
allErrs = append(allErrs, errs.NewInternalError(err)) allErrs = append(allErrs, errs.NewInternalError(err))
} else { } else {
for i := range services.Items { for i := range services.Items {
if services.Items[i].Spec.CreateExternalLoadBalancer && services.Items[i].Spec.Port == service.Spec.Port { if services.Items[i].Name != service.Name &&
services.Items[i].Spec.CreateExternalLoadBalancer &&
services.Items[i].Spec.Port == service.Spec.Port {
allErrs = append(allErrs, errs.NewConflict("service", service.Name, fmt.Errorf("Port: %d is already in use", service.Spec.Port))) allErrs = append(allErrs, errs.NewConflict("service", service.Name, fmt.Errorf("Port: %d is already in use", service.Spec.Port)))
break break
} }

View File

@ -82,7 +82,6 @@ func reloadIPsFromStorage(ipa *ipAllocator, registry Registry) {
} }
func (rs *REST) Create(ctx api.Context, obj runtime.Object) (<-chan apiserver.RESTResult, error) { func (rs *REST) Create(ctx api.Context, obj runtime.Object) (<-chan apiserver.RESTResult, error) {
service := obj.(*api.Service) service := obj.(*api.Service)
if !api.ValidNamespace(ctx, &service.ObjectMeta) { if !api.ValidNamespace(ctx, &service.ObjectMeta) {
return nil, errors.NewConflict("service", service.Namespace, fmt.Errorf("Service.Namespace does not match the provided context")) return nil, errors.NewConflict("service", service.Namespace, fmt.Errorf("Service.Namespace does not match the provided context"))

View File

@ -641,6 +641,14 @@ func TestServiceRegistryIPExternalLoadBalancer(t *testing.T) {
if created_service.Spec.ProxyPort != 6502 { if created_service.Spec.ProxyPort != 6502 {
t.Errorf("Unexpected ProxyPort: %d", created_service.Spec.ProxyPort) t.Errorf("Unexpected ProxyPort: %d", created_service.Spec.ProxyPort)
} }
update := new(api.Service)
*update = *created_service
_, err := rest.Update(ctx, update)
if err != nil {
t.Errorf("Unexpected error %v", err)
}
} }
func TestServiceRegistryIPReloadFromStorage(t *testing.T) { func TestServiceRegistryIPReloadFromStorage(t *testing.T) {