Parcourir la source

libnetwork/iptables: ProgramChain: don't fail if interface not found

DelInterfaceFirewalld returns an error if the interface to delete was
not found. Let's ignore cases where we were successfully able to get
the list of interfaces in the zone, but the interface was not part of
the zone.

This patch changes the error for these cases to an errdefs.ErrNotFound,
and updates IPTable.ProgramChain to ignore those errors.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Sebastiaan van Stijn il y a 1 an
Parent
commit
513063bcf9
2 fichiers modifiés avec 7 ajouts et 2 suppressions
  1. 5 1
      libnetwork/iptables/firewalld.go
  2. 2 1
      libnetwork/iptables/iptables.go

+ 5 - 1
libnetwork/iptables/firewalld.go

@@ -271,7 +271,7 @@ func DelInterfaceFirewalld(intf string) error {
 	}
 	}
 	// Remove interface if it exists
 	// Remove interface if it exists
 	if !contains(intfs, intf) {
 	if !contains(intfs, intf) {
-		return fmt.Errorf("Firewalld: unable to find interface %s in %s zone", intf, dockerZone)
+		return &interfaceNotFound{fmt.Errorf("firewalld: interface %q not found in %s zone", intf, dockerZone)}
 	}
 	}
 
 
 	log.G(context.TODO()).Debugf("Firewalld: removing %s interface from %s zone", intf, dockerZone)
 	log.G(context.TODO()).Debugf("Firewalld: removing %s interface from %s zone", intf, dockerZone)
@@ -282,6 +282,10 @@ func DelInterfaceFirewalld(intf string) error {
 	return nil
 	return nil
 }
 }
 
 
+type interfaceNotFound struct{ error }
+
+func (interfaceNotFound) NotFound() {}
+
 func contains(list []string, val string) bool {
 func contains(list []string, val string) bool {
 	for _, v := range list {
 	for _, v := range list {
 		if v == val {
 		if v == val {

+ 2 - 1
libnetwork/iptables/iptables.go

@@ -15,6 +15,7 @@ import (
 	"time"
 	"time"
 
 
 	"github.com/containerd/containerd/log"
 	"github.com/containerd/containerd/log"
+	"github.com/docker/docker/errdefs"
 	"github.com/docker/docker/pkg/rootless"
 	"github.com/docker/docker/pkg/rootless"
 )
 )
 
 
@@ -209,7 +210,7 @@ func (iptable IPTable) ProgramChain(c *ChainInfo, bridgeName string, hairpinMode
 				return err
 				return err
 			}
 			}
 		} else {
 		} else {
-			if err := DelInterfaceFirewalld(bridgeName); err != nil {
+			if err := DelInterfaceFirewalld(bridgeName); err != nil && !errdefs.IsNotFound(err) {
 				return err
 				return err
 			}
 			}
 		}
 		}