mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-01 07:47:56 +00:00
cloud-provider: add more log options
Change k8s.io/cloud-provider/app.NewCloudControllerManagerCommand to create a k8s.io/component-base/logs.Options, add it to the flags for the command and apply them on startup. This adds the logging-format command line option.
This commit is contained in:
parent
f21c603417
commit
e9379b3b37
@ -47,6 +47,8 @@ import (
|
|||||||
cliflag "k8s.io/component-base/cli/flag"
|
cliflag "k8s.io/component-base/cli/flag"
|
||||||
"k8s.io/component-base/cli/globalflag"
|
"k8s.io/component-base/cli/globalflag"
|
||||||
"k8s.io/component-base/configz"
|
"k8s.io/component-base/configz"
|
||||||
|
"k8s.io/component-base/logs"
|
||||||
|
logsapi "k8s.io/component-base/logs/api/v1"
|
||||||
"k8s.io/component-base/metrics/features"
|
"k8s.io/component-base/metrics/features"
|
||||||
controllersmetrics "k8s.io/component-base/metrics/prometheus/controllers"
|
controllersmetrics "k8s.io/component-base/metrics/prometheus/controllers"
|
||||||
"k8s.io/component-base/metrics/prometheus/slis"
|
"k8s.io/component-base/metrics/prometheus/slis"
|
||||||
@ -64,6 +66,7 @@ import (
|
|||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
utilruntime.Must(features.AddFeatureGates(utilfeature.DefaultMutableFeatureGate))
|
utilruntime.Must(features.AddFeatureGates(utilfeature.DefaultMutableFeatureGate))
|
||||||
|
utilruntime.Must(logsapi.AddFeatureGates(utilfeature.DefaultMutableFeatureGate))
|
||||||
}
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -77,6 +80,8 @@ const (
|
|||||||
// controllerInitFuncConstructors is a map of controller name(as defined by controllers flag in https://kubernetes.io/docs/reference/command-line-tools-reference/kube-controller-manager/#options) to their InitFuncConstructor.
|
// controllerInitFuncConstructors is a map of controller name(as defined by controllers flag in https://kubernetes.io/docs/reference/command-line-tools-reference/kube-controller-manager/#options) to their InitFuncConstructor.
|
||||||
// additionalFlags provides controller specific flags to be included in the complete set of controller manager flags
|
// additionalFlags provides controller specific flags to be included in the complete set of controller manager flags
|
||||||
func NewCloudControllerManagerCommand(s *options.CloudControllerManagerOptions, cloudInitializer InitCloudFunc, controllerInitFuncConstructors map[string]ControllerInitFuncConstructor, additionalFlags cliflag.NamedFlagSets, stopCh <-chan struct{}) *cobra.Command {
|
func NewCloudControllerManagerCommand(s *options.CloudControllerManagerOptions, cloudInitializer InitCloudFunc, controllerInitFuncConstructors map[string]ControllerInitFuncConstructor, additionalFlags cliflag.NamedFlagSets, stopCh <-chan struct{}) *cobra.Command {
|
||||||
|
logOptions := logs.NewOptions()
|
||||||
|
|
||||||
cmd := &cobra.Command{
|
cmd := &cobra.Command{
|
||||||
Use: "cloud-controller-manager",
|
Use: "cloud-controller-manager",
|
||||||
Long: `The Cloud controller manager is a daemon that embeds
|
Long: `The Cloud controller manager is a daemon that embeds
|
||||||
@ -85,6 +90,11 @@ the cloud specific control loops shipped with Kubernetes.`,
|
|||||||
verflag.PrintAndExitIfRequested()
|
verflag.PrintAndExitIfRequested()
|
||||||
cliflag.PrintFlags(cmd.Flags())
|
cliflag.PrintFlags(cmd.Flags())
|
||||||
|
|
||||||
|
if err := logsapi.ValidateAndApply(logOptions, utilfeature.DefaultFeatureGate); err != nil {
|
||||||
|
fmt.Fprintf(os.Stderr, "%v\n", err)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
c, err := s.Config(ControllerNames(controllerInitFuncConstructors), ControllersDisabledByDefault.List())
|
c, err := s.Config(ControllerNames(controllerInitFuncConstructors), ControllersDisabledByDefault.List())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Fprintf(os.Stderr, "%v\n", err)
|
fmt.Fprintf(os.Stderr, "%v\n", err)
|
||||||
@ -113,8 +123,11 @@ the cloud specific control loops shipped with Kubernetes.`,
|
|||||||
|
|
||||||
fs := cmd.Flags()
|
fs := cmd.Flags()
|
||||||
namedFlagSets := s.Flags(ControllerNames(controllerInitFuncConstructors), ControllersDisabledByDefault.List())
|
namedFlagSets := s.Flags(ControllerNames(controllerInitFuncConstructors), ControllersDisabledByDefault.List())
|
||||||
verflag.AddFlags(namedFlagSets.FlagSet("global"))
|
|
||||||
globalflag.AddGlobalFlags(namedFlagSets.FlagSet("global"), cmd.Name())
|
globalFlagSet := namedFlagSets.FlagSet("global")
|
||||||
|
verflag.AddFlags(globalFlagSet)
|
||||||
|
logsapi.AddFlags(logOptions, globalFlagSet)
|
||||||
|
globalflag.AddGlobalFlags(globalFlagSet, cmd.Name(), logs.SkipLoggingConfigurationFlags())
|
||||||
|
|
||||||
if flag.CommandLine.Lookup("cloud-provider-gce-lb-src-cidrs") != nil {
|
if flag.CommandLine.Lookup("cloud-provider-gce-lb-src-cidrs") != nil {
|
||||||
// hoist this flag from the global flagset to preserve the commandline until
|
// hoist this flag from the global flagset to preserve the commandline until
|
||||||
|
Loading…
Reference in New Issue
Block a user