Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

service: simplify DeleteVolumes() #881

Merged
merged 4 commits into from
Apr 17, 2019
Merged
Changes from 1 commit
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
45 changes: 13 additions & 32 deletions service/volume.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,39 +13,20 @@ func (s *Service) DeleteVolumes(c container.Container) error {
wg sync.WaitGroup
errs xerrors.SyncErrors
)
delete := func(d *Dependency) {
defer wg.Done()
if err := d.DeleteVolumes(c, s); err != nil {
errs.Append(err)
for _, d := range append(s.Dependencies, s.Configuration) {
// Service.Configuration can be nil so, here is a check for it.
if d == nil {
continue
}
for _, volume := range d.extractVolumes(s) {
wg.Add(1)
go func(source string) {
defer wg.Done()
if err := c.DeleteVolume(source); err != nil {
errs.Append(err)
}
}(volume.Source)
}
}
for _, d := range s.Dependencies {
wg.Add(1)
go delete(d)
}
if s.Configuration != nil {
wg.Add(1)
go delete(s.Configuration)
}
wg.Wait()
return errs.ErrorOrNil()
}

// DeleteVolumes deletes the data volumes of service's dependency.
func (d *Dependency) DeleteVolumes(c container.Container, s *Service) error {
volumes := d.extractVolumes(s)
var (
wg sync.WaitGroup
errs xerrors.SyncErrors
)
for _, mount := range volumes {
wg.Add(1)
go func(mount container.Mount) {
defer wg.Done()
if err := c.DeleteVolume(mount.Source); err != nil {
errs.Append(err)
}
}(mount)
}
wg.Wait()
return errs.ErrorOrNil()
Expand Down