Skip to content

Commit 3c3fc80

Browse files
authored
Merge pull request kubernetes#89881 from embano1/etcd-leader-ctx
Add etcd WithRequireLeader option to API watches
2 parents 0926c9c + 70c9f77 commit 3c3fc80

File tree

1 file changed

+9
-1
lines changed
  • staging/src/k8s.io/apiserver/pkg/storage/etcd3

1 file changed

+9
-1
lines changed

staging/src/k8s.io/apiserver/pkg/storage/etcd3/watcher.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,15 @@ func (w *watcher) createWatchChan(ctx context.Context, key string, rev int64, re
126126
// The filter doesn't filter out any object.
127127
wc.internalPred = storage.Everything
128128
}
129-
wc.ctx, wc.cancel = context.WithCancel(ctx)
129+
130+
// The etcd server waits until it cannot find a leader for 3 election
131+
// timeouts to cancel existing streams. 3 is currently a hard coded
132+
// constant. The election timeout defaults to 1000ms. If the cluster is
133+
// healthy, when the leader is stopped, the leadership transfer should be
134+
// smooth. (leader transfers its leadership before stopping). If leader is
135+
// hard killed, other servers will take an election timeout to realize
136+
// leader lost and start campaign.
137+
wc.ctx, wc.cancel = context.WithCancel(clientv3.WithRequireLeader(ctx))
130138
return wc
131139
}
132140

0 commit comments

Comments
 (0)