Skip to content

Commit

Permalink
volume: annotate cluster-volumes flags for API version and swarm
Browse files Browse the repository at this point in the history
This hides the flags when connecting to an older engine, or if
swarm is not enabled, and is also used to add badges in the
documentation.

Signed-off-by: Sebastiaan van Stijn <[email protected]>
  • Loading branch information
thaJeztah committed May 13, 2022
1 parent 3455580 commit 0fab8ec
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
20 changes: 20 additions & 0 deletions cli/command/volume/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,35 @@ func newCreateCommand(dockerCli command.Cli) *cobra.Command {

// flags for cluster volumes only
flags.StringVar(&options.group, "group", "", "Cluster Volume group (cluster volumes)")
flags.SetAnnotation("group", "version", []string{"1.42"})
flags.SetAnnotation("group", "swarm", []string{"manager"})
flags.StringVar(&options.scope, "scope", "single", `Cluster Volume access scope ("single"|"multi")`)
flags.SetAnnotation("scope", "version", []string{"1.42"})
flags.SetAnnotation("scope", "swarm", []string{"manager"})
flags.StringVar(&options.sharing, "sharing", "none", `Cluster Volume access sharing ("none"|"readonly"|"onewriter"|"all")`)
flags.SetAnnotation("sharing", "version", []string{"1.42"})
flags.SetAnnotation("sharing", "swarm", []string{"manager"})
flags.StringVar(&options.availability, "availability", "active", `Cluster Volume availability ("active"|"pause"|"drain")`)
flags.SetAnnotation("availability", "version", []string{"1.42"})
flags.SetAnnotation("availability", "swarm", []string{"manager"})
flags.StringVar(&options.accessType, "type", "block", `Cluster Volume access type ("mount"|"block")`)
flags.SetAnnotation("type", "version", []string{"1.42"})
flags.SetAnnotation("type", "swarm", []string{"manager"})
flags.Var(&options.secrets, "secret", "Cluster Volume secrets")
flags.SetAnnotation("secret", "version", []string{"1.42"})
flags.SetAnnotation("secret", "swarm", []string{"manager"})
flags.Var(&options.limitBytes, "limit-bytes", "Minimum size of the Cluster Volume in bytes")
flags.SetAnnotation("limit-bytes", "version", []string{"1.42"})
flags.SetAnnotation("limit-bytes", "swarm", []string{"manager"})
flags.Var(&options.requiredBytes, "required-bytes", "Maximum size of the Cluster Volume in bytes")
flags.SetAnnotation("required-bytes", "version", []string{"1.42"})
flags.SetAnnotation("required-bytes", "swarm", []string{"manager"})
flags.Var(&options.requisiteTopology, "topology-required", "A topology that the Cluster Volume must be accessible from")
flags.SetAnnotation("topology-required", "version", []string{"1.42"})
flags.SetAnnotation("topology-required", "swarm", []string{"manager"})
flags.Var(&options.preferredTopology, "topology-preferred", "A topology that the Cluster Volume would be preferred in")
flags.SetAnnotation("topology-preferred", "version", []string{"1.42"})
flags.SetAnnotation("topology-preferred", "swarm", []string{"manager"})

return cmd
}
Expand Down
2 changes: 2 additions & 0 deletions cli/command/volume/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ func newListCommand(dockerCli command.Cli) *cobra.Command {
flags.StringVar(&options.format, "format", "", flagsHelper.FormatHelp)
flags.VarP(&options.filter, "filter", "f", "Provide filter values (e.g. 'dangling=true')")
flags.BoolVar(&options.cluster, "cluster", false, "Display only cluster volumes, and use cluster volume list formatting")
flags.SetAnnotation("cluster", "version", []string{"1.42"})
flags.SetAnnotation("cluster", "swarm", []string{"manager"})

return cmd
}
Expand Down
6 changes: 6 additions & 0 deletions cli/command/volume/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,17 @@ func newUpdateCommand(dockerCli command.Cli) *cobra.Command {
RunE: func(cmd *cobra.Command, args []string) error {
return runUpdate(dockerCli, args[0], availability, cmd.Flags())
},
Annotations: map[string]string{
"version": "1.42",
"swarm": "manager",
},
ValidArgsFunction: completion.VolumeNames(dockerCli),
}

flags := cmd.Flags()
flags.StringVar(&availability, "availability", "active", `Cluster Volume availability ("active"|"pause"|"drain")`)
flags.SetAnnotation("availability", "version", []string{"1.42"})
flags.SetAnnotation("availability", "swarm", []string{"manager"})

return cmd
}
Expand Down

0 comments on commit 0fab8ec

Please sign in to comment.