| Serge Bazanski | 6dff6d6 | 2022-01-28 18:15:14 +0100 | [diff] [blame] | 1 | package roleserve |
| 2 | |
| 3 | import ( |
| 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 | |
| 11 | type localRolesValue struct { |
| 12 | value memory.Value |
| 13 | } |
| 14 | |
| 15 | func (c *localRolesValue) Watch() *localRolesWatcher { |
| 16 | return &localRolesWatcher{ |
| 17 | Watcher: c.value.Watch(), |
| 18 | } |
| 19 | } |
| 20 | |
| 21 | func (c *localRolesValue) set(v *cpb.NodeRoles) { |
| 22 | c.value.Set(v) |
| 23 | } |
| 24 | |
| 25 | type localRolesWatcher struct { |
| 26 | event.Watcher |
| 27 | } |
| 28 | |
| 29 | // Get retrieves the roles assigned to the local node by the cluster. |
| 30 | func (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 | } |