ソースを参照

Merge pull request #31513 from thaJeztah/better-handling-of-older-api-versions

Improve error handling of commands run against unsupported daemon
Vincent Demeester 8 年 前
コミット
c1b04a8d6e

+ 1 - 0
cli/command/node/cmd.go

@@ -15,6 +15,7 @@ func NewNodeCommand(dockerCli *command.DockerCli) *cobra.Command {
 		Short: "Manage Swarm nodes",
 		Args:  cli.NoArgs,
 		RunE:  dockerCli.ShowHelp,
+		Tags:  map[string]string{"version": "1.24"},
 	}
 	cmd.AddCommand(
 		newDemoteCommand(dockerCli),

+ 1 - 0
cli/command/plugin/cmd.go

@@ -13,6 +13,7 @@ func NewPluginCommand(dockerCli *command.DockerCli) *cobra.Command {
 		Short: "Manage plugins",
 		Args:  cli.NoArgs,
 		RunE:  dockerCli.ShowHelp,
+		Tags:  map[string]string{"version": "1.25"},
 	}
 
 	cmd.AddCommand(

+ 1 - 0
cli/command/plugin/upgrade.go

@@ -26,6 +26,7 @@ func newUpgradeCommand(dockerCli *command.DockerCli) *cobra.Command {
 			}
 			return runUpgrade(dockerCli, options)
 		},
+		Tags: map[string]string{"version": "1.26"},
 	}
 
 	flags := cmd.Flags()

+ 1 - 0
cli/command/secret/cmd.go

@@ -14,6 +14,7 @@ func NewSecretCommand(dockerCli *command.DockerCli) *cobra.Command {
 		Short: "Manage Docker secrets",
 		Args:  cli.NoArgs,
 		RunE:  dockerCli.ShowHelp,
+		Tags:  map[string]string{"version": "1.25"},
 	}
 	cmd.AddCommand(
 		newSecretListCommand(dockerCli),

+ 1 - 0
cli/command/service/cmd.go

@@ -14,6 +14,7 @@ func NewServiceCommand(dockerCli *command.DockerCli) *cobra.Command {
 		Short: "Manage services",
 		Args:  cli.NoArgs,
 		RunE:  dockerCli.ShowHelp,
+		Tags:  map[string]string{"version": "1.24"},
 	}
 	cmd.AddCommand(
 		newCreateCommand(dockerCli),

+ 1 - 0
cli/command/swarm/cmd.go

@@ -14,6 +14,7 @@ func NewSwarmCommand(dockerCli *command.DockerCli) *cobra.Command {
 		Short: "Manage Swarm",
 		Args:  cli.NoArgs,
 		RunE:  dockerCli.ShowHelp,
+		Tags:  map[string]string{"version": "1.24"},
 	}
 	cmd.AddCommand(
 		newInitCommand(dockerCli),

+ 1 - 0
cli/command/volume/cmd.go

@@ -13,6 +13,7 @@ func NewVolumeCommand(dockerCli *command.DockerCli) *cobra.Command {
 		Short: "Manage volumes",
 		Args:  cli.NoArgs,
 		RunE:  dockerCli.ShowHelp,
+		Tags:  map[string]string{"version": "1.21"},
 	}
 	cmd.AddCommand(
 		newCreateCommand(dockerCli),

+ 7 - 10
cmd/docker/docker.go

@@ -229,17 +229,14 @@ func hideUnsupportedFeatures(cmd *cobra.Command, clientVersion, osType string, h
 }
 
 func isSupported(cmd *cobra.Command, clientVersion, osType string, hasExperimental bool) error {
-	// We check recursively so that, e.g., `docker stack ls` will return the same output as `docker stack`
-	if !hasExperimental {
-		for curr := cmd; curr != nil; curr = curr.Parent() {
-			if _, ok := curr.Tags["experimental"]; ok {
-				return errors.New("only supported on a Docker daemon with experimental features enabled")
-			}
+	// Check recursively so that, e.g., `docker stack ls` returns the same output as `docker stack`
+	for curr := cmd; curr != nil; curr = curr.Parent() {
+		if cmdVersion, ok := curr.Tags["version"]; ok && versions.LessThan(clientVersion, cmdVersion) {
+			return fmt.Errorf("%s requires API version %s, but the Docker daemon API version is %s", cmd.CommandPath(), cmdVersion, clientVersion)
+		}
+		if _, ok := curr.Tags["experimental"]; ok && !hasExperimental {
+			return fmt.Errorf("%s is only supported on a Docker daemon with experimental features enabled", cmd.CommandPath())
 		}
-	}
-
-	if cmdVersion, ok := cmd.Tags["version"]; ok && versions.LessThan(clientVersion, cmdVersion) {
-		return fmt.Errorf("requires API version %s, but the Docker daemon API version is %s", cmdVersion, clientVersion)
 	}
 
 	errs := []string{}