var rootCmd = &cobra.Command{ Use: "hugo", Short: "Hugo is a very fast static site generator", Long: `A Fast and Flexible Static Site Generator built with love by spf13 and friends in Go. Complete documentation is available at https://gohugo.io`, RunE: func(cmd *cobra.Command, args []string)error { fmt.Println("run hugo...") returnnil }, }
var versionCmd = &cobra.Command{ Use: "version", Short: "Print the version number of Hugo", Long: `All software has versions. This is Hugo's`, RunE: func(cmd *cobra.Command, args []string)error { fmt.Println("Hugo Static Site Generator v0.9 -- HEAD") returnnil }, }
# ./hugo run hugo.. # ./hugo -h A Fast and Flexible Static Site Generator built with love by spf13 and friends in Go. Complete documentation is available at https://gohugo.io
Usage: hugo [flags] hugo [command]
Available Commands: completion Generate the autocompletion script for the specified shell help Help about any command version Print the version number of Hugo
Flags: -h, --helphelpfor hugo
Use "hugo [command] --help"for more information about a command. # ./hugo version Hugo Static Site Generator v0.9 -- HEAD
// NewSchedulerCommand creates a *cobra.Command object with default parameters and registryOptions funcNewSchedulerCommand(registryOptions ...Option) *cobra.Command { opts := options.NewOptions()
cmd := &cobra.Command{ Use: "kube-scheduler", Long: `The Kubernetes scheduler is a control plane process which assigns Pods to Nodes. The scheduler determines which Nodes are valid placements for each Pod in the scheduling queue according to constraints and available resources. The scheduler then ranks each valid Node and binds the Pod to a suitable Node. Multiple different schedulers may be used within a cluster; kube-scheduler is the reference implementation. See [scheduling](https://kubernetes.io/docs/concepts/scheduling-eviction/) for more information about scheduling and the kube-scheduler component.`, RunE: func(cmd *cobra.Command, args []string)error { return runCommand(cmd, opts, registryOptions...) }, Args: func(cmd *cobra.Command, args []string)error { for _, arg := range args { iflen(arg) > 0 { return fmt.Errorf("%q does not take any arguments, got %q", cmd.CommandPath(), args) } } returnnil }, }
// Activate logging as soon as possible, after that // show flags with the final logging configuration. if err := logsapi.ValidateAndApply(opts.Logs, utilfeature.DefaultFeatureGate); err != nil { fmt.Fprintf(os.Stderr, "%v\n", err) os.Exit(1) } cliflag.PrintFlags(cmd.Flags())
// Run executes the scheduler based on the given configuration. It only returns on error or when context is done. funcRun(ctx context.Context, cc *schedulerserverconfig.CompletedConfig, sched *scheduler.Scheduler)error { logger := klog.FromContext(ctx) // 从上下文中获取日志记录器
// Run begins watching and scheduling. It starts scheduling and blocked until the context is done. func(sched *Scheduler) Run(ctx context.Context) { // 启动调度队列,这将允许调度器观察新的、需要调度的 Pods sched.SchedulingQueue.Run()
// We need to start scheduleOne loop in a dedicated goroutine, // because scheduleOne function hangs on getting the next item // from the SchedulingQueue. // If there are no new pods to schedule, it will be hanging there // and if done in this goroutine it will be blocking closing // SchedulingQueue, in effect causing a deadlock on shutdown. // 翻译: // 我们需要在一个独立的 goroutine 中启动 scheduleOne 循环, // 因为 scheduleOne 函数在从 SchedulingQueue 获取下一个项目时会挂起。 // 如果没有新的 Pods 需要调度,它会在那里挂起, // 如果在这个 goroutine 中执行,它将阻止关闭 SchedulingQueue, // 从而在关闭时造成死锁。 go wait.UntilWithContext(ctx, sched.scheduleOne, 0)