-
Notifications
You must be signed in to change notification settings - Fork 949
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
29 changed files
with
31,818 additions
and
84 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
package cri | ||
|
||
import ( | ||
criv1alpha1 "github.com/alibaba/pouch/cri/v1alpha1" | ||
servicev1alpha1 "github.com/alibaba/pouch/cri/v1alpha1/service" | ||
criv1alpha2 "github.com/alibaba/pouch/cri/v1alpha2" | ||
servicev1alpha2 "github.com/alibaba/pouch/cri/v1alpha2/service" | ||
"github.com/alibaba/pouch/daemon/config" | ||
"github.com/alibaba/pouch/daemon/mgr" | ||
|
||
"github.com/sirupsen/logrus" | ||
) | ||
|
||
// RunCriService start cri service if pouchd is specified with --enable-cri. | ||
func RunCriService(daemonconfig *config.Config, containerMgr mgr.ContainerMgr, imageMgr mgr.ImageMgr, stopCh chan error) { | ||
var err error | ||
|
||
defer func() { | ||
stopCh <- err | ||
close(stopCh) | ||
}() | ||
if !daemonconfig.IsCriEnabled { | ||
return | ||
} | ||
switch daemonconfig.CriConfig.CriVersion { | ||
case "v1alpha1": | ||
runv1alpha1(daemonconfig, containerMgr, imageMgr) | ||
case "v1alpha2": | ||
runv1alpha2(daemonconfig, containerMgr, imageMgr) | ||
} | ||
return | ||
} | ||
|
||
func runv1alpha1(daemonconfig *config.Config, containerMgr mgr.ContainerMgr, imageMgr mgr.ImageMgr) { | ||
criMgr, err := criv1alpha1.NewCriManager(daemonconfig, containerMgr, imageMgr) | ||
if err != nil { | ||
return | ||
} | ||
|
||
service, err := servicev1alpha1.NewService(daemonconfig, criMgr) | ||
if err != nil { | ||
return | ||
} | ||
|
||
grpcServerCloseCh := make(chan struct{}) | ||
go func() { | ||
if err := service.Serve(); err != nil { | ||
logrus.Errorf("failed to start grpc server: %v", err) | ||
} | ||
close(grpcServerCloseCh) | ||
}() | ||
|
||
streamServerCloseCh := make(chan struct{}) | ||
go func() { | ||
if err := criMgr.StreamServerStart(); err != nil { | ||
logrus.Errorf("failed to start stream server: %v", err) | ||
} | ||
close(streamServerCloseCh) | ||
}() | ||
|
||
<-streamServerCloseCh | ||
logrus.Infof("CRI Stream server stopped") | ||
<-grpcServerCloseCh | ||
logrus.Infof("CRI GRPC server stopped") | ||
|
||
logrus.Infof("CRI service stopped") | ||
return | ||
} | ||
|
||
func runv1alpha2(daemonconfig *config.Config, containerMgr mgr.ContainerMgr, imageMgr mgr.ImageMgr) { | ||
criMgr, err := criv1alpha2.NewCriManager(daemonconfig, containerMgr, imageMgr) | ||
if err != nil { | ||
return | ||
} | ||
|
||
service, err := servicev1alpha2.NewService(daemonconfig, criMgr) | ||
if err != nil { | ||
return | ||
} | ||
|
||
grpcServerCloseCh := make(chan struct{}) | ||
go func() { | ||
if err := service.Serve(); err != nil { | ||
logrus.Errorf("failed to start grpc server: %v", err) | ||
} | ||
close(grpcServerCloseCh) | ||
}() | ||
|
||
streamServerCloseCh := make(chan struct{}) | ||
go func() { | ||
if err := criMgr.StreamServerStart(); err != nil { | ||
logrus.Errorf("failed to start stream server: %v", err) | ||
} | ||
close(streamServerCloseCh) | ||
}() | ||
|
||
<-streamServerCloseCh | ||
logrus.Infof("CRI Stream server stopped") | ||
<-grpcServerCloseCh | ||
logrus.Infof("CRI GRPC server stopped") | ||
|
||
logrus.Infof("CRI service stopped") | ||
return | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package src | ||
package v1alpha1 | ||
|
||
import ( | ||
"fmt" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package src | ||
package v1alpha1 | ||
|
||
import ( | ||
"k8s.io/kubernetes/pkg/kubelet/apis/cri/v1alpha1/runtime" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package src | ||
package v1alpha1 | ||
|
||
import ( | ||
"bytes" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package src | ||
package v1alpha1 | ||
|
||
import ( | ||
"fmt" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package src | ||
package v1alpha1 | ||
|
||
import ( | ||
"github.com/sirupsen/logrus" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package service | ||
|
||
import ( | ||
"net" | ||
"os" | ||
"syscall" | ||
|
||
cri "github.com/alibaba/pouch/cri/v1alpha1" | ||
"github.com/alibaba/pouch/daemon/config" | ||
|
||
"google.golang.org/grpc" | ||
"k8s.io/kubernetes/pkg/kubelet/apis/cri/v1alpha1/runtime" | ||
) | ||
|
||
// 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, | ||
} | ||
|
||
// TODO: Prepare streaming server. | ||
|
||
runtime.RegisterRuntimeServiceServer(s.server, s.criMgr) | ||
runtime.RegisterImageServiceServer(s.server, s.criMgr) | ||
|
||
return s, nil | ||
} | ||
|
||
// Serve starts grpc server. | ||
func (s *Service) Serve() error { | ||
// Unlink to cleanup the previous socket file. | ||
if err := syscall.Unlink(s.config.CriConfig.Listen); err != nil && !os.IsNotExist(err) { | ||
return err | ||
} | ||
|
||
l, err := net.Listen("unix", s.config.CriConfig.Listen) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return s.server.Serve(l) | ||
} |
Oops, something went wrong.