blob: fda776c1b58c68c30aa47f48f0aa646b05527660 [file] [log] [blame]
Tim Windelschmidt6d33a432025-02-04 14:34:25 +01001// Copyright The Monogon Project Authors.
2// SPDX-License-Identifier: Apache-2.0
3
Serge Bazanskife3d8fd2023-05-30 20:50:09 +02004package roleserve
5
6import (
Serge Bazanskife3d8fd2023-05-30 20:50:09 +02007 "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 Bazanskife3d8fd2023-05-30 20:50:09 +020015)
16
Serge Bazanskife3d8fd2023-05-30 20:50:09 +020017// 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.
24type localControlPlane struct {
25 consensus *consensus.Service
26 curator *curator.Service
27}
28
29func (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 Bazanskib2d6c332024-09-03 12:18:24 +020048type CuratorConnection struct {
49 Credentials *identity.NodeCredentials
Serge Bazanskife3d8fd2023-05-30 20:50:09 +020050 resolver *resolver.Resolver
51 conn *grpc.ClientConn
52}
53
Serge Bazanskib2d6c332024-09-03 12:18:24 +020054func newCuratorConnection(creds *identity.NodeCredentials, res *resolver.Resolver) *CuratorConnection {
Serge Bazanskife3d8fd2023-05-30 20:50:09 +020055 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 Bazanskib2d6c332024-09-03 12:18:24 +020061 return &CuratorConnection{
62 Credentials: creds,
Serge Bazanskife3d8fd2023-05-30 20:50:09 +020063 resolver: res,
64 conn: conn,
65 }
66}
67
Serge Bazanskib2d6c332024-09-03 12:18:24 +020068func (c *CuratorConnection) nodeID() string {
Jan Schär39d9c242024-09-24 13:49:55 +020069 return c.Credentials.ID()
Serge Bazanskife3d8fd2023-05-30 20:50:09 +020070}
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).
75type KubernetesStatus struct {
76 Controller *kubernetes.Controller
77}