Pārlūkot izejas kodu

libnet: Return a 403 when overlay network isn't allowed

With this change, the API will now return a 403 instead of a 500 when
trying to create an overlay network on a non-manager node.

Signed-off-by: Albin Kerouanton <albinker@gmail.com>
Albin Kerouanton 2 gadi atpakaļ
vecāks
revīzija
d29240d9eb
2 mainītis faili ar 4 papildinājumiem un 2 dzēšanām
  1. 3 1
      api/swagger.yaml
  2. 1 1
      daemon/network.go

+ 3 - 1
api/swagger.yaml

@@ -9900,7 +9900,9 @@ paths:
               Id: "22be93d5babb089c5aab8dbc369042fad48ff791584ca2da2100db837a1c7c30"
               Warning: ""
         403:
-          description: "operation not supported for pre-defined networks"
+          description: |
+            Forbidden operation. This happens when trying to create a network named after a pre-defined network,
+            or when trying to create an overlay network on a daemon which is not part of a Swarm cluster.
           schema:
             $ref: "#/definitions/ErrorResponse"
         404:

+ 1 - 1
daemon/network.go

@@ -300,7 +300,7 @@ func (daemon *Daemon) createNetwork(cfg *config.Config, create types.NetworkCrea
 	}
 
 	if driver == "overlay" && !daemon.cluster.IsManager() && !agent {
-		return nil, errors.New(`This node is not a swarm manager. Use "docker swarm init" or "docker swarm join" to connect this node to swarm and try again.`)
+		return nil, errdefs.Forbidden(errors.New(`This node is not a swarm manager. Use "docker swarm init" or "docker swarm join" to connect this node to swarm and try again.`))
 	}
 
 	var warning string