blob: 91510aedf4be8fcbb1fe29c1b2fd2a2e8c20c996 [file] [log] [blame]
Serge Bazanskife3d8fd2023-05-30 20:50:09 +02001package roleserve
2
3import (
Serge Bazanskife3d8fd2023-05-30 20:50:09 +02004 "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 Bazanskife3d8fd2023-05-30 20:50:09 +020012)
13
Serge Bazanskife3d8fd2023-05-30 20:50:09 +020014// 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.
21type localControlPlane struct {
22 consensus *consensus.Service
23 curator *curator.Service
24}
25
26func (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.
45type curatorConnection struct {
46 credentials *identity.NodeCredentials
47 resolver *resolver.Resolver
48 conn *grpc.ClientConn
49}
50
51func newCuratorConnection(creds *identity.NodeCredentials, res *resolver.Resolver) *curatorConnection {
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 }
58 return &curatorConnection{
59 credentials: creds,
60 resolver: res,
61 conn: conn,
62 }
63}
64
65func (c *curatorConnection) nodeID() string {
66 return identity.NodeID(c.credentials.PublicKey())
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).
72type KubernetesStatus struct {
73 Controller *kubernetes.Controller
74}