Skip to content

etcdctl: add --from-key to watch command - #22383

Open
avanish-garg wants to merge 1 commit into
etcd-io:mainfrom
avanish-garg:feature/etcdctl-watch-from-key
Open

etcdctl: add --from-key to watch command#22383
avanish-garg wants to merge 1 commit into
etcd-io:mainfrom
avanish-garg:feature/etcdctl-watch-from-key

Conversation

@avanish-garg

Copy link
Copy Markdown

Fixes #22381

Problem

etcdctl get and etcdctl del both support --from-key (watch/get/delete all keys that
are byte-wise >= the given key), but etcdctl watch doesn't -- it can only watch an exact
key or a --prefix.

Change

  • Added a --from-key flag to the watch command, mirroring the exact pattern already
    used by get/del (etcdctl/ctlv3/command/get_command.go, del_command.go).
  • Added the same --prefix/--from-key mutual-exclusion check get/del already have.
  • Updated the interactive-mode flag reset/reparse paths so --from-key behaves the same
    as the existing --prefix flag across repeated interactive watch invocations.
  • Added an e2e test case in tests/e2e/ctl_v3_watch_test.go mirroring the existing
    --prefix test case, run against a real spawned etcd server with the built CLI.

The server already fully implements this for Watch requests: WithFromKey()'s sentinel
value (RangeEnd = []byte{0}) is already handled in
server/etcdserver/api/v3rpc/watch.go with a comment saying "support >= key queries",
and the client library (clientv3.WithFromKey()) already documents itself as applying to
'Get', 'Delete', 'Watch'. So this PR is purely additive CLI wiring -- no server or client
library changes needed.

Verified: go build ./..., go vet ./etcdctl/... clean, existing Test_parseWatchArgs
unit test still passes, new e2e test (TestCtlV3Watch) passes against a real spawned
server running the actual built etcdctl binary.

'get' and 'del' already support --from-key (watch keys >= the given key,
byte-wise), via clientv3.WithFromKey(). The server already fully
implements this for Watch too (see the RangeEnd sentinel handling in
server/etcdserver/api/v3rpc/watch.go), and the client library already
wires it through -- only the etcdctl 'watch' command itself was missing
the flag.

Signed-off-by: Avanish Garg <gargavanish@gmail.com>
@kubernetes-prow

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: avanish-garg
Once this PR has been reviewed and has the lgtm label, please assign jmhbnz for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@kubernetes-prow

Copy link
Copy Markdown

Hi @avanish-garg. Thanks for your PR.

I'm waiting for a etcd-io member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work.

Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@avanish-garg

Copy link
Copy Markdown
Author

cc @ptabor @fuweid — both of you have prior commits in watch_command.go (the file this PR touches), so tagging in case this area is useful for you to look at. Also, this PR is gated behind needs-ok-to-test — would appreciate an /ok-to-test if it looks reasonable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

etcdctl watch --from-key

1 participant