浏览代码

Merge pull request #46546 from thaJeztah/libnetwork_return_errs

libnetwork: Controller.cleanupLocalEndpoints, sandboxCleanup: return errors
Sebastiaan van Stijn 1 年之前
父节点
当前提交
605c8fb75d
共有 3 个文件被更改,包括 17 次插入11 次删除
  1. 6 2
      libnetwork/controller.go
  2. 4 3
      libnetwork/endpoint.go
  3. 7 6
      libnetwork/sandbox_store.go

+ 6 - 2
libnetwork/controller.go

@@ -155,8 +155,12 @@ func New(cfgOptions ...config.Option) (*Controller, error) {
 	c.reservePools()
 	c.reservePools()
 
 
 	// Cleanup resources
 	// Cleanup resources
-	c.sandboxCleanup(c.cfg.ActiveSandboxes)
-	c.cleanupLocalEndpoints()
+	if err := c.sandboxCleanup(c.cfg.ActiveSandboxes); err != nil {
+		log.G(context.TODO()).WithError(err).Error("error during sandbox cleanup")
+	}
+	if err := c.cleanupLocalEndpoints(); err != nil {
+		log.G(context.TODO()).WithError(err).Warnf("error during endpoint cleanup")
+	}
 	c.networkCleanup()
 	c.networkCleanup()
 
 
 	if err := c.startExternalKeyListener(); err != nil {
 	if err := c.startExternalKeyListener(); err != nil {

+ 4 - 3
libnetwork/endpoint.go

@@ -1144,7 +1144,7 @@ func (ep *Endpoint) releaseAddress() {
 	}
 	}
 }
 }
 
 
-func (c *Controller) cleanupLocalEndpoints() {
+func (c *Controller) cleanupLocalEndpoints() error {
 	// Get used endpoints
 	// Get used endpoints
 	eps := make(map[string]interface{})
 	eps := make(map[string]interface{})
 	for _, sb := range c.sandboxes {
 	for _, sb := range c.sandboxes {
@@ -1154,8 +1154,7 @@ func (c *Controller) cleanupLocalEndpoints() {
 	}
 	}
 	nl, err := c.getNetworks()
 	nl, err := c.getNetworks()
 	if err != nil {
 	if err != nil {
-		log.G(context.TODO()).Warnf("Could not get list of networks during endpoint cleanup: %v", err)
-		return
+		return fmt.Errorf("could not get list of networks: %v", err)
 	}
 	}
 
 
 	for _, n := range nl {
 	for _, n := range nl {
@@ -1192,4 +1191,6 @@ func (c *Controller) cleanupLocalEndpoints() {
 			}
 			}
 		}
 		}
 	}
 	}
+
+	return nil
 }
 }

+ 7 - 6
libnetwork/sandbox_store.go

@@ -3,6 +3,7 @@ package libnetwork
 import (
 import (
 	"context"
 	"context"
 	"encoding/json"
 	"encoding/json"
+	"fmt"
 	"sync"
 	"sync"
 
 
 	"github.com/containerd/containerd/log"
 	"github.com/containerd/containerd/log"
@@ -171,21 +172,19 @@ func (sb *Sandbox) storeDelete() error {
 	})
 	})
 }
 }
 
 
-func (c *Controller) sandboxCleanup(activeSandboxes map[string]interface{}) {
+func (c *Controller) sandboxCleanup(activeSandboxes map[string]interface{}) error {
 	store := c.getStore()
 	store := c.getStore()
 	if store == nil {
 	if store == nil {
-		log.G(context.TODO()).Error("Could not find local scope store while trying to cleanup sandboxes")
-		return
+		return fmt.Errorf("could not find local scope store")
 	}
 	}
 
 
 	sandboxStates, err := store.List(datastore.Key(sandboxPrefix), &sbState{c: c})
 	sandboxStates, err := store.List(datastore.Key(sandboxPrefix), &sbState{c: c})
 	if err != nil {
 	if err != nil {
 		if err == datastore.ErrKeyNotFound {
 		if err == datastore.ErrKeyNotFound {
 			// It's normal for no sandboxes to be found. Just bail out.
 			// It's normal for no sandboxes to be found. Just bail out.
-			return
+			return nil
 		}
 		}
-		log.G(context.TODO()).Errorf("failed to get sandboxes for scope %s: %v", store.Scope(), err)
-		return
+		return fmt.Errorf("failed to get sandboxes for scope %s: %v", store.Scope(), err)
 	}
 	}
 
 
 	for _, s := range sandboxStates {
 	for _, s := range sandboxStates {
@@ -285,4 +284,6 @@ func (c *Controller) sandboxCleanup(activeSandboxes map[string]interface{}) {
 			}
 			}
 		}
 		}
 	}
 	}
+
+	return nil
 }
 }