Skip to content

Commit bbbddee

Browse files
committed
Add version annotation to various flags added in 1.13
Pull request moby#27745 added support for the client to talk to older versions of the daemon. Various flags were added to docker 1.13 that are not compatible with older daemons. This PR adds annotations to those flags, so that they are automatically hidden if the daemon is older than docker 1.13 (API 1.25). Not all new flags affect the API (some are client-side only). The following PR's added new flags to docker 1.13 that affect the API; - moby#23430 added `--cpu-rt-period`and `--cpu-rt-runtime` - moby#27800 / moby#25317 added `--group` / `--group-add` / `--group-rm` - moby#27702 added `--network` to `docker build` - moby#25962 added `--attachable` to `docker network create` - moby#27998 added `--compose-file` to `docker stack deploy` - moby#22566 added `--stop-timeout` to `docker run` and `docker create` - moby#26061 added `--init` to `docker run` and `docker create` - moby#26941 added `--init-path` to `docker run` and `docker create` - moby#27958 added `--cpus` on `docker run` / `docker create` - moby#27567 added `--dns`, `--dns-opt`, and `--dns-search` to `docker service create` - moby#27596 added `--force` to `docker service update` - moby#27857 added `--hostname` to `docker service create` - moby#28031 added `--hosts`, `--host-add` / `--host-rm` to `docker service create` and `docker service update` - moby#28076 added `--tty` on `docker service create` / `docker service update` - moby#26421 added `--update-max-failure-ratio`, `--update-monitor` and `--rollback` on `docker service update` - moby#27369 added `--health-cmd`, `--health-interval`, `--health-retries`, `--health-timeout` and `--no-healthcheck` options to `docker service create` and `docker service update` Signed-off-by: Sebastiaan van Stijn <[email protected]>
1 parent e74623d commit bbbddee

File tree

9 files changed

+41
-0
lines changed

9 files changed

+41
-0
lines changed

cli/command/container/opts.go

+5
Original file line numberDiff line numberDiff line change
@@ -236,9 +236,12 @@ func addFlags(flags *pflag.FlagSet) *containerOptions {
236236
flags.Int64Var(&copts.cpuPeriod, "cpu-period", 0, "Limit CPU CFS (Completely Fair Scheduler) period")
237237
flags.Int64Var(&copts.cpuQuota, "cpu-quota", 0, "Limit CPU CFS (Completely Fair Scheduler) quota")
238238
flags.Int64Var(&copts.cpuRealtimePeriod, "cpu-rt-period", 0, "Limit CPU real-time period in microseconds")
239+
flags.SetAnnotation("cpu-rt-period", "version", []string{"1.25"})
239240
flags.Int64Var(&copts.cpuRealtimeRuntime, "cpu-rt-runtime", 0, "Limit CPU real-time runtime in microseconds")
241+
flags.SetAnnotation("cpu-rt-runtime", "version", []string{"1.25"})
240242
flags.Int64VarP(&copts.cpuShares, "cpu-shares", "c", 0, "CPU shares (relative weight)")
241243
flags.Var(&copts.cpus, "cpus", "Number of CPUs")
244+
flags.SetAnnotation("cpus", "version", []string{"1.25"})
242245
flags.Var(&copts.deviceReadBps, "device-read-bps", "Limit read rate (bytes per second) from a device")
243246
flags.Var(&copts.deviceReadIOps, "device-read-iops", "Limit read rate (IO per second) from a device")
244247
flags.Var(&copts.deviceWriteBps, "device-write-bps", "Limit write rate (bytes per second) to a device")
@@ -264,7 +267,9 @@ func addFlags(flags *pflag.FlagSet) *containerOptions {
264267
flags.StringVar(&copts.runtime, "runtime", "", "Runtime to use for this container")
265268

266269
flags.BoolVar(&copts.init, "init", false, "Run an init inside the container that forwards signals and reaps processes")
270+
flags.SetAnnotation("init", "version", []string{"1.25"})
267271
flags.StringVar(&copts.initPath, "init-path", "", "Path to the docker-init binary")
272+
flags.SetAnnotation("init-path", "version", []string{"1.25"})
268273
return copts
269274
}
270275

cli/command/container/update.go

+2
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,9 @@ func NewUpdateCommand(dockerCli *command.DockerCli) *cobra.Command {
5454
flags.Int64Var(&opts.cpuPeriod, "cpu-period", 0, "Limit CPU CFS (Completely Fair Scheduler) period")
5555
flags.Int64Var(&opts.cpuQuota, "cpu-quota", 0, "Limit CPU CFS (Completely Fair Scheduler) quota")
5656
flags.Int64Var(&opts.cpuRealtimePeriod, "cpu-rt-period", 0, "Limit the CPU real-time period in microseconds")
57+
flags.SetAnnotation("cpu-rt-period", "version", []string{"1.25"})
5758
flags.Int64Var(&opts.cpuRealtimeRuntime, "cpu-rt-runtime", 0, "Limit the CPU real-time runtime in microseconds")
59+
flags.SetAnnotation("cpu-rt-runtime", "version", []string{"1.25"})
5860
flags.StringVar(&opts.cpusetCpus, "cpuset-cpus", "", "CPUs in which to allow execution (0-3, 0,1)")
5961
flags.StringVar(&opts.cpusetMems, "cpuset-mems", "", "MEMs in which to allow execution (0-3, 0,1)")
6062
flags.Int64VarP(&opts.cpuShares, "cpu-shares", "c", 0, "CPU shares (relative weight)")

cli/command/image/build.go

+1
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ func NewBuildCommand(dockerCli *command.DockerCli) *cobra.Command {
107107
flags.BoolVar(&options.compress, "compress", false, "Compress the build context using gzip")
108108
flags.StringSliceVar(&options.securityOpt, "security-opt", []string{}, "Security options")
109109
flags.StringVar(&options.networkMode, "network", "default", "Set the networking mode for the RUN instructions during build")
110+
flags.SetAnnotation("network", "version", []string{"1.25"})
110111

111112
command.AddTrustedFlags(flags, true)
112113

cli/command/network/create.go

+1
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ func newCreateCommand(dockerCli *command.DockerCli) *cobra.Command {
5858
flags.BoolVar(&opts.internal, "internal", false, "Restrict external access to the network")
5959
flags.BoolVar(&opts.ipv6, "ipv6", false, "Enable IPv6 networking")
6060
flags.BoolVar(&opts.attachable, "attachable", false, "Enable manual container attachment")
61+
flags.SetAnnotation("attachable", "version", []string{"1.25"})
6162

6263
flags.StringVar(&opts.ipamDriver, "ipam-driver", "default", "IP Address Management Driver")
6364
flags.StringSliceVar(&opts.ipamSubnet, "subnet", []string{}, "Subnet in CIDR format that represents a network segment")

cli/command/service/create.go

+6
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,18 @@ func newCreateCommand(dockerCli *command.DockerCli) *cobra.Command {
3939
flags.Var(&opts.constraints, flagConstraint, "Placement constraints")
4040
flags.Var(&opts.networks, flagNetwork, "Network attachments")
4141
flags.Var(&opts.secrets, flagSecret, "Specify secrets to expose to the service")
42+
flags.SetAnnotation(flagSecret, "version", []string{"1.25"})
4243
flags.VarP(&opts.endpoint.publishPorts, flagPublish, "p", "Publish a port as a node port")
4344
flags.Var(&opts.groups, flagGroup, "Set one or more supplementary user groups for the container")
45+
flags.SetAnnotation(flagGroup, "version", []string{"1.25"})
4446
flags.Var(&opts.dns, flagDNS, "Set custom DNS servers")
47+
flags.SetAnnotation(flagDNS, "version", []string{"1.25"})
4548
flags.Var(&opts.dnsOption, flagDNSOption, "Set DNS options")
49+
flags.SetAnnotation(flagDNSOption, "version", []string{"1.25"})
4650
flags.Var(&opts.dnsSearch, flagDNSSearch, "Set custom DNS search domains")
51+
flags.SetAnnotation(flagDNSSearch, "version", []string{"1.25"})
4752
flags.Var(&opts.hosts, flagHost, "Set one or more custom host-to-IP mappings (host:ip)")
53+
flags.SetAnnotation(flagHost, "version", []string{"1.25"})
4854

4955
flags.SetInterspersed(false)
5056
return cmd

cli/command/service/opts.go

+9
Original file line numberDiff line numberDiff line change
@@ -445,6 +445,7 @@ func addServiceFlags(cmd *cobra.Command, opts *serviceOptions) {
445445
flags.StringVarP(&opts.workdir, flagWorkdir, "w", "", "Working directory inside the container")
446446
flags.StringVarP(&opts.user, flagUser, "u", "", "Username or UID (format: <name|uid>[:<group|gid>])")
447447
flags.StringVar(&opts.hostname, flagHostname, "", "Container hostname")
448+
flags.SetAnnotation(flagHostname, "version", []string{"1.25"})
448449

449450
flags.Var(&opts.resources.limitCPU, flagLimitCPU, "Limit CPUs")
450451
flags.Var(&opts.resources.limitMemBytes, flagLimitMemory, "Limit Memory")
@@ -462,8 +463,10 @@ func addServiceFlags(cmd *cobra.Command, opts *serviceOptions) {
462463
flags.Uint64Var(&opts.update.parallelism, flagUpdateParallelism, 1, "Maximum number of tasks updated simultaneously (0 to update all at once)")
463464
flags.DurationVar(&opts.update.delay, flagUpdateDelay, time.Duration(0), "Delay between updates (ns|us|ms|s|m|h) (default 0s)")
464465
flags.DurationVar(&opts.update.monitor, flagUpdateMonitor, time.Duration(0), "Duration after each task update to monitor for failure (ns|us|ms|s|m|h) (default 0s)")
466+
flags.SetAnnotation(flagUpdateMonitor, "version", []string{"1.25"})
465467
flags.StringVar(&opts.update.onFailure, flagUpdateFailureAction, "pause", "Action on update failure (pause|continue)")
466468
flags.Var(&opts.update.maxFailureRatio, flagUpdateMaxFailureRatio, "Failure rate to tolerate during an update")
469+
flags.SetAnnotation(flagUpdateMaxFailureRatio, "version", []string{"1.25"})
467470

468471
flags.StringVar(&opts.endpoint.mode, flagEndpointMode, "", "Endpoint mode (vip or dnsrr)")
469472

@@ -473,12 +476,18 @@ func addServiceFlags(cmd *cobra.Command, opts *serviceOptions) {
473476
flags.Var(&opts.logDriver.opts, flagLogOpt, "Logging driver options")
474477

475478
flags.StringVar(&opts.healthcheck.cmd, flagHealthCmd, "", "Command to run to check health")
479+
flags.SetAnnotation(flagHealthCmd, "version", []string{"1.25"})
476480
flags.Var(&opts.healthcheck.interval, flagHealthInterval, "Time between running the check (ns|us|ms|s|m|h)")
481+
flags.SetAnnotation(flagHealthInterval, "version", []string{"1.25"})
477482
flags.Var(&opts.healthcheck.timeout, flagHealthTimeout, "Maximum time to allow one check to run (ns|us|ms|s|m|h)")
483+
flags.SetAnnotation(flagHealthTimeout, "version", []string{"1.25"})
478484
flags.IntVar(&opts.healthcheck.retries, flagHealthRetries, 0, "Consecutive failures needed to report unhealthy")
485+
flags.SetAnnotation(flagHealthRetries, "version", []string{"1.25"})
479486
flags.BoolVar(&opts.healthcheck.noHealthcheck, flagNoHealthcheck, false, "Disable any container-specified HEALTHCHECK")
487+
flags.SetAnnotation(flagNoHealthcheck, "version", []string{"1.25"})
480488

481489
flags.BoolVarP(&opts.tty, flagTTY, "t", false, "Allocate a pseudo-TTY")
490+
flags.SetAnnotation(flagTTY, "version", []string{"1.25"})
482491
}
483492

484493
const (

cli/command/service/update.go

+14
Original file line numberDiff line numberDiff line change
@@ -38,34 +38,48 @@ func newUpdateCommand(dockerCli *command.DockerCli) *cobra.Command {
3838
flags.String("image", "", "Service image tag")
3939
flags.String("args", "", "Service command args")
4040
flags.Bool("rollback", false, "Rollback to previous specification")
41+
flags.SetAnnotation("rollback", "version", []string{"1.25"})
4142
flags.Bool("force", false, "Force update even if no changes require it")
43+
flags.SetAnnotation("force", "version", []string{"1.25"})
4244
addServiceFlags(cmd, serviceOpts)
4345

4446
flags.Var(newListOptsVar(), flagEnvRemove, "Remove an environment variable")
4547
flags.Var(newListOptsVar(), flagGroupRemove, "Remove a previously added supplementary user group from the container")
48+
flags.SetAnnotation(flagGroupRemove, "version", []string{"1.25"})
4649
flags.Var(newListOptsVar(), flagLabelRemove, "Remove a label by its key")
4750
flags.Var(newListOptsVar(), flagContainerLabelRemove, "Remove a container label by its key")
4851
flags.Var(newListOptsVar(), flagMountRemove, "Remove a mount by its target path")
4952
// flags.Var(newListOptsVar().WithValidator(validatePublishRemove), flagPublishRemove, "Remove a published port by its target port")
5053
flags.Var(&opts.PortOpt{}, flagPublishRemove, "Remove a published port by its target port")
5154
flags.Var(newListOptsVar(), flagConstraintRemove, "Remove a constraint")
5255
flags.Var(newListOptsVar(), flagDNSRemove, "Remove a custom DNS server")
56+
flags.SetAnnotation(flagDNSRemove, "version", []string{"1.25"})
5357
flags.Var(newListOptsVar(), flagDNSOptionRemove, "Remove a DNS option")
58+
flags.SetAnnotation(flagDNSOptionRemove, "version", []string{"1.25"})
5459
flags.Var(newListOptsVar(), flagDNSSearchRemove, "Remove a DNS search domain")
60+
flags.SetAnnotation(flagDNSSearchRemove, "version", []string{"1.25"})
5561
flags.Var(newListOptsVar(), flagHostRemove, "Remove a custom host-to-IP mapping (host:ip)")
62+
flags.SetAnnotation(flagHostRemove, "version", []string{"1.25"})
5663
flags.Var(&serviceOpts.labels, flagLabelAdd, "Add or update a service label")
5764
flags.Var(&serviceOpts.containerLabels, flagContainerLabelAdd, "Add or update a container label")
5865
flags.Var(&serviceOpts.env, flagEnvAdd, "Add or update an environment variable")
5966
flags.Var(newListOptsVar(), flagSecretRemove, "Remove a secret")
67+
flags.SetAnnotation(flagSecretRemove, "version", []string{"1.25"})
6068
flags.Var(&serviceOpts.secrets, flagSecretAdd, "Add or update a secret on a service")
69+
flags.SetAnnotation(flagSecretAdd, "version", []string{"1.25"})
6170
flags.Var(&serviceOpts.mounts, flagMountAdd, "Add or update a mount on a service")
6271
flags.Var(&serviceOpts.constraints, flagConstraintAdd, "Add or update a placement constraint")
6372
flags.Var(&serviceOpts.endpoint.publishPorts, flagPublishAdd, "Add or update a published port")
6473
flags.Var(&serviceOpts.groups, flagGroupAdd, "Add an additional supplementary user group to the container")
74+
flags.SetAnnotation(flagGroupAdd, "version", []string{"1.25"})
6575
flags.Var(&serviceOpts.dns, flagDNSAdd, "Add or update a custom DNS server")
76+
flags.SetAnnotation(flagDNSAdd, "version", []string{"1.25"})
6677
flags.Var(&serviceOpts.dnsOption, flagDNSOptionAdd, "Add or update a DNS option")
78+
flags.SetAnnotation(flagDNSOptionAdd, "version", []string{"1.25"})
6779
flags.Var(&serviceOpts.dnsSearch, flagDNSSearchAdd, "Add or update a custom DNS search domain")
80+
flags.SetAnnotation(flagDNSSearchAdd, "version", []string{"1.25"})
6881
flags.Var(&serviceOpts.hosts, flagHostAdd, "Add or update a custom host-to-IP mapping (host:ip)")
82+
flags.SetAnnotation(flagHostAdd, "version", []string{"1.25"})
6983

7084
return cmd
7185
}

cli/command/stack/opts.go

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111

1212
func addComposefileFlag(opt *string, flags *pflag.FlagSet) {
1313
flags.StringVarP(opt, "compose-file", "c", "", "Path to a Compose file")
14+
flags.SetAnnotation("compose-file", "version", []string{"1.25"})
1415
}
1516

1617
func addBundlefileFlag(opt *string, flags *pflag.FlagSet) {

cli/command/swarm/opts.go

+2
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,9 @@ func addSwarmFlags(flags *pflag.FlagSet, opts *swarmOptions) {
176176
flags.DurationVar(&opts.nodeCertExpiry, flagCertExpiry, time.Duration(90*24*time.Hour), "Validity period for node certificates (ns|us|ms|s|m|h)")
177177
flags.Var(&opts.externalCA, flagExternalCA, "Specifications of one or more certificate signing endpoints")
178178
flags.Uint64Var(&opts.maxSnapshots, flagMaxSnapshots, 0, "Number of additional Raft snapshots to retain")
179+
flags.SetAnnotation(flagMaxSnapshots, "version", []string{"1.25"})
179180
flags.Uint64Var(&opts.snapshotInterval, flagSnapshotInterval, 10000, "Number of log entries between Raft snapshots")
181+
flags.SetAnnotation(flagSnapshotInterval, "version", []string{"1.25"})
180182
}
181183

182184
func (opts *swarmOptions) mergeSwarmSpec(spec *swarm.Spec, flags *pflag.FlagSet) {

0 commit comments

Comments
 (0)