Simple Main
Cmd
The main program lives under the cmd/
package created by kubebuilder init
.It does not need to be changed by the user for most cases.
The main program starts the Controllers that have been registered with the Manager.Scaffolded Controllers are automatically registered with the Manager by scaffoldingan init function to the controller
package. Scaffolded Resources are automatically registered with the Manager Scheme by scaffolding an initfunction to the apis
package.
- Get a kubeconfig to talk to an apiserver
- Add APIs to the Manager's Scheme
- Add Controllers to the Manager
- Start the Manager
func main() {
// Get a config to talk to the apiserver
cfg, err := config.GetConfig()
if err != nil {
log.Fatal(err)
}
// Create a new Cmd to provide shared dependencies and start components
mgr, err := manager.New(cfg, manager.Options{})
if err != nil {
log.Fatal(err)
}
// Setup Scheme for all resources
if err := apis.AddToScheme(mgr.GetScheme()); err != nil {
log.Fatal(err)
}
// Setup all Controllers
if err := controller.AddToManager(mgr); err != nil {
log.Fatal(err)
}
// Start the Cmd
log.Fatal(mgr.Start(signals.SetupSignalHandler()))}
当前内容版权归 kubebuilder.io 或其关联方所有,如需对内容或内容相关联开源项目进行关注与资助,请访问 kubebuilder.io .