forked from AliyunContainerService/pouch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cri.go
42 lines (34 loc) · 990 Bytes
/
cri.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
package service
import (
runtime "github.com/alibaba/pouch/cri/apis/v1alpha2"
cri "github.com/alibaba/pouch/cri/v1alpha2"
"github.com/alibaba/pouch/daemon/config"
"github.com/alibaba/pouch/pkg/netutils"
"google.golang.org/grpc"
)
// Service serves the kubelet runtime grpc api which will be consumed by kubelet.
type Service struct {
config *config.Config
server *grpc.Server
criMgr cri.CriMgr
}
// NewService creates a brand new cri service.
func NewService(cfg *config.Config, criMgr cri.CriMgr) (*Service, error) {
s := &Service{
config: cfg,
server: grpc.NewServer(),
criMgr: criMgr,
}
runtime.RegisterRuntimeServiceServer(s.server, s.criMgr)
runtime.RegisterImageServiceServer(s.server, s.criMgr)
runtime.RegisterVolumeServiceServer(s.server, s.criMgr)
return s, nil
}
// Serve starts grpc server.
func (s *Service) Serve() error {
l, err := netutils.GetListener(s.config.CriConfig.Listen, nil)
if err != nil {
return err
}
return s.server.Serve(l)
}