Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 17 additions & 12 deletions endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -311,16 +311,25 @@ func (ep *endpoint) isAnonymous() bool {
return ep.anonymous
}

// enableService sets ep's serviceEnabled to the passed value if it's not in the
// current state and returns true; false otherwise.
func (ep *endpoint) enableService(state bool) bool {
// isServiceEnabled check if service is enabled on the endpoint
func (ep *endpoint) isServiceEnabled() bool {
ep.Lock()
defer ep.Unlock()
if ep.serviceEnabled != state {
ep.serviceEnabled = state
return true
}
return false
return ep.serviceEnabled
}

// enableService sets service enabled on the endpoint
func (ep *endpoint) enableService() {
ep.Lock()
defer ep.Unlock()
ep.serviceEnabled = true
}

// disableService disables service on the endpoint
func (ep *endpoint) disableService() {
ep.Lock()
defer ep.Unlock()
ep.serviceEnabled = false
}

func (ep *endpoint) needResolver() bool {
Expand Down Expand Up @@ -759,10 +768,6 @@ func (ep *endpoint) sbLeave(sb *sandbox, force bool, options ...EndpointOption)
return err
}

if e := ep.deleteServiceInfoFromCluster(sb, "sbLeave"); e != nil {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

without this one will it still work the network disconnect?

Copy link
Contributor Author

@abhi abhi Jan 9, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

check the corresponding moby/moby#35960 PR for this

logrus.Errorf("Could not delete service state for endpoint %s from cluster: %v", ep.Name(), e)
}

if e := ep.deleteDriverInfoFromCluster(); e != nil {
logrus.Errorf("Could not delete endpoint state for endpoint %s from cluster: %v", ep.Name(), e)
}
Expand Down
27 changes: 22 additions & 5 deletions sandbox.go
Original file line number Diff line number Diff line change
Expand Up @@ -674,24 +674,41 @@ func (sb *sandbox) SetKey(basePath string) error {
return nil
}

func (sb *sandbox) EnableService() error {
func (sb *sandbox) EnableService() (err error) {
logrus.Debugf("EnableService %s START", sb.containerID)
defer func() {
if err != nil {
sb.DisableService()
}
}()
for _, ep := range sb.getConnectedEndpoints() {
if ep.enableService(true) {
if !ep.isServiceEnabled() {
if err := ep.addServiceInfoToCluster(sb); err != nil {
ep.enableService(false)
return fmt.Errorf("could not update state for endpoint %s into cluster: %v", ep.Name(), err)
}
ep.enableService()
}
}
logrus.Debugf("EnableService %s DONE", sb.containerID)
return nil
}

func (sb *sandbox) DisableService() error {
func (sb *sandbox) DisableService() (err error) {
logrus.Debugf("DisableService %s START", sb.containerID)
failedEps := []string{}
defer func() {
if len(failedEps) > 0 {
err = fmt.Errorf("failed to disable service on sandbox:%s, for endpoints %s", sb.ID(), strings.Join(failedEps, ","))
}
}()
for _, ep := range sb.getConnectedEndpoints() {
ep.enableService(false)
if ep.isServiceEnabled() {
if err := ep.deleteServiceInfoFromCluster(sb, "DisableService"); err != nil {
failedEps = append(failedEps, ep.Name())
logrus.Warnf("failed update state for endpoint %s into cluster: %v", ep.Name(), err)
}
ep.disableService()
}
}
logrus.Debugf("DisableService %s DONE", sb.containerID)
return nil
Expand Down