mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Fix docker plugin inspect <unkown object>
issue on Windows
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>
This commit is contained in:
parent
fb41283e49
commit
0b3c10ac4d
3 changed files with 18 additions and 6 deletions
|
@ -2,6 +2,7 @@ package system
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"golang.org/x/net/context"
|
"golang.org/x/net/context"
|
||||||
|
|
||||||
|
@ -156,6 +157,10 @@ func inspectAll(ctx context.Context, dockerCli *command.DockerCli, getSize bool,
|
||||||
return info.Swarm.ControlAvailable
|
return info.Swarm.ControlAvailable
|
||||||
}
|
}
|
||||||
|
|
||||||
|
isErrNotSupported := func(err error) bool {
|
||||||
|
return strings.Contains(err.Error(), "not supported")
|
||||||
|
}
|
||||||
|
|
||||||
return func(ref string) (interface{}, []byte, error) {
|
return func(ref string) (interface{}, []byte, error) {
|
||||||
const (
|
const (
|
||||||
swarmSupportUnknown = iota
|
swarmSupportUnknown = iota
|
||||||
|
@ -183,7 +188,7 @@ func inspectAll(ctx context.Context, dockerCli *command.DockerCli, getSize bool,
|
||||||
}
|
}
|
||||||
v, raw, err := inspectData.objectInspector(ref)
|
v, raw, err := inspectData.objectInspector(ref)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if typeConstraint == "" && apiclient.IsErrNotFound(err) {
|
if typeConstraint == "" && (apiclient.IsErrNotFound(err) || isErrNotSupported(err)) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
return v, raw, err
|
return v, raw, err
|
||||||
|
|
|
@ -251,3 +251,14 @@ func (s *DockerSuite) TestPluginInspect(c *check.C) {
|
||||||
_, _, err = dockerCmdWithError("plugin", "inspect", "-f", "{{.Id}}", id[:5])
|
_, _, err = dockerCmdWithError("plugin", "inspect", "-f", "{{.Id}}", id[:5])
|
||||||
c.Assert(err, checker.NotNil)
|
c.Assert(err, checker.NotNil)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Test case for https://github.com/docker/docker/pull/29186#discussion_r91277345
|
||||||
|
func (s *DockerSuite) TestPluginInspectOnWindows(c *check.C) {
|
||||||
|
// This test should work on Windows only
|
||||||
|
testRequires(c, DaemonIsWindows)
|
||||||
|
|
||||||
|
out, _, err := dockerCmdWithError("plugin", "inspect", "foobar")
|
||||||
|
c.Assert(err, checker.NotNil)
|
||||||
|
c.Assert(out, checker.Contains, "plugins are not supported on this platform")
|
||||||
|
c.Assert(err.Error(), checker.Contains, "plugins are not supported on this platform")
|
||||||
|
}
|
||||||
|
|
|
@ -4,7 +4,6 @@ package plugin
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
|
@ -26,10 +25,7 @@ func (pm *Manager) Enable(name string, config *types.PluginEnableConfig) error {
|
||||||
|
|
||||||
// Inspect examines a plugin config
|
// Inspect examines a plugin config
|
||||||
func (pm *Manager) Inspect(refOrID string) (tp types.Plugin, err error) {
|
func (pm *Manager) Inspect(refOrID string) (tp types.Plugin, err error) {
|
||||||
// Even though plugin is not supported, we still want to return `not found`
|
return tp, errNotSupported
|
||||||
// error so that `docker inspect` (without `--type` specified) returns correct
|
|
||||||
// `not found` message
|
|
||||||
return tp, fmt.Errorf("no such plugin name or ID associated with %q", refOrID)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Privileges pulls a plugin config and computes the privileges required to install it.
|
// Privileges pulls a plugin config and computes the privileges required to install it.
|
||||||
|
|
Loading…
Reference in a new issue