(接上篇)
表 8-3 KubeEdge核心组件源码入口文件
| 组件名 | 代码目录 | 组件启动入口 |
|---|---|---|
| CloudCore | KubeEdge/cloud | KubeEdge/cloud/CloudCore/CloudCore.go、KubeEdge/cloud/admission/admission.go、KubeEdge/cloud/csidriver/csidriver.go |
| EdgeCore | KubeEdge/edge | KubeEdge/edge/cmd/EdgeCore/EdgeCore.go |
| edgemesh | KubeEdge/edgemesh | KubeEdge/edgemesh/cmd/edgemesh.go |
| edgesite | KubeEdge/edgesite | KubeEdge/edgesite/cmd/edgesite.go |
在CloudCore、EdgeCore、edgemesh和edgesite组件的源码中都使用了命令行框架cobra(GitHub.com/spf13/cobra) ,具体如下。
Cloudcore 源 码入口
Cloudcore源码入口为KubeEdge/cloud/CloudCore/CloudCore.go。
CloudCore 源码入口函数具体如下所示。
| func main() {command := app.NewCloudCoreCommand() //此函数是对cobra调用的封装...} |
|---|
进入app.NewCloudCoreCommand()函数内部,也就是KubeEdge/cloud/CloudCore/app/server.go中的NewCloudCoreCommand()函数中。
NewCloudCoreCommand()函数定义具体如下所示。
| func NewCloudCoreCommand() *cobra.Command {...cmd := &cobra.Command{...Run: func(cmd *cobra.Command, args []string) {...registerModules() //注册CloudCore中的功能模块 // start all modules core.Run() //启动已注册的CloudCore中的功能模块},} ...} |
|---|
| 在NewCloudCoreCommand()函数中,通过registerModules()函数注册CloudCore中的功能模块,通过core.Run()函数启动已注册的CloudCore中的功能模块。至于registerModules()函数注册了哪些功能模块,core.Run()函数怎么启动已注册功能模块的,详见《深入理解边缘计算:云、边、端工作原理与源码分析》8.2.3节。 |
注意:KubeEdge/cloud/admission/admission.go,KubeEdge/cloud/csidriver/csidriver.go两个入口,目前还没有用到,暂不分析。
EdgeCore 源 码入口
EdgeCore源码入口为KubeEdge/edge/cmd/EdgeCore/EdgeCore.go。
EdgeCore源码入口函数具体如下所示。
| func main() {command := app.NewEdgeCoreCommand()//此函数是对cobra调用的封装...} |
|---|
进入app.NewEdgeCoreCommand()函数内部,也就是KubeEdge/edge/cmd/EdgeCore/app/server.go中的NewEdgeCoreCommand()函数中。
NewEdgeCoreCommand()函数定义具体如下所示。
| func NewEdgeCoreCommand() *cobra.Command {...cmd := &cobra.Command{...Run: func(cmd *cobra.Command, args []string) {...registerModules() //注册CloudCore中的功能模块 // start all modules core.Run() //启动已注册的CloudCore中的功能模块}, } ...} |
|---|
在NewEdgeCoreCommand()函数中,通过 registerModules()函数注册EdgeCore中的功能模块,通过core.Run()函数启动已注册的EdgeCore中的功能模块。至于registerModules()函数注册了哪些功能模块,core.Run()函数怎么启动已注册功能模块的,详见《深入理解边缘计算:云、边、端工作原理与源码分析》8.2.3节。
「未完待续……」 点击下方标题可阅读技术文章