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>
This commit is contained in:
Sebastiaan van Stijn 2023-08-12 14:29:33 +02:00
parent 389b21a341
commit 2eccf0e8d1
No known key found for this signature in database
GPG key ID: 76698F39D527CE8C

View file

@ -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,