Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: add a flag of pouchd to specify whether enable CRI #1118

Merged
merged 1 commit into from
Apr 12, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
IsCriEnabled bool `json:"enable-cri,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.IsCriEnabled {
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.IsCriEnabled, "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