mirror of https://github.com/k3s-io/k3s
Factor out etcdWatcher to a separate file
parent
dde72229dc
commit
db5f6eae6c
|
@ -163,7 +163,7 @@ resource type. However, this watch can potentially expire at any time and
|
|||
reconnecting can return "too old resource version". In that case relisting is
|
||||
necessary. In such case, to avoid LIST requests coming from all watchers at
|
||||
the same time, we can introduce an additional etcd event type:
|
||||
[EtcdResync](../../pkg/tools/etcd_helper_watch.go#L36)
|
||||
[EtcdResync](../../pkg/tools/etcd_watcher.go#L36)
|
||||
|
||||
Whenever reslisting will be done to refresh the internal watch to etcd,
|
||||
EtcdResync event will be send to all the watchers. It will contain the
|
||||
|
|
|
@ -29,6 +29,7 @@ import (
|
|||
"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/tools/metrics"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/watch"
|
||||
"github.com/coreos/go-etcd/etcd"
|
||||
|
||||
"github.com/golang/glog"
|
||||
|
@ -176,6 +177,22 @@ func (h *etcdHelper) Delete(key string, recursive bool) error {
|
|||
return err
|
||||
}
|
||||
|
||||
// Implements StorageInterface.
|
||||
func (h *etcdHelper) Watch(key string, resourceVersion uint64, filter FilterFunc) (watch.Interface, error) {
|
||||
key = h.prefixEtcdKey(key)
|
||||
w := newEtcdWatcher(false, nil, filter, h.codec, h.versioner, nil, h)
|
||||
go w.etcdWatch(h.client, key, resourceVersion)
|
||||
return w, nil
|
||||
}
|
||||
|
||||
// Implements StorageInterface.
|
||||
func (h *etcdHelper) WatchList(key string, resourceVersion uint64, filter FilterFunc) (watch.Interface, error) {
|
||||
key = h.prefixEtcdKey(key)
|
||||
w := newEtcdWatcher(true, exceptKey(key), filter, h.codec, h.versioner, nil, h)
|
||||
go w.etcdWatch(h.client, key, resourceVersion)
|
||||
return w, nil
|
||||
}
|
||||
|
||||
// Implements StorageInterface.
|
||||
func (h *etcdHelper) ExtractObj(key string, objPtr runtime.Object, ignoreNotFound bool) error {
|
||||
key = h.prefixEtcdKey(key)
|
||||
|
|
|
@ -66,27 +66,6 @@ func ParseWatchResourceVersion(resourceVersion, kind string) (uint64, error) {
|
|||
return version + 1, nil
|
||||
}
|
||||
|
||||
// WatchList begins watching the specified key's items. Items are decoded into
|
||||
// API objects, and any items passing 'filter' are sent down the returned
|
||||
// watch.Interface. resourceVersion may be used to specify what version to begin
|
||||
// watching (e.g., for reconnecting without missing any updates).
|
||||
func (h *etcdHelper) WatchList(key string, resourceVersion uint64, filter FilterFunc) (watch.Interface, error) {
|
||||
key = h.prefixEtcdKey(key)
|
||||
w := newEtcdWatcher(true, exceptKey(key), filter, h.codec, h.versioner, nil, h)
|
||||
go w.etcdWatch(h.client, key, resourceVersion)
|
||||
return w, nil
|
||||
}
|
||||
|
||||
// Watch begins watching the specified key. Events are decoded into
|
||||
// API objects and sent down the returned watch.Interface.
|
||||
// Errors will be sent down the channel.
|
||||
func (h *etcdHelper) Watch(key string, resourceVersion uint64, filter FilterFunc) (watch.Interface, error) {
|
||||
key = h.prefixEtcdKey(key)
|
||||
w := newEtcdWatcher(false, nil, filter, h.codec, h.versioner, nil, h)
|
||||
go w.etcdWatch(h.client, key, resourceVersion)
|
||||
return w, nil
|
||||
}
|
||||
|
||||
// TransformFunc attempts to convert an object to another object for use with a watcher.
|
||||
type TransformFunc func(runtime.Object) (runtime.Object, error)
|
||||
|
Loading…
Reference in New Issue