This series of source code analysis is carried out on the commit da92692baa660359bb314d89dfa3a80bffb1d26c.
kubeedge is constructed based kubernetes open platform enabling edge computation, the function of the expansion vessel to the scheduling application and the edge node device, and the network between the cloud and the edge, application deployment and synchronized metadata provides infrastructure support.
This article outlines
From the overall architecture kubeedge cut, first summarized relationships between components and functional components that it contains, and then analyzed sharing between the frame and the function of each component, in the final analysis component sharing between the frame and the function of each module. details as follows:
- Functional relationships between components and assemblies
- And functional components of a common frame
- And functional components in a common frame module
Functional relationships between components and assemblies
Components and component relationships kubeedge in, start talking about the official organization chart, as follows:
You can clearly see from the official organization chart, kubeedge overall points and Cloud Edge of two parts:
- Cloud is part kubernetes api server and Edge section of the bridge, it will be sent to the responsible Edge under kubernetes instruction, while Edge of state and event synchronization to kubernetes api server;
- Edge section accepts and executes the instructions issued by the lower part of Cloud, manage load and part load condition and Edge event synchronized to Cloud portion;
In addition to the official part of the Cloud and Edge architecture diagram shows, as well as across the Cloud and Edge part, as follows:
- Edgemesh solutions based Istio across Cloud services and Edge grid;
- Edgesite to meet the needs at the edge of a full cluster functionality scene, custom-built management both at the edge, run a full schedule can be responsible for a cluster solution;
And functional components of a common frame
In the source code level, kubeedge independent core assembly comprises cloudcore, edgecore, edge_mesh and edge_site, and in addition mappers keadm, follows the following table:
Component Name | Component Function | Remark |
---|---|---|
cloudcore | Cloud portion of each set of functional modules | |
edgecore | Cloud portion of each set of functional modules | |
edge_mesh | Service Grid Solutions | Source directory is missing from the makefile |
edge_site | Edge independent clustering solutions | |
mappers | Things protocol packet | This series does not involve source code analysis |
keadm | kubeedge one-click deployment tools | Currently supports unbuntu, this series does not involve source code analysis |
The above components cloudcore, edgecore, edge_mesh and edge_site having similar code structure, the following table:
Component Name | Code Directory | Components boot entry |
---|---|---|
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 |
edge_mesh | kubeedge/edgemesh | kubeedge/edgemesh/cmd/edgemesh.go |
edge_site | kubeedge/edgesite | kubeedge/edgesite/cmd/edgesite.go |
In the source cloudcore, edgecore, edge_mesh edge_site assembly and use the command-line frame COBRA , as follows:
-
code entry cloudcore
kubeedge/cloud/cloudcore/cloudcore.go
func main() { command := app.NewCloudCoreCommand() //此函数是对cobra调用的封装 ... } 复制代码
Entering app.NewCloudCoreCommand () internal function, i.e. kubeedge / cloud / cloudcore / app / server.go in NewCloudCoreCommand () function, as follows:
func NewCloudCoreCommand() *cobra.Command { ... cmd := &cobra.Command{ ... Run: func(cmd *cobra.Command, args []string) { ... registerModules() //注册cloudcore中的功能模块 // start all modules core.Run() //启动已注册的cloudcore中的功能模块 }, } ... } 复制代码
In NewCloudCoreCommand () function by registerModules () function to register cloudcore function module, by core.Run () cloudcore function starts registered in function modules, as registerModules () function to register what function modules, core.Run () function is registered how activated function module, see "common frame components and functional modules."
Note: kubeedge / cloud / admission / admission.go, kubeedge / cloud / csidriver / csidriver.go two entrances, there seems no use, they will not analysis.
-
code entry edgecore
kubeedge/edge/cmd/edgecore/edgecore.go
func main() { command := app.NewEdgeCoreCommand()//此函数是对cobra调用的封装 ... } 复制代码
Entering app.NewEdgeCoreCommand () internal function, i.e. kubeedge / edge / cmd / edgecore / app / server.go in NewEdgeCoreCommand () function, as follows:
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()函数怎么启动已注册功能模块的,详见“组件中模块的共用框架和功能”。
复制代码
-
code entry edge_mesh
kubeedge/edgemesh/cmd/edgemesh.go
func main() { ... pkg.Register() //注册edgemesh的功能模块 //Start server server.StartTCP() //启动一个tcp服务 } 复制代码
() Function can be seen from the main, edgemesh not use cobra, but directly registered function module, and then start a TCP service.
-
code entry edge_site
kubeedge/edgesite/cmd/edgesite.go
func NewEdgeSiteCommand() *cobra.Command { ... cmd := &cobra.Command{ ... Run: func(cmd *cobra.Command, args []string) { ... registerModules() //注册cloudcore中的功能模块 // start all modules core.Run() //启动已注册的cloudcore中的功能模块 }, } ... } 复制代码
In NewEdgeSiteCommand () function by registerModules () function to register edgesite function module, by core.Run () edgecore function starts registered in function modules, as registerModules () function to register what function modules, core.Run () function is registered how activated function module, see "common frame components and functional modules."
This, the source common frame assembly and functional analysis (cloudcore, edgecore, edge_mesh and edge_site) levels ended, in-depth analysis common frame components and functions of the functional modules below.
And functional components in a common frame module
kubeedge component is to organize and manage through the Beehive between the various functional modules, Beehive is a go-channels of news-based framework, but the focus is not is not the Beehive this article, so will only analysis related functions kubeedge used in the Beehive. Let's depth cloudcore, edgecore, edge_mesh and edge_site assembly, the internal components together to explore the common frame of each functional module.
Cloudcore common frame modules and functional analysis
In the "common frame and functional components" a "cloudcore code entry" section has analyzed and registered to the registered start function module cloudcore functional modules, it then analyzes this section down.
-
Registration cloudcore functional modules
func registerModules() { cloudhub.Register() edgecontroller.Register() devicecontroller.Register() } 复制代码
From registerModules () function, you can know cloudcore there cloudhub, edgecontroller and devicecontroller a total of three functional modules into the Register () function to explore in the registration module specifically what to do:
func Register() { core.Register(&cloudHub{}) } 复制代码
Register at kubeedge / cloud / pkg / cloudhub / cloudhub.go in () function simply calls the kubeedge / beehive / pkg / core / Register module.go in (...) function, continue to the Register (...) function, you will see:
... var ( // Modules map modules map[string]Module disabledModules map[string]Module ) ... func Register(m Module) { if isModuleEnabled(m.Name()) { modules[m.Name()] = m klog.Infof("Module %v registered", m.Name()) } else { disabledModules[m.Name()] = m klog.Warningf("Module %v is not register, please check modules.yaml",m.Name()) } } 复制代码
Can be clearly seen from the above variable and function definitions, cloudhub module registration module will eventually be placed in the structure of a map [string] Module type modules in the global variable.
Accordance with the idea cloudhub analysis module registration, edgecontroller devicecontroller and have done the same thing, each of the final structure into a map [string] Module type modules in the global variable.
cloudhub, edgecontroller devicecontroller and three functional modules, was able to use the same registration process, because they have achieved Interface Module kubeedge / beehive / pkg / core / module.go in, Module interfaces including the following:
type Module interface { Name() string Group() string Start(c *context.Context) Cleanup() } 复制代码
You may respectively kubeedge / cloud / pkg / cloudhub / cloudhub.go, kubeedge / cloud / pkg / controller / controller.go, kubeedge / cloud / pkg / devicecontroller / module.go found cloudhub, edgecontroller and three functional modules devicecontroller Module specific implementation of the interface.
-
Start cloudcore functional modules
kubeedge/beehive/pkg/core/core.go
//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() } 复制代码
From the above Run () function you may know that the function started by StartModules modules already registered (), by GracefulShutdown () module and elegant stop, as to how to start and stop, you need to take a closer look into the function contents:
kubeedge/beehive/pkg/core/core.go
// 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) } } 复制代码
From the above-defined StartModules () function will be clear to the function to obtain the module registered, and then start all the module by a for loop.
kubeedge/beehive/pkg/core/core.go
// 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 () function is similar to StartModules () logic function module is obtained first registered, and then through a closed loop to wait for all the module.
Common frame modules and functional analysis edgecore
In the "common frame and functional components" a "Edgecore code entry" section has analyzed and registered to the registered function module starting Edgecore functional modules, it then analyzes this section down.
-
Registration edgecore functional modules
// registerModules register all the modules started in edgecore func registerModules() { devicetwin.Register() edged.Register() edgehub.Register() eventbus.Register() edgemesh.Register() metamanager.Register() servicebus.Register() test.Register() dbm.InitDBManager() } 复制代码
From registerModules () function, you can know edgecore there devicetwin, edged, edgehub, eventbus, edgemesh, metamanager, servicebus, and test a total of eight modules, there is a db initialization function, enter Register () function to explore in the registration module specifically what to do:
// Register register devicetwin func Register() { dtclient.InitDBTable() dt := DeviceTwin{} core.Register(&dt) } 复制代码
In kubeedge / edge / pkg / devicetwin / devicetwin.go in the Register () function simply calls the kubeedge / beehive / pkg / core / Register module.go in (...) function, continue to the Register (...) function, you will see:
... var ( // Modules map modules map[string]Module disabledModules map[string]Module ) ... func Register(m Module) { if isModuleEnabled(m.Name()) { modules[m.Name()] = m klog.Infof("Module %v registered", m.Name()) } else { disabledModules[m.Name()] = m klog.Warningf("Module %v is not register, please check modules.yaml",m.Name()) } } 复制代码
Can be clearly seen from the above variable and function definitions, devicetwin module registration module will eventually be placed in the structure of a map [string] Module type modules in the global variable.
Accordance with the idea cloudhub analysis module registration, edged, edgehub, eventbus, edgemesh, metamanager, servicebus, test, and have done the same thing, each of the final structure into a map [string] Module type modules in the global variable.
devicetwin, edged, edgehub, eventbus, edgemesh, metamanager, servicebus, and a total of eight test modules, was able to use the same registration process, because they have achieved kubeedge / beehive / pkg / core / module.go in Module Interface, Interface Module including the following:
type Module interface { Name() string Group() string Start(c *context.Context) Cleanup() } 复制代码
May respectively kubeedge / edge / pkg / devicetwin / devicetwin.go, kubeedge / edge / pkg / edged / edged.go, kubeedge / edge / pkg / edgehub / module.go, kubeedge / edge / pkg / eventbus / event_bus.go , kubeedge / edge / pkg / edgemesh / module.go, kubeedge / edge / pkg / metamanager / module.go, kubeedge / edge / pkg / servicebush / servicebus.go, kubeedge / edge / pkg / test / test.go found devicetwin, edged, edgehub, eventbus, embodied edgemesh, metamanager, servicebus, and a total of eight functional test module interface module.
-
Startup function module edgecore
Dgecore function module startup and "cloudcore modules in a common frame and functional analysis" in the "startup function module cloudcore" process is identical, we can refer to the changed portion.
Common frame modules and functional analysis edgemesh
In the "common frame and functional components" a "edgemesh code entry" section has analyzed and registered to the registered start function module edgemesh functional modules, it then analyzes this section down.
- Registration edgemesh functional modules
edgemesh registered function module "Registering edgecore functional modules" here not in the repeat.
-
Start edgemesh functional modules
edgemesh currently no startup logic module.
Common frame modules and functional analysis edgesite
In the "common frame and functional components" a "edgesite code entry" section has analyzed and registered to the registered start function module edgemesh functional modules, it then analyzes this section down.
- Registration edgesite functional modules
Registration edgesite functional modules, refer to "Registering edgecore functional modules" here not in the repeat.
-
Startup function module edgesite
Startup function module edgesite refer to the "startup function module edgecore", not here in the repeat.
This article is the "end side of the river Laboratory cloud operating system team," the first series of articles kubeedge source code analysis, source code would be followed by a systematic analysis of each component. If our team will have the opportunity to actively address the issue and achieve kubeedge new feature.
This is our "end side of the river Laboratory cloud operating system team" maintenance "of the river Laboratory kubeedge source code analysis group" micro-channel group, and everyone is welcome to participate! ! !
kubeedge source code analysis group of two-dimensional code entry