MCPcopy
hub / github.com/kubeedge/kubeedge / NewEdgeCoreCommand

Function NewEdgeCoreCommand

edge/cmd/edgecore/app/server.go:42–162  ·  view source on GitHub ↗

NewEdgeCoreCommand create edgecore cmd

()

Source from the content-addressed store, hash-verified

40
41// NewEdgeCoreCommand create edgecore cmd
42func NewEdgeCoreCommand() *cobra.Command {
43 opts := options.NewEdgeCoreOptions()
44 cmd := &cobra.Command{
45 Use: "edgecore",
46 Long: `Edgecore is the core edge part of KubeEdge, which contains six modules: devicetwin, edged,
47edgehub, eventbus, metamanager, and servicebus. DeviceTwin is responsible for storing device status
48and syncing device status to the cloud. It also provides query interfaces for applications. Edged is an
49agent that runs on edge nodes and manages containerized applications and devices. Edgehub is a web socket
50client responsible for interacting with Cloud Service for the edge computing (like Edge Controller as in the KubeEdge
51Architecture). This includes syncing cloud-side resource updates to the edge, and reporting
52edge-side host and device status changes to the cloud. EventBus is a MQTT client to interact with MQTT
53servers (mosquito), offering publish and subscribe capabilities to other components. MetaManager
54is the message processor between edged and edgehub. It is also responsible for storing/retrieving metadata
55to/from a lightweight database (SQLite).ServiceBus is a HTTP client to interact with HTTP servers (REST),
56offering HTTP client capabilities to components of cloud to reach HTTP servers running at edge. `,
57 PreRunE: func(_cmd *cobra.Command, _args []string) error {
58 return initForOS(opts)
59 },
60 Run: func(cmd *cobra.Command, args []string) {
61 flag.PrintMinConfigAndExitIfRequested(v1alpha2.NewMinEdgeCoreConfig())
62 flag.PrintDefaultConfigAndExitIfRequested(v1alpha2.NewDefaultEdgeCoreConfig())
63 flag.PrintFlags(cmd.Flags())
64
65 if errs := opts.Validate(); len(errs) > 0 {
66 klog.Exit(util.SpliceErrors(errs))
67 }
68
69 config, err := opts.Config()
70 if err != nil {
71 klog.Exit(err)
72 }
73
74 // should not save token in config file
75 if config.Modules.EdgeHub.Token != "" {
76 go func() {
77 // if receive data from CleanupTokenChan
78 // it means that edgecore apply for ca/certs successfully, then we can cleanup token
79 <-certificate.CleanupTokenChan
80
81 // cleanup token
82 if err := cleanupToken(*config, opts.ConfigFile); err != nil {
83 klog.Exit(err)
84 }
85 }()
86 }
87
88 bootstrapFile := constants.BootstrapFile
89 // get token from bootstrapFile if it exist
90 if utilvalidation.FileIsExist(bootstrapFile) {
91 token, err := os.ReadFile(bootstrapFile)
92 if err != nil {
93 klog.Exit(err)
94 }
95 config.Modules.EdgeHub.Token = strings.TrimSpace(string(token))
96 }
97
98 if errs := validation.ValidateEdgeCoreConfiguration(config); len(errs) > 0 {
99 klog.Exit(util.SpliceErrors(errs.ToAggregate().Errors()))

Callers 1

mainFunction · 0.92

Calls 15

FlagsMethod · 0.95
ValidateMethod · 0.95
ConfigMethod · 0.95
NewEdgeCoreOptionsFunction · 0.92
PrintFlagsFunction · 0.92
SpliceErrorsFunction · 0.92
GetFunction · 0.92
AddFlagsFunction · 0.92
cleanupTokenFunction · 0.85
environmentCheckFunction · 0.85

Tested by

no test coverage detected