-
Notifications
You must be signed in to change notification settings - Fork 153
/
server.go
66 lines (55 loc) · 1.75 KB
/
server.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package server
import (
"context"
"fmt"
"github.com/go-logr/logr"
"github.com/grpc-ecosystem/grpc-gateway/v2/runtime"
"github.com/weaveworks/weave-gitops/core/clustersmngr"
"github.com/weaveworks/weave-gitops/core/nsaccess"
pb "github.com/weaveworks/weave-gitops/pkg/api/core"
"k8s.io/client-go/rest"
)
func Hydrate(ctx context.Context, mux *runtime.ServeMux, cfg CoreServerConfig) error {
appsServer, err := NewCoreServer(cfg)
if err != nil {
return fmt.Errorf("unable to create new kube client: %w", err)
}
if err = pb.RegisterCoreHandlerServer(ctx, mux, appsServer); err != nil {
return fmt.Errorf("could not register new app server: %w", err)
}
return nil
}
const temporarilyEmptyAppName = ""
type coreServer struct {
pb.UnimplementedCoreServer
logger logr.Logger
nsChecker nsaccess.Checker
clientsFactory clustersmngr.ClientsFactory
primaryKinds *PrimaryKinds
}
type CoreServerConfig struct {
log logr.Logger
RestCfg *rest.Config
clusterName string
NSAccess nsaccess.Checker
ClientsFactory clustersmngr.ClientsFactory
PrimaryKinds *PrimaryKinds
}
func NewCoreConfig(log logr.Logger, cfg *rest.Config, clusterName string, clusterClientFactory clustersmngr.ClientsFactory) CoreServerConfig {
return CoreServerConfig{
log: log.WithName("core-server"),
RestCfg: cfg,
clusterName: clusterName,
NSAccess: nsaccess.NewChecker(nsaccess.DefautltWegoAppRules),
ClientsFactory: clusterClientFactory,
PrimaryKinds: DefaultPrimaryKinds(),
}
}
func NewCoreServer(cfg CoreServerConfig) (pb.CoreServer, error) {
return &coreServer{
logger: cfg.log,
nsChecker: cfg.NSAccess,
clientsFactory: cfg.ClientsFactory,
primaryKinds: cfg.PrimaryKinds,
}, nil
}