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

[skip ci] Remove dangling container during network rm #6190

Closed
wants to merge 2 commits into from
Closed
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
12 changes: 12 additions & 0 deletions lib/portlayer/network/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -1269,6 +1269,18 @@ func (c *Context) DeleteScope(ctx context.Context, name string) error {
return fmt.Errorf("cannot remove builtin scope")
}

// remove dangling endpoints
if exec.Containers != nil {
for _, eps := range s.Endpoints() {
if exec.Containers.Container(eps.ID().String()) == nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

small nit: instead of calling eps.ID().String() 3 times here you could assign it a variable once and then just use that variable instead :) will make the code a little more friendly to read.

log.Debugf("Remove dangling endpoint (%s)", eps.ID().String())
if err = s.RemoveContainer(eps.Container()); err != nil {
return fmt.Errorf("failed to remove dangling endpoint (%s): %s", eps.ID().String(), err.Error())
}
}
}
}

if len(s.Endpoints()) != 0 {
return fmt.Errorf("%s has active endpoints", s.Name())
}
Expand Down