NewEdgeCoreCommand create edgecore cmd
()
| 40 | |
| 41 | // NewEdgeCoreCommand create edgecore cmd |
| 42 | func 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, |
| 47 | edgehub, eventbus, metamanager, and servicebus. DeviceTwin is responsible for storing device status |
| 48 | and syncing device status to the cloud. It also provides query interfaces for applications. Edged is an |
| 49 | agent that runs on edge nodes and manages containerized applications and devices. Edgehub is a web socket |
| 50 | client responsible for interacting with Cloud Service for the edge computing (like Edge Controller as in the KubeEdge |
| 51 | Architecture). This includes syncing cloud-side resource updates to the edge, and reporting |
| 52 | edge-side host and device status changes to the cloud. EventBus is a MQTT client to interact with MQTT |
| 53 | servers (mosquito), offering publish and subscribe capabilities to other components. MetaManager |
| 54 | is the message processor between edged and edgehub. It is also responsible for storing/retrieving metadata |
| 55 | to/from a lightweight database (SQLite).ServiceBus is a HTTP client to interact with HTTP servers (REST), |
| 56 | offering 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())) |
no test coverage detected