Skip to content

Commit

Permalink
Merge pull request #1237 from vdemeester/use-non-deprecated-filters-f…
Browse files Browse the repository at this point in the history
…uncs

Migrate to non-deprecated functions of `api/types/filters`

Signed-off-by: selansen <elango.siva@docker.com>
  • Loading branch information
Vincent Demeester authored and selansen committed Jul 29, 2018
2 parents a3464c0 + 55edeb4 commit ce858bd
Show file tree
Hide file tree
Showing 9 changed files with 31 additions and 10 deletions.
2 changes: 1 addition & 1 deletion cli/command/service/ps.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ loop:
}

func updateNodeFilter(ctx context.Context, client client.APIClient, filter filters.Args) error {
if filter.Include("node") {
if filter.Contains("node") {
nodeFilters := filter.Get("node")
for _, nodeFilter := range nodeFilters {
nodeReference, err := node.Reference(ctx, client, nodeFilter)
Expand Down
3 changes: 3 additions & 0 deletions cli/command/swarm/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ type initOptions struct {
dataPathAddr string
forceNewCluster bool
availability string
defaultAddrPool string
}

func newInitCommand(dockerCli command.Cli) *cobra.Command {
Expand All @@ -44,6 +45,7 @@ func newInitCommand(dockerCli command.Cli) *cobra.Command {
flags.BoolVar(&opts.forceNewCluster, "force-new-cluster", false, "Force create a new cluster from current state")
flags.BoolVar(&opts.autolock, flagAutolock, false, "Enable manager autolocking (requiring an unlock key to start a stopped manager)")
flags.StringVar(&opts.availability, flagAvailability, "active", `Availability of the node ("active"|"pause"|"drain")`)
flags.StringVar(&opts.defaultAddrPool, flagDefaultAddrPool, "", "List of default subnet addresses followed by subnet size (format: <subnet,subnet,..:subnet-size)")
addSwarmFlags(flags, &opts.swarmOptions)
return cmd
}
Expand All @@ -56,6 +58,7 @@ func runInit(dockerCli command.Cli, flags *pflag.FlagSet, opts initOptions) erro
ListenAddr: opts.listenAddr.String(),
AdvertiseAddr: opts.advertiseAddr,
DataPathAddr: opts.dataPathAddr,
DefaultAddrPool: opts.defaultAddrPool,
ForceNewCluster: opts.forceNewCluster,
Spec: opts.swarmOptions.ToSpec(flags),
AutoLockManagers: opts.swarmOptions.autolock,
Expand Down
1 change: 1 addition & 0 deletions cli/command/swarm/opts.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const (
flagListenAddr = "listen-addr"
flagAdvertiseAddr = "advertise-addr"
flagDataPathAddr = "data-path-addr"
flagDefaultAddrPool = "default-addr-pool"
flagQuiet = "quiet"
flagRotate = "rotate"
flagToken = "token"
Expand Down
2 changes: 1 addition & 1 deletion cli/command/system/prune.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func runBuildCachePrune(dockerCli command.Cli, _ opts.FilterOpt) (uint64, string

func runPrune(dockerCli command.Cli, options pruneOptions) error {
// TODO version this once "until" filter is supported for volumes
if options.pruneVolumes && options.filter.Value().Include("until") {
if options.pruneVolumes && options.filter.Value().Contains("until") {
return fmt.Errorf(`ERROR: The "until" filter is not supported with "--volumes"`)
}
if versions.LessThan(dockerCli.Client().ClientVersion(), "1.31") {
Expand Down
4 changes: 2 additions & 2 deletions cli/command/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,14 +102,14 @@ func PruneFilters(dockerCli Cli, pruneFilters filters.Args) filters.Args {
// CLI label filter supersede config.json.
// If CLI label filter conflict with config.json,
// skip adding label! filter in config.json.
if pruneFilters.Include("label!") && pruneFilters.ExactMatch("label!", parts[1]) {
if pruneFilters.Contains("label!") && pruneFilters.ExactMatch("label!", parts[1]) {
continue
}
} else if parts[0] == "label!" {
// CLI label! filter supersede config.json.
// If CLI label! filter conflict with config.json,
// skip adding label filter in config.json.
if pruneFilters.Include("label") && pruneFilters.ExactMatch("label", parts[1]) {
if pruneFilters.Contains("label") && pruneFilters.ExactMatch("label", parts[1]) {
continue
}
}
Expand Down
4 changes: 2 additions & 2 deletions contrib/completion/bash/docker
Original file line number Diff line number Diff line change
Expand Up @@ -3661,7 +3661,7 @@ _docker_swarm_init() {
COMPREPLY=( $( compgen -W "active drain pause" -- "$cur" ) )
return
;;
--cert-expiry|--dispatcher-heartbeat|--external-ca|--max-snapshots|--snapshot-interval|--task-history-limit)
--cert-expiry|--dispatcher-heartbeat|--external-ca|--max-snapshots|--snapshot-interval|--task-history-limit | --default-addr-pool )
return
;;
--data-path-addr)
Expand All @@ -3681,7 +3681,7 @@ _docker_swarm_init() {

case "$cur" in
-*)
COMPREPLY=( $( compgen -W "--advertise-addr --autolock --availability --cert-expiry --data-path-addr --dispatcher-heartbeat --external-ca --force-new-cluster --help --listen-addr --max-snapshots --snapshot-interval --task-history-limit" -- "$cur" ) )
COMPREPLY=( $( compgen -W "--advertise-addr --autolock --availability --cert-expiry --data-path-addr --default-addr-pool --dispatcher-heartbeat --external-ca --force-new-cluster --help --listen-addr --max-snapshots --snapshot-interval --task-history-limit" -- "$cur" ) )
;;
esac
}
Expand Down
1 change: 1 addition & 0 deletions contrib/completion/zsh/_docker
Original file line number Diff line number Diff line change
Expand Up @@ -2285,6 +2285,7 @@ __docker_swarm_subcommand() {
$opts_help \
"($help)--advertise-addr=[Advertised address]:ip\:port: " \
"($help)--data-path-addr=[Data path IP or interface]:ip " \
"($help)--default-addr-pool=[default subnet addresses]:subnet-size " \
"($help)--autolock[Enable manager autolocking]" \
"($help)--availability=[Availability of the node]:availability:(active drain pause)" \
"($help)--cert-expiry=[Validity period for node certificates]:duration: " \
Expand Down
6 changes: 6 additions & 0 deletions docs/reference/commandline/swarm_init.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ Options:
--availability string Availability of the node ("active"|"pause"|"drain") (default "active")
--cert-expiry duration Validity period for node certificates (ns|us|ms|s|m|h) (default 2160h0m0s)
--data-path-addr string Address or interface to use for data path traffic (format: <ip|interface>)
--default-addr-pool string List of default subnet addresses followed by subnet size (format: <subnet,subnet,..:subnet-size)
--dispatcher-heartbeat duration Dispatcher heartbeat period (ns|us|ms|s|m|h) (default 5s)
--external-ca external-ca Specifications of one or more certificate signing endpoints
--force-new-cluster Force create a new cluster from current state
Expand Down Expand Up @@ -128,6 +129,11 @@ management traffic of the cluster.
If unspecified, Docker will use the same IP address or interface that is used for the
advertise address.

### `--default-addr-pool`
This flag specifies default subnet pools for global scope networks. If subnet size is not
specified then default value 24 will be used.
If unspecified, Docker will use the predefined subnets as it works on older releases.

### `--task-history-limit`

This flag sets up task history retention limit.
Expand Down
18 changes: 14 additions & 4 deletions opts/opts.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (

"github.com/docker/docker/api/types/filters"
units "github.com/docker/go-units"
"github.com/pkg/errors"
)

var (
Expand Down Expand Up @@ -318,7 +319,7 @@ func NewFilterOpt() FilterOpt {
}

func (o *FilterOpt) String() string {
repr, err := filters.ToParam(o.filter)
repr, err := filters.ToJSON(o.filter)
if err != nil {
return "invalid filters"
}
Expand All @@ -327,9 +328,18 @@ func (o *FilterOpt) String() string {

// Set sets the value of the opt by parsing the command line value
func (o *FilterOpt) Set(value string) error {
var err error
o.filter, err = filters.ParseFlag(value, o.filter)
return err
if value == "" {
return nil
}
if !strings.Contains(value, "=") {
return errors.New("bad format of filter (expected name=value)")
}
f := strings.SplitN(value, "=", 2)
name := strings.ToLower(strings.TrimSpace(f[0]))
value = strings.TrimSpace(f[1])

o.filter.Add(name, value)
return nil
}

// Type returns the option type
Expand Down

0 comments on commit ce858bd

Please sign in to comment.