-
Notifications
You must be signed in to change notification settings - Fork 120
/
k8s.go
59 lines (46 loc) · 1.17 KB
/
k8s.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
package k8s
// <!-- START clutchdoc -->
// description: Endpoints for interacting with Kubernetes resources.
// <!-- END clutchdoc -->
import (
"errors"
"github.com/golang/protobuf/ptypes/any"
"github.com/uber-go/tally/v4"
"go.uber.org/zap"
k8sv1 "github.com/lyft/clutch/backend/api/k8s/v1"
"github.com/lyft/clutch/backend/module"
"github.com/lyft/clutch/backend/service"
k8sservice "github.com/lyft/clutch/backend/service/k8s"
)
const (
Name = "clutch.module.k8s"
)
func New(*any.Any, *zap.Logger, tally.Scope) (module.Module, error) {
client, ok := service.Registry["clutch.service.k8s"]
if !ok {
return nil, errors.New("could not find service")
}
svc, ok := client.(k8sservice.Service)
if !ok {
return nil, errors.New("service was not the correct type")
}
mod := &mod{
k8s: newK8sAPI(svc),
}
return mod, nil
}
type mod struct {
k8s k8sv1.K8SAPIServer
}
func (m *mod) Register(r module.Registrar) error {
k8sv1.RegisterK8SAPIServer(r.GRPCServer(), m.k8s)
return r.RegisterJSONGateway(k8sv1.RegisterK8SAPIHandler)
}
type k8sAPI struct {
k8s k8sservice.Service
}
func newK8sAPI(svc k8sservice.Service) k8sv1.K8SAPIServer {
return &k8sAPI{
k8s: svc,
}
}