Skip to content

Commit

Permalink
Make experimental a runtime flag
Browse files Browse the repository at this point in the history
Signed-off-by: Kenfe-Mickael Laventure <[email protected]>
  • Loading branch information
mlaventure committed Oct 24, 2016
1 parent 0ab13dd commit 7781a1b
Show file tree
Hide file tree
Showing 112 changed files with 782 additions and 979 deletions.
29 changes: 29 additions & 0 deletions api/server/middleware/experimental.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package middleware

import (
"net/http"

"golang.org/x/net/context"
)

// ExperimentalMiddleware is a the middleware in charge of adding the
// 'Docker-Experimental' header to every outgoing request
type ExperimentalMiddleware struct {
experimental string
}

// NewExperimentalMiddleware creates a new ExperimentalMiddleware
func NewExperimentalMiddleware(experimentalEnabled bool) ExperimentalMiddleware {
if experimentalEnabled {
return ExperimentalMiddleware{"true"}
}
return ExperimentalMiddleware{"false"}
}

// WrapHandler returns a new handler function wrapping the previous one in the request chain.
func (e ExperimentalMiddleware) WrapHandler(handler func(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error) func(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
return func(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
w.Header().Set("Docker-Experimental", e.experimental)
return handler(ctx, w, r, vars)
}
}
2 changes: 0 additions & 2 deletions api/server/router/checkpoint/backend.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// +build experimental

package checkpoint

import "github.com/docker/docker/api/types"
Expand Down
8 changes: 8 additions & 0 deletions api/server/router/checkpoint/checkpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,11 @@ func NewRouter(b Backend, decoder httputils.ContainerDecoder) router.Router {
func (r *checkpointRouter) Routes() []router.Route {
return r.routes
}

func (r *checkpointRouter) initRoutes() {
r.routes = []router.Route{
router.NewGetRoute("/containers/{name:.*}/checkpoints", r.getContainerCheckpoints),
router.NewPostRoute("/containers/{name:.*}/checkpoints", r.postContainerCheckpoint),
router.NewDeleteRoute("/containers/{name}/checkpoints/{checkpoint}", r.deleteContainerCheckpoint),
}
}
15 changes: 0 additions & 15 deletions api/server/router/checkpoint/checkpoint_experimental.go

This file was deleted.

8 changes: 0 additions & 8 deletions api/server/router/checkpoint/checkpoint_regular.go

This file was deleted.

2 changes: 0 additions & 2 deletions api/server/router/checkpoint/checkpoint_routes.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// +build experimental

package checkpoint

import (
Expand Down
2 changes: 0 additions & 2 deletions api/server/router/plugin/backend.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// +build experimental

package plugin

import (
Expand Down
13 changes: 13 additions & 0 deletions api/server/router/plugin/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,16 @@ func NewRouter(b Backend) router.Router {
func (r *pluginRouter) Routes() []router.Route {
return r.routes
}

func (r *pluginRouter) initRoutes() {
r.routes = []router.Route{
router.NewGetRoute("/plugins", r.listPlugins),
router.NewGetRoute("/plugins/{name:.*}", r.inspectPlugin),
router.NewDeleteRoute("/plugins/{name:.*}", r.removePlugin),
router.NewPostRoute("/plugins/{name:.*}/enable", r.enablePlugin), // PATCH?
router.NewPostRoute("/plugins/{name:.*}/disable", r.disablePlugin),
router.NewPostRoute("/plugins/pull", r.pullPlugin),
router.NewPostRoute("/plugins/{name:.*}/push", r.pushPlugin),
router.NewPostRoute("/plugins/{name:.*}/set", r.setPlugin),
}
}
20 changes: 0 additions & 20 deletions api/server/router/plugin/plugin_experimental.go

This file was deleted.

9 changes: 0 additions & 9 deletions api/server/router/plugin/plugin_regular.go

This file was deleted.

2 changes: 0 additions & 2 deletions api/server/router/plugin/plugin_routes.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// +build experimental

package plugin

import (
Expand Down
2 changes: 0 additions & 2 deletions cli/command/bundlefile/bundlefile.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// +build experimental

package bundlefile

import (
Expand Down
2 changes: 0 additions & 2 deletions cli/command/bundlefile/bundlefile_test.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// +build experimental

package bundlefile

import (
Expand Down
20 changes: 17 additions & 3 deletions cli/command/checkpoint/cmd.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,27 @@
// +build !experimental

package checkpoint

import (
"fmt"

"github.com/docker/docker/cli"
"github.com/docker/docker/cli/command"
"github.com/spf13/cobra"
)

// NewCheckpointCommand returns the `checkpoint` subcommand (only in experimental)
func NewCheckpointCommand(dockerCli *command.DockerCli) *cobra.Command {
return &cobra.Command{}
cmd := &cobra.Command{
Use: "checkpoint",
Short: "Manage checkpoints",
Args: cli.NoArgs,
Run: func(cmd *cobra.Command, args []string) {
fmt.Fprintf(dockerCli.Err(), "\n"+cmd.UsageString())
},
}
cmd.AddCommand(
newCreateCommand(dockerCli),
newListCommand(dockerCli),
newRemoveCommand(dockerCli),
)
return cmd
}
30 changes: 0 additions & 30 deletions cli/command/checkpoint/cmd_experimental.go

This file was deleted.

2 changes: 0 additions & 2 deletions cli/command/checkpoint/create.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// +build experimental

package checkpoint

import (
Expand Down
2 changes: 0 additions & 2 deletions cli/command/checkpoint/list.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// +build experimental

package checkpoint

import (
Expand Down
2 changes: 0 additions & 2 deletions cli/command/checkpoint/remove.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// +build experimental

package checkpoint

import (
Expand Down
28 changes: 22 additions & 6 deletions cli/command/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
dopts "github.com/docker/docker/opts"
"github.com/docker/go-connections/sockets"
"github.com/docker/go-connections/tlsconfig"
"golang.org/x/net/context"
)

// Streams is an interface which exposes the standard input and output streams
Expand All @@ -31,12 +32,27 @@ type Streams interface {
// DockerCli represents the docker command line client.
// Instances of the client can be returned from NewDockerCli.
type DockerCli struct {
configFile *configfile.ConfigFile
in *InStream
out *OutStream
err io.Writer
keyFile string
client client.APIClient
configFile *configfile.ConfigFile
in *InStream
out *OutStream
err io.Writer
keyFile string
client client.APIClient
hasExperimental *bool
}

// HasExperimental returns true if experimental features are accessible
func (cli *DockerCli) HasExperimental() bool {
if cli.hasExperimental == nil {
if cli.client == nil {
cli.Initialize(cliflags.NewClientOptions())
}
enabled := false
cli.hasExperimental = &enabled
enabled, _ = cli.client.Ping(context.Background())
}

return *cli.hasExperimental
}

// Client returns the APIClient
Expand Down
14 changes: 10 additions & 4 deletions cli/command/commands/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ func AddCommands(cmd *cobra.Command, dockerCli *command.DockerCli) {
cmd.AddCommand(
node.NewNodeCommand(dockerCli),
service.NewServiceCommand(dockerCli),
stack.NewStackCommand(dockerCli),
stack.NewTopLevelDeployCommand(dockerCli),
swarm.NewSwarmCommand(dockerCli),
container.NewContainerCommand(dockerCli),
image.NewImageCommand(dockerCli),
Expand Down Expand Up @@ -72,9 +70,17 @@ func AddCommands(cmd *cobra.Command, dockerCli *command.DockerCli) {
hide(image.NewSaveCommand(dockerCli)),
hide(image.NewTagCommand(dockerCli)),
hide(system.NewInspectCommand(dockerCli)),
checkpoint.NewCheckpointCommand(dockerCli),
plugin.NewPluginCommand(dockerCli),
)

if dockerCli.HasExperimental() {
cmd.AddCommand(
stack.NewStackCommand(dockerCli),
stack.NewTopLevelDeployCommand(dockerCli),
checkpoint.NewCheckpointCommand(dockerCli),
plugin.NewPluginCommand(dockerCli),
)
}

}

func hide(cmd *cobra.Command) *cobra.Command {
Expand Down
4 changes: 3 additions & 1 deletion cli/command/container/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ func NewStartCommand(dockerCli *command.DockerCli) *cobra.Command {
flags.BoolVarP(&opts.openStdin, "interactive", "i", false, "Attach container's STDIN")
flags.StringVar(&opts.detachKeys, "detach-keys", "", "Override the key sequence for detaching a container")

addExperimentalStartFlags(flags, &opts)
if dockerCli.HasExperimental() {
flags.StringVar(&opts.checkpoint, "checkpoint", "", "Restore from this checkpoint")
}

return cmd
}
Expand Down
8 changes: 0 additions & 8 deletions cli/command/container/start_utils.go

This file was deleted.

9 changes: 0 additions & 9 deletions cli/command/container/start_utils_experimental.go

This file was deleted.

26 changes: 23 additions & 3 deletions cli/command/plugin/cmd.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,33 @@
// +build !experimental

package plugin

import (
"fmt"

"github.com/docker/docker/cli"
"github.com/docker/docker/cli/command"
"github.com/spf13/cobra"
)

// NewPluginCommand returns a cobra command for `plugin` subcommands
func NewPluginCommand(dockerCli *command.DockerCli) *cobra.Command {
return &cobra.Command{}
cmd := &cobra.Command{
Use: "plugin",
Short: "Manage plugins",
Args: cli.NoArgs,
Run: func(cmd *cobra.Command, args []string) {
fmt.Fprintf(dockerCli.Err(), "\n"+cmd.UsageString())
},
}

cmd.AddCommand(
newDisableCommand(dockerCli),
newEnableCommand(dockerCli),
newInspectCommand(dockerCli),
newInstallCommand(dockerCli),
newListCommand(dockerCli),
newRemoveCommand(dockerCli),
newSetCommand(dockerCli),
newPushCommand(dockerCli),
)
return cmd
}
Loading

0 comments on commit 7781a1b

Please sign in to comment.