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