(接上篇)
Module接口定义具体内容如下所示。
type Module interface { Name() string Group() string Start(c *context.Context) Cleanup() } |
我们可以分别在KubeEdge/cloud/pkg/cloudhub/cloudhub.go、KubeEdge/cloud/pkg/controller/controller.go、KubeEdge/cloud/pkg/devicecontroller/module.go中找到cloudhub、edgecontroller和devicecontroller三个功能模块对Module接口的具体实现。
CloudCore中功能模块的启动
CloudCore中功能模块的启动具体如下所示。
//Run starts the modules and in the end does module cleanup func Run() { //Address the module registration and start the core StartModules() // monitor system signal and shutdown gracefully GracefulShutdown() } |
上述代码中,通过StartModules()启动已经注册的模块,通过GracefulShutdown()将模块优雅地停止。至于如何启动和停止,需要进入GracefulShutdown()函数内容一探究竟。
函数StartModules()定义具体如下所示。
// StartModules starts modules that are registered func StartModules() { coreContext := context.GetContext(context.MsgCtxTypeChannel) modules := GetModules() for name, module := range modules { //Init the module coreContext.AddModule(name) //Assemble typeChannels for sendToGroup coreContext.AddModuleGroup(name, module.Group()) go module.Start(coreContext) klog.Infof("Starting module %v", name) } } |
从上面 StartModules()函数的定义,可以清楚地知道该函数首先获得已经注册的模块,然后通过一个for循环启动所有的模块。
各模块的启动过程如下所示。
// GracefulShutdown is if it gets the special signals it does modules cleanup func GracefulShutdown() { c := make(chan os.Signal) signal.Notify(c, syscall.SIGINT, syscall.SIGHUP, syscall.SIGTERM, syscall.SIGQUIT, syscall.SIGILL, syscall.SIGTRAP, syscall.SIGABRT) select { case s := <-c: klog.Infof("Get os signal %v", s.String()) //Cleanup each modules modules := GetModules() for name, module := range modules { klog.Infof("Cleanup module %v", name) module.Cleanup() } } } |
GracefulShutdown()函数与StartModules()函数的逻辑类似,也是首先获得已经注册的模块,然后通过一个for循环等待关闭所有的模块。
「未完待续……」
点击下方标题可阅读技术文章
「连载」边缘计算(五)01-19:云边端的部署与配置(基础篇)
「连载」边缘计算(六)01-22:云边端的部署与配置(基础篇)
「连载」边缘计算(七)01-23:云边端的部署与配置(基础篇)
「连载」边缘计算(八)01-24:云边端的部署与配置(基础篇)
「连载」边缘计算(九)01-25:云边端的部署与配置(基础篇)
「连载」边缘计算(十)01-26:云边端的部署与配置(基础篇)
「连载」边缘计算(十一)01-29:云边端的部署与配置(基础篇)
「连载」边缘计算(十二)01-30:云边端的部署与配置(基础篇)
「连载」边缘计算(十三)01-31:云边端的部署与配置(基础篇)
「连载」边缘计算(十四)02-01:云边端的部署与配置(基础篇)
「连载」边缘计算(十五)02-02:云边端的部署与配置(基础篇)
「连载」边缘计算(十六)2-18:边缘计算系统逻辑架构(原理篇)
「连载」边缘计算(十七)2-19:边缘计算系统逻辑架构(原理篇)
「连载」边缘计算(十八)2-20:边缘部分原理解析(原理篇)
「连载」边缘计算(十九)2-21:边缘部分原理解析(原理篇)
「连载」边缘计算(二十)2-22:边缘部分原理解析(原理篇)
「连载」边缘计算(二十一)2-23:边缘部分原理解析(原理篇)
「连载」边缘计算(二十二)2-26:边缘部分原理解析(原理篇)
「连载」边缘计算(二十三)2-27:边缘部分原理解析(原理篇)