瀏覽代碼

Merge pull request #46245 from thaJeztah/firewalld_dont_fail_on_removal

libnetwork/iptables: ProgramChain: don't fail if interface not found
Sebastiaan van Stijn 1 年之前
父節點
當前提交
0e3b2ec267
共有 2 個文件被更改,包括 7 次插入2 次删除
  1. 5 1
      libnetwork/iptables/firewalld.go
  2. 2 1
      libnetwork/iptables/iptables.go

+ 5 - 1
libnetwork/iptables/firewalld.go

@@ -273,7 +273,7 @@ func DelInterfaceFirewalld(intf string) error {
 	}
 	// Remove interface if it exists
 	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)
@@ -284,6 +284,10 @@ func DelInterfaceFirewalld(intf string) error {
 	return nil
 }
 
+type interfaceNotFound struct{ error }
+
+func (interfaceNotFound) NotFound() {}
+
 func contains(list []string, val string) bool {
 	for _, v := range list {
 		if v == val {

+ 2 - 1
libnetwork/iptables/iptables.go

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