Skip to content

Commit

Permalink
feature: add a flag of pouchd to specify whether enable CRI
Browse files Browse the repository at this point in the history
Signed-off-by: YaoZengzeng <yaozengzeng@zju.edu.cn>
  • Loading branch information
YaoZengzeng committed Apr 12, 2018
1 parent e143482 commit 921d9bc
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 31 deletions.
3 changes: 3 additions & 0 deletions daemon/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ type Config struct {
// Network config
NetworkConfg network.Config

// Whether enable cri manager.
CriEnabled bool `json:"cri-enabled,omitempty"`

// CRI config.
CriConfig cri.Config

Expand Down
86 changes: 56 additions & 30 deletions daemon/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,17 +167,6 @@ func (d *Daemon) Run() error {
}
d.containerMgr = containerMgr

criMgr, err := internal.GenCriMgr(d)
if err != nil {
return err
}
d.criMgr = criMgr

d.criService, err = cri.NewService(d.config, criMgr)
if err != nil {
return err
}

d.server = server.Server{
Config: d.config,
ContainerMgr: containerMgr,
Expand Down Expand Up @@ -205,29 +194,17 @@ func (d *Daemon) Run() error {
close(httpServerCloseCh)
}()

grpcServerCloseCh := make(chan struct{})
go func() {
if err := d.criService.Serve(); err != nil {
logrus.Errorf("failed to start grpc server: %v", err)
}
close(grpcServerCloseCh)
}()
criStopCh := make(chan error)
go d.RunCriService(criStopCh)

streamServerCloseCh := make(chan struct{})
go func() {
if d.criMgr.StreamServerStart(); err != nil {
logrus.Errorf("failed to start stream server: %v", err)
}
close(streamServerCloseCh)
}()
err = <-criStopCh
if err != nil {
return err
}

// Stop pouchd if both server stopped.
// Stop pouchd if the server stopped
<-httpServerCloseCh
logrus.Infof("HTTP server stopped")
<-grpcServerCloseCh
logrus.Infof("GRPC server stopped")
<-streamServerCloseCh
logrus.Infof("Stream server stopped")

return nil
}
Expand Down Expand Up @@ -291,3 +268,52 @@ func (d *Daemon) ShutdownPlugin() error {
}
return nil
}

// RunCriService start cri service if pouchd is specified with --enable-cri.
func (d *Daemon) RunCriService(stopCh chan error) {
var err error

defer func() {
stopCh <- err
close(stopCh)
}()

if !d.config.CriEnabled {
return
}

criMgr, err := internal.GenCriMgr(d)
if err != nil {
return
}
d.criMgr = criMgr

d.criService, err = cri.NewService(d.config, criMgr)
if err != nil {
return
}

grpcServerCloseCh := make(chan struct{})
go func() {
if err := d.criService.Serve(); err != nil {
logrus.Errorf("failed to start grpc server: %v", err)
}
close(grpcServerCloseCh)
}()

streamServerCloseCh := make(chan struct{})
go func() {
if err := d.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
}
2 changes: 1 addition & 1 deletion hack/cri-test/test-utils.sh
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ test_setup() {
pouch_pid_command=`pgrep pouchd`
pouch_pid=${pouch_pid_command}
if [ ! -n "${pouch_pid}" ]; then
keepalive "pouchd ${POUCH_FLAGS}" \
keepalive "pouchd --enable-cri ${POUCH_FLAGS}" \
${RESTART_WAIT_PERIOD} &> ${report_dir}/pouch.log &
pouch_pid=$!
fi
Expand Down
1 change: 1 addition & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ func setupFlags(cmd *cobra.Command) {

flagSet.StringVar(&cfg.HomeDir, "home-dir", "/var/lib/pouch", "Specify root dir of pouchd")
flagSet.StringArrayVarP(&cfg.Listen, "listen", "l", []string{"unix:///var/run/pouchd.sock"}, "Specify listening addresses of Pouchd")
flagSet.BoolVar(&cfg.CriEnabled, "enable-cri", false, "Specify whether enable the cri part of pouchd which is used to support Kubernetes")
flagSet.StringVar(&cfg.CriConfig.Listen, "listen-cri", "/var/run/pouchcri.sock", "Specify listening address of CRI")
flagSet.StringVar(&cfg.CriConfig.NetworkPluginBinDir, "cni-bin-dir", "/opt/cni/bin", "The directory for putting cni plugin binaries.")
flagSet.StringVar(&cfg.CriConfig.NetworkPluginConfDir, "cni-conf-dir", "/etc/cni/net.d", "The directory for putting cni plugin configuration files.")
Expand Down

0 comments on commit 921d9bc

Please sign in to comment.