Skip to content

Commit

Permalink
Do not error on del command
Browse files Browse the repository at this point in the history
According to the cni spec[1], a plugin should not return an error on
del. If a plugin returns an error cni will not call the following
plugins. Since the plugins are invoked in reverse order on del, the
portmapping and bridge plugins won't get invoked and therefore leave
iptables rules around.

Fixes containers#67
Fixes containers/podman#10806
Fixes containers/podman#10745

[1] https://github.com/containernetworking/cni/blob/master/SPEC.md#del-remove-container-from-network-or-un-apply-modifications

Signed-off-by: Paul Holzinger <[email protected]>
  • Loading branch information
Luap99 committed Aug 11, 2021
1 parent 11e8348 commit 3cf5bbe
Showing 1 changed file with 25 additions and 9 deletions.
34 changes: 25 additions & 9 deletions plugins/meta/dnsname/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,25 +107,30 @@ func cmdAdd(args *skel.CmdArgs) error {

func cmdDel(args *skel.CmdArgs) error {
if err := findDNSMasq(); err != nil {
return ErrBinaryNotFound
logrus.Error(ErrBinaryNotFound)
return nil
}
netConf, result, podname, err := parseConfig(args.StdinData, args.Args)
if err != nil {
return errors.Wrap(err, "failed to parse config")
logrus.Error(errors.Wrap(err, "failed to parse config"))
return nil
} else if result == nil {
return nil
}
dnsNameConf, err := newDNSMasqFile(netConf.DomainName, result.Interfaces[0].Name, netConf.Name)
if err != nil {
return err
logrus.Error(err)
return nil
}
domainBaseDir := filepath.Dir(dnsNameConf.PidFile)
lock, err := getLock(domainBaseDir)
if err != nil {
return err
logrus.Error(err)
return nil
}
if err := lock.acquire(); err != nil {
return err
logrus.Error(err)
return nil
}
defer func() {
// if the lock isn't given up by another process
Expand All @@ -135,20 +140,31 @@ func cmdDel(args *skel.CmdArgs) error {
}()
shouldHUP, err := removeFromFile(filepath.Join(domainBaseDir, hostsFileName), podname)
if err != nil {
return err
logrus.Error(err)
return nil
}
if !shouldHUP {
// if there are no hosts, we should just stop the dnsmasq instance to not take
// system resources
err = dnsNameConf.stop()
if err != nil {
return err
logrus.Error(err)
return nil
}
// remove the config directory
return os.RemoveAll(domainBaseDir)
err = os.RemoveAll(domainBaseDir)
logrus.Error(err)
if err != nil {
logrus.Error(err)
}
return nil
}
// Now we need to HUP
return dnsNameConf.hup()
err = dnsNameConf.hup()
if err != nil {
logrus.Error(err)
}
return nil
}

func main() {
Expand Down

0 comments on commit 3cf5bbe

Please sign in to comment.