mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-09-25 04:11:46 +00:00
component-base: initialize logging as soon as possible
In various places log messages where emitted as part of validation or even before it (for example, cli.PrintFlags). Those log messages did not use the final logging configuration, for example text output instead of JSON or not the final verbosity. The last point became more obvious after moving the setup of verbosity into logs.Options.Apply because PrintFlags never printed anything anymore. In order to force applications to deal with logging as soon as possible, the Options.Validate and Options.Apply methods are now private. Applications should use the new Options.ValidateAndApply directly after parsing.
This commit is contained in:
@@ -231,7 +231,6 @@ func (o *Options) ApplyTo(c *schedulerappconfig.Config) error {
|
||||
}
|
||||
}
|
||||
o.Metrics.Apply()
|
||||
o.Logs.Apply()
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -247,7 +246,6 @@ func (o *Options) Validate() []error {
|
||||
errs = append(errs, o.Authorization.Validate()...)
|
||||
errs = append(errs, o.Deprecated.Validate()...)
|
||||
errs = append(errs, o.Metrics.Validate()...)
|
||||
errs = append(errs, o.Logs.Validate()...)
|
||||
|
||||
return errs
|
||||
}
|
||||
|
@@ -108,6 +108,13 @@ for more information about scheduling and the kube-scheduler component.`,
|
||||
// runCommand runs the scheduler.
|
||||
func runCommand(cmd *cobra.Command, opts *options.Options, registryOptions ...Option) error {
|
||||
verflag.PrintAndExitIfRequested()
|
||||
|
||||
// Activate logging as soon as possible, after that
|
||||
// show flags with the final logging configuration.
|
||||
if err := opts.Logs.ValidateAndApply(); err != nil {
|
||||
fmt.Fprintf(os.Stderr, "%v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
cliflag.PrintFlags(cmd.Flags())
|
||||
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
|
Reference in New Issue
Block a user