From db5f6eae6c5f6367c9383f3cd7a5da422bf0803d Mon Sep 17 00:00:00 2001 From: Wojciech Tyczynski Date: Mon, 27 Jul 2015 09:54:07 +0200 Subject: [PATCH] Factor out etcdWatcher to a separate file --- docs/proposals/apiserver_watch.md | 2 +- pkg/tools/etcd_helper.go | 17 +++++++++++++++ .../{etcd_helper_watch.go => etcd_watcher.go} | 21 ------------------- ...per_watch_test.go => etcd_watcher_test.go} | 0 4 files changed, 18 insertions(+), 22 deletions(-) rename pkg/tools/{etcd_helper_watch.go => etcd_watcher.go} (92%) rename pkg/tools/{etcd_helper_watch_test.go => etcd_watcher_test.go} (100%) diff --git a/docs/proposals/apiserver_watch.md b/docs/proposals/apiserver_watch.md index 10ae98f1ea..ce866b6d68 100644 --- a/docs/proposals/apiserver_watch.md +++ b/docs/proposals/apiserver_watch.md @@ -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 diff --git a/pkg/tools/etcd_helper.go b/pkg/tools/etcd_helper.go index 6334ce6d12..7132ce8dd1 100644 --- a/pkg/tools/etcd_helper.go +++ b/pkg/tools/etcd_helper.go @@ -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) diff --git a/pkg/tools/etcd_helper_watch.go b/pkg/tools/etcd_watcher.go similarity index 92% rename from pkg/tools/etcd_helper_watch.go rename to pkg/tools/etcd_watcher.go index 780d9239b3..ab1ac597b8 100644 --- a/pkg/tools/etcd_helper_watch.go +++ b/pkg/tools/etcd_watcher.go @@ -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) diff --git a/pkg/tools/etcd_helper_watch_test.go b/pkg/tools/etcd_watcher_test.go similarity index 100% rename from pkg/tools/etcd_helper_watch_test.go rename to pkg/tools/etcd_watcher_test.go