Skip to content

Commit

Permalink
Add support for filtering by {min,max} x {create,mod} x {revision} to…
Browse files Browse the repository at this point in the history
… etcdctl.

Signed-off-by: Cristian Ferretti <[email protected]>
  • Loading branch information
jcferretti committed Jun 25, 2024
1 parent a897676 commit 29e4edc
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 10 deletions.
8 changes: 8 additions & 0 deletions etcdctl/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,14 @@ RPC: Range

- keys-only -- Get only the keys

- max-create-revision -- restrict results to kvs with create revision lower or equal than the supplied revision

- min-create-revision -- restrict results to kvs with create revision greater or equal than the supplied revision

- max-mod-revision -- restrict results to kvs with modified revision lower or equal than the supplied revision

- min-mod-revision -- restrict results to kvs with modified revision greater or equal than the supplied revision

#### Output
Prints the data in format below,
```
Expand Down
44 changes: 34 additions & 10 deletions etcdctl/ctlv3/command/get_command.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,20 @@ import (
)

var (
getConsistency string
getLimit int64
getSortOrder string
getSortTarget string
getPrefix bool
getFromKey bool
getRev int64
getKeysOnly bool
getCountOnly bool
printValueOnly bool
getConsistency string
getLimit int64
getSortOrder string
getSortTarget string
getPrefix bool
getFromKey bool
getRev int64
getKeysOnly bool
getCountOnly bool
printValueOnly bool
getMinCreateRevision int64
getMaxCreateRevision int64
getMinModRevision int64
getMaxModRevision int64
)

// NewGetCommand returns the cobra command for "get".
Expand All @@ -55,6 +59,10 @@ func NewGetCommand() *cobra.Command {
cmd.Flags().BoolVar(&getKeysOnly, "keys-only", false, "Get only the keys")
cmd.Flags().BoolVar(&getCountOnly, "count-only", false, "Get only the count")
cmd.Flags().BoolVar(&printValueOnly, "print-value-only", false, `Only write values when using the "simple" output format`)
cmd.Flags().Int64Var(&getMinCreateRevision, "min-create-revision", 0, "Minimum create revision")
cmd.Flags().Int64Var(&getMaxCreateRevision, "max-create-revision", 0, "Maximum create revision")
cmd.Flags().Int64Var(&getMinModRevision, "min-mod-revision", 0, "Minimum modification revision")
cmd.Flags().Int64Var(&getMaxModRevision, "max-mod-revision", 0, "Maximum modification revision")

cmd.RegisterFlagCompletionFunc("consistency", func(_ *cobra.Command, _ []string, _ string) ([]string, cobra.ShellCompDirective) {
return []string{"l", "s"}, cobra.ShellCompDirectiveDefault
Expand Down Expand Up @@ -184,5 +192,21 @@ func getGetOp(args []string) (string, []clientv3.OpOption) {
opts = append(opts, clientv3.WithCountOnly())
}

if getMinCreateRevision > 0 {
opts = append(opts, clientv3.WithMinCreateRev(getMinCreateRevision))
}

if getMaxCreateRevision > 0 {
opts = append(opts, clientv3.WithMaxCreateRev(getMaxCreateRevision))
}

if getMinModRevision > 0 {
opts = append(opts, clientv3.WithMinModRev(getMinModRevision))
}

if getMaxModRevision > 0 {
opts = append(opts, clientv3.WithMaxModRev(getMaxModRevision))
}

return key, opts
}

0 comments on commit 29e4edc

Please sign in to comment.