m/pkg/event: split out ValueWatch from Value
Summary:
This implements a small TODO, letting the etcd Value implementation only
implement the Watch part of the interface.
Test Plan: Refactor.
Change-Id: I9ccd73ce4d165182d9588387230e71bcb425ab94
Reviewed-on: https://review.monogon.dev/c/monogon/+/122
Reviewed-by: Lorenz Brun <lorenz@nexantic.com>
diff --git a/metropolis/pkg/event/etcd/etcd.go b/metropolis/pkg/event/etcd/etcd.go
index 041e600..ff40bcd 100644
--- a/metropolis/pkg/event/etcd/etcd.go
+++ b/metropolis/pkg/event/etcd/etcd.go
@@ -14,11 +14,11 @@
)
var (
- // Type assert that *Value implements event.Value. We do this artificially,
- // as there currently is no code path that needs this to be strictly true.
- // However, users of this library might want to rely on the Value type
- // instead of particular Value implementations.
- _ event.Value = &Value{}
+ // Type assert that *Value implements event.ValueWatcher. We do this
+ // artificially, as there currently is no code path that needs this to be
+ // strictly true. However, users of this library might want to rely on the
+ // Value type instead of particular Value implementations.
+ _ event.ValueWatch = &Value{}
)
// Value is an 'Event Value' backed in an etcd cluster, accessed over an
@@ -54,11 +54,6 @@
return data, nil
}
-func (e *Value) Set(val interface{}) {
- // TODO(q3k): split up the Value interface into ValueReader/ValueWriter
- panic("Set is unimplemented on etcd values")
-}
-
func (e *Value) Watch() event.Watcher {
ctx, ctxC := context.WithCancel(context.Background())
return &watcher{
diff --git a/metropolis/pkg/event/event.go b/metropolis/pkg/event/event.go
index d3ea5df..6c40666 100644
--- a/metropolis/pkg/event/event.go
+++ b/metropolis/pkg/event/event.go
@@ -105,6 +105,16 @@
// this should be negotiated and serialized externally by the producers.
Set(val interface{})
+ // ValueWatch implements the Watch method. It is split out into another
+ // interface to allow some 'Event Values' to implement only the watch/read
+ // part, with the write side being implicit or defined by a more complex
+ // interface then a simple Set().
+ ValueWatch
+}
+
+// ValueWatch is the read side of an 'Event Value', witch can by retrieved by
+// Consumers by performing a Watch operation on it.
+type ValueWatch interface {
// Watch retrieves a Watcher that keeps track on the version of the data
// contained within the Value that was last seen by a consumer. Once a
// Watcher is retrieved, it can be used to then get the actual data stored