Skip to content

Commit

Permalink
[v0.60] rootlessnetns: make cleanup idempotent
Browse files Browse the repository at this point in the history
Signed-off-by: Paul Holzinger <[email protected]>
Signed-off-by: tomsweeneyredhat <[email protected]>
  • Loading branch information
Luap99 authored and TomSweeneyRedHat committed Aug 9, 2024
1 parent e1bec87 commit 5fd0ba2
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion libnetwork/internal/rootlessnetns/netns_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ func (n *Netns) cleanup() error {
if err := n.cleanupRootlessNetns(); err != nil {
multiErr = multierror.Append(multiErr, wrapError("kill network process", err))
}
if err := os.RemoveAll(n.dir); err != nil {
if err := os.RemoveAll(n.dir); err != nil && !errors.Is(err, fs.ErrNotExist) {
multiErr = multierror.Append(multiErr, wrapError("remove rootless netns dir", err))
}

Expand Down Expand Up @@ -280,6 +280,11 @@ func (n *Netns) setupSlirp4netns(nsPath string) error {
func (n *Netns) cleanupRootlessNetns() error {
pidFile := n.getPath(rootlessNetNsConnPidFile)
pid, err := readPidFile(pidFile)
// do not hard error if the file dos not exists, cleanup should be idempotent
if errors.Is(err, fs.ErrNotExist) {
logrus.Debugf("Rootless netns conn pid file does not exists %s", pidFile)
return nil
}
if err == nil {
// kill the slirp/pasta process so we do not leak it
err = unix.Kill(pid, unix.SIGTERM)
Expand Down

0 comments on commit 5fd0ba2

Please sign in to comment.