This fix adds `--filter capability=[volumedriver|authz]` to `docker plugin ls`.
The related docs has been updated.
An integration test has been added.
Signed-off-by: Yong Tang <yong.tang.github@outlook.com>
| ... | ... |
@@ -31,6 +31,10 @@ func TestPluginList(t *testing.T) {
|
| 31 | 31 |
enabledFilters := filters.NewArgs() |
| 32 | 32 |
enabledFilters.Add("enabled", "true")
|
| 33 | 33 |
|
| 34 |
+ capabilityFilters := filters.NewArgs() |
|
| 35 |
+ capabilityFilters.Add("capability", "volumedriver")
|
|
| 36 |
+ capabilityFilters.Add("capability", "authz")
|
|
| 37 |
+ |
|
| 34 | 38 |
listCases := []struct {
|
| 35 | 39 |
filters filters.Args |
| 36 | 40 |
expectedQueryParams map[string]string |
| ... | ... |
@@ -51,6 +55,14 @@ func TestPluginList(t *testing.T) {
|
| 51 | 51 |
"filters": `{"enabled":{"true":true}}`,
|
| 52 | 52 |
}, |
| 53 | 53 |
}, |
| 54 |
+ {
|
|
| 55 |
+ filters: capabilityFilters, |
|
| 56 |
+ expectedQueryParams: map[string]string{
|
|
| 57 |
+ "all": "", |
|
| 58 |
+ "filter": "", |
|
| 59 |
+ "filters": `{"capability":{"authz":true,"volumedriver":true}}`,
|
|
| 60 |
+ }, |
|
| 61 |
+ }, |
|
| 54 | 62 |
} |
| 55 | 63 |
|
| 56 | 64 |
for _, listCase := range listCases {
|
| ... | ... |
@@ -51,9 +51,13 @@ Config provides the base accessible fields for working with V0 plugin format |
| 51 | 51 |
|
| 52 | 52 |
currently supported: |
| 53 | 53 |
|
| 54 |
- - **docker.volumedriver/1.0** |
|
| 54 |
+ - **docker.volumedriver/1.0** |
|
| 55 | 55 |
|
| 56 |
- - **docker.authz/1.0** |
|
| 56 |
+ - **docker.networkdriver/1.0** |
|
| 57 |
+ |
|
| 58 |
+ - **docker.ipamdriver/1.0** |
|
| 59 |
+ |
|
| 60 |
+ - **docker.authz/1.0** |
|
| 57 | 61 |
|
| 58 | 62 |
- **`socket`** *string* |
| 59 | 63 |
|
| ... | ... |
@@ -53,11 +53,26 @@ than one filter, then pass multiple flags (e.g., `--filter "foo=bar" --filter "b |
| 53 | 53 |
The currently supported filters are: |
| 54 | 54 |
|
| 55 | 55 |
* enabled (boolean - true or false, 0 or 1) |
| 56 |
+* capability (string - currently `volumedriver`, `networkdriver`, `ipamdriver`, or `authz`) |
|
| 56 | 57 |
|
| 57 | 58 |
### enabled |
| 58 | 59 |
|
| 59 | 60 |
The `enabled` filter matches on plugins enabled or disabled. |
| 60 | 61 |
|
| 62 |
+### capability |
|
| 63 |
+ |
|
| 64 |
+The `capability` filter matches on plugin capabilities. One plugin |
|
| 65 |
+might have multiple capabilities. Currently `volumedriver`, `networkdriver`, |
|
| 66 |
+`ipamdriver`, and `authz` are supported capabilities. |
|
| 67 |
+ |
|
| 68 |
+```bash |
|
| 69 |
+$ docker plugin install --disable tiborvass/no-remove |
|
| 70 |
+tiborvass/no-remove |
|
| 71 |
+ |
|
| 72 |
+$ docker plugin ls --filter enabled=true |
|
| 73 |
+NAME TAG DESCRIPTION ENABLED |
|
| 74 |
+``` |
|
| 75 |
+ |
|
| 61 | 76 |
|
| 62 | 77 |
## Formatting |
| 63 | 78 |
|
| ... | ... |
@@ -313,3 +313,30 @@ func (s *DockerDaemonSuite) TestPluginListFilterEnabled(c *check.C) {
|
| 313 | 313 |
c.Assert(err, checker.IsNil) |
| 314 | 314 |
c.Assert(out, checker.Contains, pName) |
| 315 | 315 |
} |
| 316 |
+ |
|
| 317 |
+func (s *DockerDaemonSuite) TestPluginListFilterCapability(c *check.C) {
|
|
| 318 |
+ testRequires(c, Network) |
|
| 319 |
+ |
|
| 320 |
+ s.d.Start(c) |
|
| 321 |
+ |
|
| 322 |
+ out, err := s.d.Cmd("plugin", "install", "--grant-all-permissions", pNameWithTag, "--disable")
|
|
| 323 |
+ c.Assert(err, check.IsNil, check.Commentf(out)) |
|
| 324 |
+ |
|
| 325 |
+ defer func() {
|
|
| 326 |
+ if out, err := s.d.Cmd("plugin", "remove", pNameWithTag); err != nil {
|
|
| 327 |
+ c.Fatalf("Could not remove plugin: %v %s", err, out)
|
|
| 328 |
+ } |
|
| 329 |
+ }() |
|
| 330 |
+ |
|
| 331 |
+ out, err = s.d.Cmd("plugin", "ls", "--filter", "capability=volumedriver")
|
|
| 332 |
+ c.Assert(err, checker.IsNil) |
|
| 333 |
+ c.Assert(out, checker.Contains, pName) |
|
| 334 |
+ |
|
| 335 |
+ out, err = s.d.Cmd("plugin", "ls", "--filter", "capability=authz")
|
|
| 336 |
+ c.Assert(err, checker.IsNil) |
|
| 337 |
+ c.Assert(out, checker.Not(checker.Contains), pName) |
|
| 338 |
+ |
|
| 339 |
+ out, err = s.d.Cmd("plugin", "ls")
|
|
| 340 |
+ c.Assert(err, checker.IsNil) |
|
| 341 |
+ c.Assert(out, checker.Contains, pName) |
|
| 342 |
+} |
| ... | ... |
@@ -35,7 +35,8 @@ import ( |
| 35 | 35 |
) |
| 36 | 36 |
|
| 37 | 37 |
var acceptedPluginFilterTags = map[string]bool{
|
| 38 |
- "enabled": true, |
|
| 38 |
+ "enabled": true, |
|
| 39 |
+ "capability": true, |
|
| 39 | 40 |
} |
| 40 | 41 |
|
| 41 | 42 |
// Disable deactivates a plugin. This means resources (volumes, networks) cant use them. |
| ... | ... |
@@ -284,6 +285,7 @@ func (pm *Manager) List(pluginFilters filters.Args) ([]types.Plugin, error) {
|
| 284 | 284 |
plugins := pm.config.Store.GetAll() |
| 285 | 285 |
out := make([]types.Plugin, 0, len(plugins)) |
| 286 | 286 |
|
| 287 |
+next: |
|
| 287 | 288 |
for _, p := range plugins {
|
| 288 | 289 |
if enabledOnly && !p.PluginObj.Enabled {
|
| 289 | 290 |
continue |
| ... | ... |
@@ -291,6 +293,13 @@ func (pm *Manager) List(pluginFilters filters.Args) ([]types.Plugin, error) {
|
| 291 | 291 |
if disabledOnly && p.PluginObj.Enabled {
|
| 292 | 292 |
continue |
| 293 | 293 |
} |
| 294 |
+ if pluginFilters.Include("capability") {
|
|
| 295 |
+ for _, f := range p.GetTypes() {
|
|
| 296 |
+ if !pluginFilters.Match("capability", f.Capability) {
|
|
| 297 |
+ continue next |
|
| 298 |
+ } |
|
| 299 |
+ } |
|
| 300 |
+ } |
|
| 294 | 301 |
out = append(out, p.PluginObj) |
| 295 | 302 |
} |
| 296 | 303 |
return out, nil |