Quellcode durchsuchen

libnetwork: Controller.NewSandbox: don't generate ID if not used

Windows uses the container-iD as ID for sandboxes, so it's not needed to
generate an ID  when running on Windows.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Sebastiaan van Stijn vor 1 Jahr
Ursprung
Commit
2eccf0e8d1
1 geänderte Dateien mit 5 neuen und 5 gelöschten Zeilen
  1. 5 5
      libnetwork/controller.go

+ 5 - 5
libnetwork/controller.go

@@ -887,13 +887,13 @@ func (c *Controller) NewSandbox(containerID string, options ...SandboxOption) (_
 	}
 	c.mu.Unlock()
 
-	sandboxID := stringid.GenerateRandomID()
-	if runtime.GOOS == "windows" {
-		sandboxID = containerID
-	}
-
 	// Create sandbox and process options first. Key generation depends on an option
 	if sb == nil {
+		// TODO(thaJeztah): given that a "containerID" must be unique in the list of sandboxes, is there any reason we're not using containerID as sandbox ID on non-Windows?
+		sandboxID := containerID
+		if runtime.GOOS != "windows" {
+			sandboxID = stringid.GenerateRandomID()
+		}
 		sb = &Sandbox{
 			id:                 sandboxID,
 			containerID:        containerID,