| Tim Windelschmidt | 6d33a43 | 2025-02-04 14:34:25 +0100 | [diff] [blame] | 1 | // Copyright The Monogon Project Authors. |
| 2 | // SPDX-License-Identifier: Apache-2.0 |
| 3 | |
| Serge Bazanski | fe3d8fd | 2023-05-30 20:50:09 +0200 | [diff] [blame] | 4 | package roleserve |
| 5 | |
| 6 | import ( |
| Serge Bazanski | fe3d8fd | 2023-05-30 20:50:09 +0200 | [diff] [blame] | 7 | "google.golang.org/grpc" |
| 8 | |
| 9 | "source.monogon.dev/metropolis/node/core/consensus" |
| 10 | "source.monogon.dev/metropolis/node/core/curator" |
| 11 | "source.monogon.dev/metropolis/node/core/identity" |
| 12 | "source.monogon.dev/metropolis/node/core/rpc" |
| 13 | "source.monogon.dev/metropolis/node/core/rpc/resolver" |
| 14 | "source.monogon.dev/metropolis/node/kubernetes" |
| Serge Bazanski | fe3d8fd | 2023-05-30 20:50:09 +0200 | [diff] [blame] | 15 | ) |
| 16 | |
| Serge Bazanski | fe3d8fd | 2023-05-30 20:50:09 +0200 | [diff] [blame] | 17 | // localControlPlane is an internal EventValue structure which carries |
| 18 | // information about whether the node has a locally running consensus and curator |
| 19 | // service. When it does, the structure pointer inside the EventValue will be |
| 20 | // non-nil and its consensus and curator members will also be non-nil. If it |
| 21 | // doesn't, either the pointer inside the EventValue will be nil, or will carry |
| 22 | // nil pointers. Because of this, it is recommended to use the exists() method to |
| 23 | // check for consensus/curator presence. |
| 24 | type localControlPlane struct { |
| 25 | consensus *consensus.Service |
| 26 | curator *curator.Service |
| 27 | } |
| 28 | |
| 29 | func (l *localControlPlane) exists() bool { |
| 30 | if l == nil { |
| 31 | return false |
| 32 | } |
| 33 | if l.consensus == nil || l.curator == nil { |
| 34 | return false |
| 35 | } |
| 36 | return true |
| 37 | } |
| 38 | |
| 39 | // CuratorConnection carries information about the node having successfully |
| 40 | // established connectivity to its cluster's control plane. |
| 41 | // |
| 42 | // It carries inside it a single gRPC client connection which is built using the |
| 43 | // main roleserver resolver. This connection will automatically use any available |
| 44 | // curator, whether running locally or remotely. |
| 45 | // |
| 46 | // This structure should also be used by roleserver runnables that simply wish to |
| 47 | // access the node's credentials. |
| Serge Bazanski | b2d6c33 | 2024-09-03 12:18:24 +0200 | [diff] [blame] | 48 | type CuratorConnection struct { |
| 49 | Credentials *identity.NodeCredentials |
| Serge Bazanski | fe3d8fd | 2023-05-30 20:50:09 +0200 | [diff] [blame] | 50 | resolver *resolver.Resolver |
| 51 | conn *grpc.ClientConn |
| 52 | } |
| 53 | |
| Serge Bazanski | b2d6c33 | 2024-09-03 12:18:24 +0200 | [diff] [blame] | 54 | func newCuratorConnection(creds *identity.NodeCredentials, res *resolver.Resolver) *CuratorConnection { |
| Serge Bazanski | fe3d8fd | 2023-05-30 20:50:09 +0200 | [diff] [blame] | 55 | c := rpc.NewAuthenticatedCredentials(creds.TLSCredentials(), rpc.WantRemoteCluster(creds.ClusterCA())) |
| 56 | conn, err := grpc.Dial(resolver.MetropolisControlAddress, grpc.WithTransportCredentials(c), grpc.WithResolvers(res)) |
| 57 | if err != nil { |
| 58 | // TOOD(q3k): triple check that Dial will not fail |
| 59 | panic(err) |
| 60 | } |
| Serge Bazanski | b2d6c33 | 2024-09-03 12:18:24 +0200 | [diff] [blame] | 61 | return &CuratorConnection{ |
| 62 | Credentials: creds, |
| Serge Bazanski | fe3d8fd | 2023-05-30 20:50:09 +0200 | [diff] [blame] | 63 | resolver: res, |
| 64 | conn: conn, |
| 65 | } |
| 66 | } |
| 67 | |
| Serge Bazanski | b2d6c33 | 2024-09-03 12:18:24 +0200 | [diff] [blame] | 68 | func (c *CuratorConnection) nodeID() string { |
| Jan Schär | 39d9c24 | 2024-09-24 13:49:55 +0200 | [diff] [blame] | 69 | return c.Credentials.ID() |
| Serge Bazanski | fe3d8fd | 2023-05-30 20:50:09 +0200 | [diff] [blame] | 70 | } |
| 71 | |
| 72 | // KubernetesStatus is an Event Value structure populated by a running |
| 73 | // Kubernetes instance. It allows external services to access the Kubernetes |
| 74 | // Service whenever available (ie. enabled and started by the Role Server). |
| 75 | type KubernetesStatus struct { |
| 76 | Controller *kubernetes.Controller |
| 77 | } |