Browse Source

better diagnostic message on network label mismatch

Signed-off-by: Nicolas De Loof <[email protected]>
Nicolas De Loof 2 years ago
parent
commit
629c9f62e9
1 changed files with 5 additions and 1 deletions
  1. 5 1
      pkg/compose/create.go

+ 5 - 1
pkg/compose/create.go

@@ -1034,9 +1034,13 @@ func (s *composeService) resolveOrCreateNetwork(ctx context.Context, n *types.Ne
 		// NetworkInspect will match on ID prefix, so double check we get the expected one
 		// as looking for network named `db` we could erroneously matched network ID `db9086999caf`
 		if inspect.Name == n.Name || inspect.ID == n.Name {
-			if inspect.Labels[api.ProjectLabel] != expectedProjectLabel {
+			p, ok := inspect.Labels[api.ProjectLabel]
+			if !ok {
 				logrus.Warnf("a network with name %s exists but was not created by compose.\n"+
 					"Set `external: true` to use an existing network", n.Name)
+			} else if p != expectedProjectLabel {
+				logrus.Warnf("a network with name %s exists but was not created for project %q.\n"+
+					"Set `external: true` to use an existing network", n.Name, expectedProjectLabel)
 			}
 			if inspect.Labels[api.NetworkLabel] != expectedNetworkLabel {
 				return fmt.Errorf("network %s was found but has incorrect label %s set to %q", n.Name, api.NetworkLabel, inspect.Labels[api.NetworkLabel])