This fix is a follow up for comment:
https://github.com/docker/docker/pull/29186/files#r91277345
While #29186 addresses the issue of `docker inspect <unknown object>`
on Windows, it actually makes `docker plugin inspect <unknown object>`
out `object not found` on Windows as well. This is actually misleading
as plugin is not supported on Windows.
This fix reverted the change in #29186 while at the same time,
checks `not supported` in `docker inspect <unknown object>` so that
- `docker plugin inspect <unknown object>` returns `not supported` on Windows
- `docker inspect <unknown object>` returns `not found` on Windows
This fix is related to #29186 and #29185.
Signed-off-by: Yong Tang <yong.tang.github@outlook.com>
| ... | ... |
@@ -2,6 +2,7 @@ package system |
| 2 | 2 |
|
| 3 | 3 |
import ( |
| 4 | 4 |
"fmt" |
| 5 |
+ "strings" |
|
| 5 | 6 |
|
| 6 | 7 |
"golang.org/x/net/context" |
| 7 | 8 |
|
| ... | ... |
@@ -156,6 +157,10 @@ func inspectAll(ctx context.Context, dockerCli *command.DockerCli, getSize bool, |
| 156 | 156 |
return info.Swarm.ControlAvailable |
| 157 | 157 |
} |
| 158 | 158 |
|
| 159 |
+ isErrNotSupported := func(err error) bool {
|
|
| 160 |
+ return strings.Contains(err.Error(), "not supported") |
|
| 161 |
+ } |
|
| 162 |
+ |
|
| 159 | 163 |
return func(ref string) (interface{}, []byte, error) {
|
| 160 | 164 |
const ( |
| 161 | 165 |
swarmSupportUnknown = iota |
| ... | ... |
@@ -183,7 +188,7 @@ func inspectAll(ctx context.Context, dockerCli *command.DockerCli, getSize bool, |
| 183 | 183 |
} |
| 184 | 184 |
v, raw, err := inspectData.objectInspector(ref) |
| 185 | 185 |
if err != nil {
|
| 186 |
- if typeConstraint == "" && apiclient.IsErrNotFound(err) {
|
|
| 186 |
+ if typeConstraint == "" && (apiclient.IsErrNotFound(err) || isErrNotSupported(err)) {
|
|
| 187 | 187 |
continue |
| 188 | 188 |
} |
| 189 | 189 |
return v, raw, err |
| ... | ... |
@@ -251,3 +251,14 @@ func (s *DockerSuite) TestPluginInspect(c *check.C) {
|
| 251 | 251 |
_, _, err = dockerCmdWithError("plugin", "inspect", "-f", "{{.Id}}", id[:5])
|
| 252 | 252 |
c.Assert(err, checker.NotNil) |
| 253 | 253 |
} |
| 254 |
+ |
|
| 255 |
+// Test case for https://github.com/docker/docker/pull/29186#discussion_r91277345 |
|
| 256 |
+func (s *DockerSuite) TestPluginInspectOnWindows(c *check.C) {
|
|
| 257 |
+ // This test should work on Windows only |
|
| 258 |
+ testRequires(c, DaemonIsWindows) |
|
| 259 |
+ |
|
| 260 |
+ out, _, err := dockerCmdWithError("plugin", "inspect", "foobar")
|
|
| 261 |
+ c.Assert(err, checker.NotNil) |
|
| 262 |
+ c.Assert(out, checker.Contains, "plugins are not supported on this platform") |
|
| 263 |
+ c.Assert(err.Error(), checker.Contains, "plugins are not supported on this platform") |
|
| 264 |
+} |
| ... | ... |
@@ -4,7 +4,6 @@ package plugin |
| 4 | 4 |
|
| 5 | 5 |
import ( |
| 6 | 6 |
"errors" |
| 7 |
- "fmt" |
|
| 8 | 7 |
"io" |
| 9 | 8 |
"net/http" |
| 10 | 9 |
|
| ... | ... |
@@ -26,10 +25,7 @@ func (pm *Manager) Enable(name string, config *types.PluginEnableConfig) error {
|
| 26 | 26 |
|
| 27 | 27 |
// Inspect examines a plugin config |
| 28 | 28 |
func (pm *Manager) Inspect(refOrID string) (tp types.Plugin, err error) {
|
| 29 |
- // Even though plugin is not supported, we still want to return `not found` |
|
| 30 |
- // error so that `docker inspect` (without `--type` specified) returns correct |
|
| 31 |
- // `not found` message |
|
| 32 |
- return tp, fmt.Errorf("no such plugin name or ID associated with %q", refOrID)
|
|
| 29 |
+ return tp, errNotSupported |
|
| 33 | 30 |
} |
| 34 | 31 |
|
| 35 | 32 |
// Privileges pulls a plugin config and computes the privileges required to install it. |