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>
This commit is contained in:
Albin Kerouanton 2023-07-08 15:31:27 +02:00
parent 21dcbada2d
commit d29240d9eb
No known key found for this signature in database
GPG key ID: 630B8E1DCBDB1864
2 changed files with 4 additions and 2 deletions

View file

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

View file

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