blob: f095f2fa317f6ec03b25592a51c80917e1725145 [file] [log] [blame]
Serge Bazanski6dff6d62022-01-28 18:15:14 +01001package roleserve
2
3import (
4 "context"
5
6 "source.monogon.dev/metropolis/pkg/event"
7 "source.monogon.dev/metropolis/pkg/event/memory"
8 cpb "source.monogon.dev/metropolis/proto/common"
9)
10
11type localRolesValue struct {
12 value memory.Value
13}
14
15func (c *localRolesValue) Watch() *localRolesWatcher {
16 return &localRolesWatcher{
17 Watcher: c.value.Watch(),
18 }
19}
20
21func (c *localRolesValue) set(v *cpb.NodeRoles) {
22 c.value.Set(v)
23}
24
25type localRolesWatcher struct {
26 event.Watcher
27}
28
29// Get retrieves the roles assigned to the local node by the cluster.
30func (c *localRolesWatcher) Get(ctx context.Context) (*cpb.NodeRoles, error) {
31 v, err := c.Watcher.Get(ctx)
32 if err != nil {
33 return nil, err
34 }
35 return v.(*cpb.NodeRoles), nil
36}