From 9aafed42261ae3519a85405b30830b3d84c9b9a0 Mon Sep 17 00:00:00 2001 From: Cristian Ferretti Date: Tue, 25 Jun 2024 15:41:05 -0400 Subject: [PATCH] etcdctl: add support for filtering by {min,max} x {create,mod} x {revision}. Signed-off-by: Cristian Ferretti --- etcdctl/README.md | 8 +++++ etcdctl/ctlv3/command/get_command.go | 44 +++++++++++++++++++++------- 2 files changed, 42 insertions(+), 10 deletions(-) diff --git a/etcdctl/README.md b/etcdctl/README.md index 1a9ce3ebd69d..40e93c4d1c02 100644 --- a/etcdctl/README.md +++ b/etcdctl/README.md @@ -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, ``` diff --git a/etcdctl/ctlv3/command/get_command.go b/etcdctl/ctlv3/command/get_command.go index 86f281177a90..5b233bdb0be5 100644 --- a/etcdctl/ctlv3/command/get_command.go +++ b/etcdctl/ctlv3/command/get_command.go @@ -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". @@ -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 @@ -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 }