Skip to content

Conversation

@MkDev11
Copy link

@MkDev11 MkDev11 commented Jan 22, 2026

What this PR does

This adds a client-side utility for watching membership changes by polling MemberList() and comparing with the previous state.

Fixes: #5277

Why we need it

Users want to watch for membership changes in etcd v3. Following maintainer feedback, this implements the functionality on the client side rather than adding server complexity.

This approach uses the existing Sync() and MemberList() APIs as suggested by @ahrtr.

Changes

Added single file: client/v3/member_watch.go

  • MemberWatcher struct with configurable poll interval
  • MemberEvent and MemberEventType types
  • Watch() method that returns a channel of membership events

Usage

watcher := clientv3.NewMemberWatcher(client, clientv3.MemberWatchConfig{
    PollInterval: 5 * time.Second,
})

ctx, cancel := context.WithCancel(context.Background())
defer cancel()

for event := range watcher.Watch(ctx, true) {
    switch event.Type {
    case clientv3.MemberAdded:
        fmt.Printf("Member added: %s\n", event.Member.Name)
    case clientv3.MemberRemoved:
        fmt.Printf("Member removed: %s\n", event.Member.Name)
    case clientv3.MemberUpdated:
        fmt.Printf("Member updated: %s\n", event.Member.Name)
    }
}

Event types

Event Triggered when
MemberAdded New member detected in cluster
MemberRemoved Member no longer in cluster
MemberUpdated Member's peer URLs changed

Test Results

$ go run test_member_watcher.go

Connected to etcd
Starting MemberWatcher (polling every 3s)...
Initial members will be sent as MemberAdded events
Waiting 15 seconds for events...

[Event #1] Type: ADDED
  Member ID:    8e9e05c52164694d
  Member Name:  default
  PeerURLs:     [http://localhost:2380]
  ClientURLs:   [http://localhost:2379]
  IsLearner:    false

Watch ended. Total events received: 1

Testing checklist

  • Builds successfully (go build ./client/v3/...)
  • Lint passes
  • Manual testing verified

@k8s-ci-robot
Copy link

Hi @MkDev11. 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.

@MkDev11
Copy link
Author

MkDev11 commented Jan 22, 2026

/assign @MkDev11

This adds a client-side utility for watching membership changes by
polling MemberList() and comparing with the previous state.

This approach follows the maintainer's suggestion to implement member
watching on the client side rather than adding server complexity.

Usage:
  watcher := clientv3.NewMemberWatcher(client, clientv3.MemberWatchConfig{
      PollInterval: 5 * time.Second,
  })
  for event := range watcher.Watch(ctx, true) {
      fmt.Printf("Event: %v, Member: %s\n", event.Type, event.Member.Name)
  }

Event types:
- MemberAdded: new member joined
- MemberRemoved: member was removed
- MemberUpdated: member's peer URLs changed

Fixes: etcd-io#5277

Signed-off-by: MkDev11 <[email protected]>
@MkDev11 MkDev11 force-pushed the feature/member-watch-api branch from 0adc10f to 0ed5093 Compare January 23, 2026 12:50
@k8s-ci-robot
Copy link

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: MkDev11
Once this PR has been reviewed and has the lgtm label, please ask for approval from ahrtr. 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

@MkDev11 MkDev11 changed the title api: add MemberWatch streaming RPC for membership changes client/v3: add MemberWatcher helper for polling-based member changes Jan 23, 2026
@MkDev11
Copy link
Author

MkDev11 commented Jan 23, 2026

@ahrtr could you please have a look at the PR and let me know your feedback? thanks.

@ahrtr
Copy link
Member

ahrtr commented Jan 23, 2026

This approach uses the existing Sync() and MemberList() APIs as suggested by @ahrtr.

Sorry, I should be clearer. The comment #5277 (comment) is just a workaround solution for users reference. I didn't mean to add it into etcd's client SDK.

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.

3 participants