Skip to content

Commit fd85a6f

Browse files
author
Tibor Vass
committed
cli-plugins: add concept of experimental plugin, only enabled in experimental mode
To test, add $(pwd)/build/plugins-linux-amd64 to "cliPluginsExtraDirs" config and run: make plugins make binary HELLO_EXPERIMENTAL=1 docker helloworld To show it enabled: HELLO_EXPERIMENTAL=1 DOCKER_CLI_EXPERIMENTAL=enabled docker helloworld Signed-off-by: Tibor Vass <tibor@docker.com>
1 parent 57aa773 commit fd85a6f

File tree

4 files changed

+11
-5
lines changed

4 files changed

+11
-5
lines changed

cli-plugins/examples/helloworld/main.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,5 +101,6 @@ func main() {
101101
SchemaVersion: "0.1.0",
102102
Vendor: "Docker Inc.",
103103
Version: "testing",
104+
Experimental: os.Getenv("HELLO_EXPERIMENTAL") != "",
104105
})
105106
}

cli-plugins/manager/manager.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ func ListPlugins(dockerCli command.Cli, rootcmd *cobra.Command) ([]Plugin, error
117117
continue
118118
}
119119
c := &candidate{paths[0]}
120-
p, err := newPlugin(c, rootcmd)
120+
p, err := newPlugin(c, rootcmd, dockerCli.ClientInfo().HasExperimental)
121121
if err != nil {
122122
return nil, err
123123
}
@@ -159,13 +159,12 @@ func PluginRunCommand(dockerCli command.Cli, name string, rootcmd *cobra.Command
159159
}
160160

161161
c := &candidate{path: path}
162-
plugin, err := newPlugin(c, rootcmd)
162+
plugin, err := newPlugin(c, rootcmd, dockerCli.ClientInfo().HasExperimental)
163163
if err != nil {
164164
return nil, err
165165
}
166166
if plugin.Err != nil {
167-
// TODO: why are we not returning plugin.Err?
168-
return nil, errPluginNotFound(name)
167+
return nil, plugin.Err
169168
}
170169
cmd := exec.Command(plugin.Path, args...)
171170
// Using dockerCli.{In,Out,Err}() here results in a hang until something is input.

cli-plugins/manager/metadata.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,6 @@ type Metadata struct {
2222
ShortDescription string `json:",omitempty"`
2323
// URL is a pointer to the plugin's homepage.
2424
URL string `json:",omitempty"`
25+
// Experimental specifies whether the plugin is experimental
26+
Experimental bool `json:",omitempty"`
2527
}

cli-plugins/manager/plugin.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ type Plugin struct {
3333
// is set, and is always a `pluginError`, but the `Plugin` is still
3434
// returned with no error. An error is only returned due to a
3535
// non-recoverable error.
36-
func newPlugin(c Candidate, rootcmd *cobra.Command) (Plugin, error) {
36+
func newPlugin(c Candidate, rootcmd *cobra.Command, allowExperimental bool) (Plugin, error) {
3737
path := c.Path()
3838
if path == "" {
3939
return Plugin{}, errors.New("plugin candidate path cannot be empty")
@@ -94,6 +94,10 @@ func newPlugin(c Candidate, rootcmd *cobra.Command) (Plugin, error) {
9494
p.Err = wrapAsPluginError(err, "invalid metadata")
9595
return p, nil
9696
}
97+
if p.Experimental && !allowExperimental {
98+
p.Err = NewPluginError("plugin candidate %q: requires experimental enabled", p.Name)
99+
return p, nil
100+
}
97101

98102
if p.Metadata.SchemaVersion != "0.1.0" {
99103
p.Err = NewPluginError("plugin SchemaVersion %q is not valid, must be 0.1.0", p.Metadata.SchemaVersion)

0 commit comments

Comments
 (0)