Skip to content

Commit

Permalink
Merge pull request moby#1349 from yongtang/25375-service-update-publi…
Browse files Browse the repository at this point in the history
…sh-add

Skip same service PortConfig check to allow PortConfig updating
  • Loading branch information
mrjana authored Aug 10, 2016
2 parents ad6fb9e + aaf1efb commit cb6d813
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions manager/controlapi/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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)] {
Expand Down Expand Up @@ -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
}

Expand Down Expand Up @@ -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
}
}
Expand Down

0 comments on commit cb6d813

Please sign in to comment.