From 241f3d702bac8178863ee4e105db60df85c38fe9 Mon Sep 17 00:00:00 2001 From: Deyuan Deng Date: Sat, 15 Nov 2014 10:40:40 -0500 Subject: [PATCH] Exclude service itself when checking conflict. --- pkg/api/validation/validation.go | 4 +++- pkg/registry/service/rest.go | 1 - pkg/registry/service/rest_test.go | 8 ++++++++ 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/pkg/api/validation/validation.go b/pkg/api/validation/validation.go index 6b747a6cdd3..21eba4ad026 100644 --- a/pkg/api/validation/validation.go +++ b/pkg/api/validation/validation.go @@ -431,7 +431,9 @@ func ValidateService(service *api.Service, lister ServiceLister, ctx api.Context allErrs = append(allErrs, errs.NewInternalError(err)) } else { 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))) break } diff --git a/pkg/registry/service/rest.go b/pkg/registry/service/rest.go index b85123e3ac9..de99daf8fcd 100644 --- a/pkg/registry/service/rest.go +++ b/pkg/registry/service/rest.go @@ -82,7 +82,6 @@ func reloadIPsFromStorage(ipa *ipAllocator, registry Registry) { } func (rs *REST) Create(ctx api.Context, obj runtime.Object) (<-chan apiserver.RESTResult, error) { - service := obj.(*api.Service) if !api.ValidNamespace(ctx, &service.ObjectMeta) { return nil, errors.NewConflict("service", service.Namespace, fmt.Errorf("Service.Namespace does not match the provided context")) diff --git a/pkg/registry/service/rest_test.go b/pkg/registry/service/rest_test.go index b970c58b26b..7a628b23dbc 100644 --- a/pkg/registry/service/rest_test.go +++ b/pkg/registry/service/rest_test.go @@ -641,6 +641,14 @@ func TestServiceRegistryIPExternalLoadBalancer(t *testing.T) { if created_service.Spec.ProxyPort != 6502 { 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) {