metropolis/node/core/cluster: use curator
This refactors the cluster manager. It removes all etcd storage
functionality (which now lives in the curator) and otherwise dusts
things off slightly (some file renames, some comments to reflect the now
clarified and limited scope of the cluster manager).
Change-Id: Ic62d8402c0618fb5e0e65966b0d732a2cab564e0
Reviewed-on: https://review.monogon.dev/c/monogon/+/188
Reviewed-by: Lorenz Brun <lorenz@nexantic.com>
diff --git a/metropolis/node/core/cluster/watcher.go b/metropolis/node/core/cluster/watcher.go
new file mode 100644
index 0000000..1251f2d
--- /dev/null
+++ b/metropolis/node/core/cluster/watcher.go
@@ -0,0 +1,46 @@
+package cluster
+
+import (
+ "context"
+ "fmt"
+
+ "source.monogon.dev/metropolis/pkg/event"
+ cpb "source.monogon.dev/metropolis/proto/common"
+)
+
+type Watcher struct {
+ event.Watcher
+}
+
+func (w *Watcher) Get(ctx context.Context) (*Status, error) {
+ val, err := w.Watcher.Get(ctx)
+ if err != nil {
+ return nil, err
+ }
+ status := val.(Status)
+ return &status, err
+}
+
+// GetHome waits until the cluster, from the point of view of this node, is in
+// the ClusterHome state. This can be used to wait for the cluster manager to
+// 'settle', before clients start more node services.
+func (w *Watcher) GetHome(ctx context.Context) (*Status, error) {
+ for {
+ status, err := w.Get(ctx)
+ if err != nil {
+ return nil, err
+ }
+ switch status.State {
+ case cpb.ClusterState_CLUSTER_STATE_HOME:
+ return status, nil
+ case cpb.ClusterState_CLUSTER_STATE_DISOWNING:
+ return nil, fmt.Errorf("the cluster has disowned this node")
+ }
+ }
+}
+
+func (m *Manager) Watch() Watcher {
+ return Watcher{
+ Watcher: m.status.Watch(),
+ }
+}