فهرست منبع

Merge pull request #45429 from thaJeztah/libnetwork_cleanup_buildtags_and_stubs

libnetwork: remove redundant init(), remove dead code, and fix stubs / build-tags
Sebastiaan van Stijn 2 سال پیش
والد
کامیت
7d7749ee47

+ 2 - 6
libnetwork/drivers/overlay/overlayutils/utils.go

@@ -8,14 +8,10 @@ import (
 
 var (
 	mutex        sync.RWMutex
-	vxlanUDPPort uint32
+	vxlanUDPPort = defaultVXLANUDPPort
 )
 
-const defaultVXLANUDPPort = 4789
-
-func init() {
-	vxlanUDPPort = defaultVXLANUDPPort
-}
+const defaultVXLANUDPPort uint32 = 4789
 
 // ConfigVXLANUDPPort configures the VXLAN UDP port (data path port) number.
 // If no port is set, the default (4789) is returned. Valid port numbers are

+ 8 - 0
libnetwork/drivers_unsupported.go

@@ -0,0 +1,8 @@
+//go:build !freebsd && !linux && !windows
+// +build !freebsd,!linux,!windows
+
+package libnetwork
+
+func getInitializers() []initializer {
+	return nil
+}

+ 0 - 4
libnetwork/osl/interface_freebsd.go

@@ -1,4 +0,0 @@
-package osl
-
-// IfaceOption is a function option type to set interface options
-type IfaceOption func()

+ 0 - 3
libnetwork/osl/interface_linux.go

@@ -14,9 +14,6 @@ import (
 	"github.com/vishvananda/netns"
 )
 
-// IfaceOption is a function option type to set interface options
-type IfaceOption func(i *nwIface)
-
 type nwIface struct {
 	srcName     string
 	dstName     string

+ 6 - 0
libnetwork/osl/interface_unsupported.go

@@ -0,0 +1,6 @@
+//go:build !linux
+// +build !linux
+
+package osl
+
+type nwIface struct{}

+ 0 - 4
libnetwork/osl/interface_windows.go

@@ -1,4 +0,0 @@
-package osl
-
-// IfaceOption is a function option type to set interface options
-type IfaceOption func()

+ 6 - 6
libnetwork/osl/namespace_linux.go

@@ -600,29 +600,29 @@ func (n *networkNamespace) checkLoV6() {
 }
 
 func setIPv6(nspath, iface string, enable bool) error {
-	origns, err := netns.Get()
+	origNS, err := netns.Get()
 	if err != nil {
 		return fmt.Errorf("failed to get current network namespace: %w", err)
 	}
-	defer origns.Close()
+	defer origNS.Close()
 
-	ns, err := netns.GetFromPath(nspath)
+	namespace, err := netns.GetFromPath(nspath)
 	if err != nil {
 		return fmt.Errorf("failed get network namespace %q: %w", nspath, err)
 	}
-	defer ns.Close()
+	defer namespace.Close()
 
 	errCh := make(chan error, 1)
 	go func() {
 		defer close(errCh)
 
 		runtime.LockOSThread()
-		if err = netns.Set(ns); err != nil {
+		if err = netns.Set(namespace); err != nil {
 			errCh <- fmt.Errorf("setting into container netns %q failed: %w", nspath, err)
 			return
 		}
 		defer func() {
-			if err := netns.Set(origns); err != nil {
+			if err := netns.Set(origNS); err != nil {
 				logrus.WithError(err).Error("libnetwork: restoring thread network namespace failed")
 				// The error is only fatal for the current thread. Keep this
 				// goroutine locked to the thread to make the runtime replace it

+ 0 - 4
libnetwork/osl/neigh_freebsd.go

@@ -1,4 +0,0 @@
-package osl
-
-// NeighOption is a function option type to set neighbor options
-type NeighOption func()

+ 0 - 3
libnetwork/osl/neigh_linux.go

@@ -20,9 +20,6 @@ func (n NeighborSearchError) Error() string {
 	return fmt.Sprintf("Search neighbor failed for IP %v, mac %v, present in db:%t", n.ip, n.mac, n.present)
 }
 
-// NeighOption is a function option type to set interface options
-type NeighOption func(nh *neigh)
-
 type neigh struct {
 	dstIP    net.IP
 	dstMac   net.HardwareAddr

+ 6 - 0
libnetwork/osl/neigh_unsupported.go

@@ -0,0 +1,6 @@
+//go:build !linux
+// +build !linux
+
+package osl
+
+type neigh struct{}

+ 0 - 4
libnetwork/osl/neigh_windows.go

@@ -1,4 +0,0 @@
-package osl
-
-// NeighOption is a function option type to set neighbor options
-type NeighOption func()

+ 6 - 0
libnetwork/osl/sandbox.go

@@ -17,6 +17,12 @@ const (
 	SandboxTypeLoadBalancer = iota
 )
 
+// IfaceOption is a function option type to set interface options.
+type IfaceOption func(i *nwIface)
+
+// NeighOption is a function option type to set neighbor options.
+type NeighOption func(nh *neigh)
+
 // Sandbox represents a network sandbox, identified by a specific key.  It
 // holds a list of Interfaces, routes etc, and more can be added dynamically.
 type Sandbox interface {

+ 8 - 9
libnetwork/service_unsupported.go

@@ -4,23 +4,22 @@
 package libnetwork
 
 import (
-	"fmt"
+	"errors"
 	"net"
 )
 
-func (c *Controller) cleanupServiceBindings(nid string) {
-}
+func (c *Controller) cleanupServiceDiscovery(cleanupNID string) {}
+
+func (c *Controller) cleanupServiceBindings(nid string) {}
 
 func (c *Controller) addServiceBinding(name, sid, nid, eid string, vip net.IP, ingressPorts []*PortConfig, aliases []string, ip net.IP) error {
-	return fmt.Errorf("not supported")
+	return errors.New("not supported")
 }
 
 func (c *Controller) rmServiceBinding(name, sid, nid, eid string, vip net.IP, ingressPorts []*PortConfig, aliases []string, ip net.IP) error {
-	return fmt.Errorf("not supported")
+	return errors.New("not supported")
 }
 
-func (sb *sandbox) populateLoadBalancers(ep *endpoint) {
-}
+func (sb *Sandbox) populateLoadBalancers(*Endpoint) {}
 
-func arrangeIngressFilterRule() {
-}
+func arrangeIngressFilterRule() {}