diff --git a/manager/controlapi/service.go b/manager/controlapi/service.go index 0b5aae8cbda5d..13cfe2ed1dd58 100644 --- a/manager/controlapi/service.go +++ b/manager/controlapi/service.go @@ -182,7 +182,7 @@ func validateServiceSpec(spec *api.ServiceSpec) error { // checkPortConflicts does a best effort to find if the passed in spec has port // conflicts with existing services. -func (s *Server) checkPortConflicts(spec *api.ServiceSpec) error { +func (s *Server) checkPortConflicts(spec *api.ServiceSpec, serviceID string) error { if spec.Endpoint == nil { return nil } @@ -215,6 +215,10 @@ func (s *Server) checkPortConflicts(spec *api.ServiceSpec) error { } for _, service := range services { + // If service ID is the same (and not "") then this is an update + if serviceID != "" && serviceID == service.ID { + continue + } if service.Spec.Endpoint != nil { for _, pc := range service.Spec.Endpoint.Ports { if reqPorts[pcToString(pc)] { @@ -243,7 +247,7 @@ func (s *Server) CreateService(ctx context.Context, request *api.CreateServiceRe return nil, err } - if err := s.checkPortConflicts(request.Spec); err != nil { + if err := s.checkPortConflicts(request.Spec, ""); err != nil { return nil, err } @@ -309,7 +313,7 @@ func (s *Server) UpdateService(ctx context.Context, request *api.UpdateServiceRe } if request.Spec.Endpoint != nil && !reflect.DeepEqual(request.Spec.Endpoint, service.Spec.Endpoint) { - if err := s.checkPortConflicts(request.Spec); err != nil { + if err := s.checkPortConflicts(request.Spec, request.ServiceID); err != nil { return nil, err } }