-
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.
feature:cri-upgrade and support down-level compatibility
Signed-off-by: Starnop <[email protected]>
- Loading branch information
Showing
30 changed files
with
31,787 additions
and
92 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,114 @@ | ||
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) | ||
default: | ||
logrus.Errorf("invalid CRI version,failed to start CRI service") | ||
} | ||
return | ||
} | ||
|
||
// Start CRI service with CRI version: v1alpha1 | ||
func runv1alpha1(daemonconfig *config.Config, containerMgr mgr.ContainerMgr, imageMgr mgr.ImageMgr) { | ||
logrus.Infof("Start CRI service with CRI version: v1alpha1") | ||
criMgr, err := criv1alpha1.NewCriManager(daemonconfig, containerMgr, imageMgr) | ||
if err != nil { | ||
logrus.Errorf("failed to get CriManager with error: %v", err) | ||
return | ||
} | ||
|
||
service, err := servicev1alpha1.NewService(daemonconfig, criMgr) | ||
if err != nil { | ||
logrus.Errorf("failed to start CRI service with error: %v", err) | ||
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 | ||
} | ||
|
||
// Start CRI service with CRI version: v1alpha2 | ||
func runv1alpha2(daemonconfig *config.Config, containerMgr mgr.ContainerMgr, imageMgr mgr.ImageMgr) { | ||
logrus.Infof("Start CRI service with CRI version: v1alpha2") | ||
criMgr, err := criv1alpha2.NewCriManager(daemonconfig, containerMgr, imageMgr) | ||
if err != nil { | ||
logrus.Errorf("failed to get CriManager with error: %v", err) | ||
return | ||
} | ||
|
||
service, err := servicev1alpha2.NewService(daemonconfig, criMgr) | ||
if err != nil { | ||
logrus.Errorf("failed to start CRI service with error: %v", err) | ||
return | ||
} | ||
// TODO: Stop the whole CRI service if any of the critical service exits | ||
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) | ||
}() | ||
// TODO: refactor it with select | ||
<-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
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
Oops, something went wrong.