Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

component-base: move v/vmodule/log-flush-frequency into LoggingConfiguration #106090

Merged
merged 3 commits into from Nov 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 0 additions & 1 deletion cmd/kube-apiserver/app/options/validation.go
Expand Up @@ -170,7 +170,6 @@ func (s *ServerRunOptions) Validate() []error {
errs = append(errs, s.APIEnablement.Validate(legacyscheme.Scheme, apiextensionsapiserver.Scheme, aggregatorscheme.Scheme)...)
errs = append(errs, validateTokenRequest(s)...)
errs = append(errs, s.Metrics.Validate()...)
errs = append(errs, s.Logs.Validate()...)
errs = append(errs, validateAPIServerIdentity(s)...)

return errs
Expand Down
11 changes: 8 additions & 3 deletions cmd/kube-apiserver/app/server.go
Expand Up @@ -56,6 +56,7 @@ import (
"k8s.io/client-go/util/keyutil"
cliflag "k8s.io/component-base/cli/flag"
"k8s.io/component-base/cli/globalflag"
"k8s.io/component-base/logs"
_ "k8s.io/component-base/metrics/prometheus/workqueue" // for workqueue metric registration
"k8s.io/component-base/term"
"k8s.io/component-base/version"
Expand Down Expand Up @@ -114,6 +115,12 @@ cluster's shared state through which all other components interact.`,
RunE: func(cmd *cobra.Command, args []string) error {
verflag.PrintAndExitIfRequested()
fs := cmd.Flags()

// Activate logging as soon as possible, after that
// show flags with the final logging configuration.
if err := s.Logs.ValidateAndApply(); err != nil {
return err
}
cliflag.PrintFlags(fs)

err := checkNonZeroInsecurePort(fs)
Expand Down Expand Up @@ -146,7 +153,7 @@ cluster's shared state through which all other components interact.`,
fs := cmd.Flags()
namedFlagSets := s.Flags()
verflag.AddFlags(namedFlagSets.FlagSet("global"))
globalflag.AddGlobalFlags(namedFlagSets.FlagSet("global"), cmd.Name())
globalflag.AddGlobalFlags(namedFlagSets.FlagSet("global"), cmd.Name(), logs.SkipLoggingConfigurationFlags())
options.AddCustomGlobalFlags(namedFlagSets.FlagSet("generic"))
for _, f := range namedFlagSets.FlagSets {
fs.AddFlagSet(f)
Expand Down Expand Up @@ -265,8 +272,6 @@ func CreateKubeAPIServerConfig(s completedServerRunOptions) (
s.Metrics.Apply()
serviceaccount.RegisterMetrics()

s.Logs.Apply()

config := &controlplane.Config{
GenericConfig: genericConfig,
ExtraConfig: controlplane.ExtraConfig{
Expand Down
10 changes: 9 additions & 1 deletion cmd/kube-controller-manager/app/controllermanager.go
Expand Up @@ -55,6 +55,7 @@ import (
cliflag "k8s.io/component-base/cli/flag"
"k8s.io/component-base/cli/globalflag"
"k8s.io/component-base/configz"
"k8s.io/component-base/logs"
"k8s.io/component-base/term"
"k8s.io/component-base/version"
"k8s.io/component-base/version/verflag"
Expand Down Expand Up @@ -128,6 +129,13 @@ controller, and serviceaccounts controller.`,
},
Run: func(cmd *cobra.Command, args []string) {
verflag.PrintAndExitIfRequested()

// Activate logging as soon as possible, after that
// show flags with the final logging configuration.
if err := s.Logs.ValidateAndApply(); err != nil {
fmt.Fprintf(os.Stderr, "%v\n", err)
os.Exit(1)
}
cliflag.PrintFlags(cmd.Flags())

err := checkNonZeroInsecurePort(cmd.Flags())
Expand Down Expand Up @@ -160,7 +168,7 @@ controller, and serviceaccounts controller.`,
fs := cmd.Flags()
namedFlagSets := s.Flags(KnownControllers(), ControllersDisabledByDefault.List())
verflag.AddFlags(namedFlagSets.FlagSet("global"))
globalflag.AddGlobalFlags(namedFlagSets.FlagSet("global"), cmd.Name())
globalflag.AddGlobalFlags(namedFlagSets.FlagSet("global"), cmd.Name(), logs.SkipLoggingConfigurationFlags())
registerLegacyGlobalFlags(namedFlagSets)
for _, f := range namedFlagSets.FlagSets {
fs.AddFlagSet(f)
Expand Down
3 changes: 0 additions & 3 deletions cmd/kube-controller-manager/app/options/options.go
Expand Up @@ -415,7 +415,6 @@ func (s *KubeControllerManagerOptions) Validate(allControllers []string, disable
errs = append(errs, s.Authentication.Validate()...)
errs = append(errs, s.Authorization.Validate()...)
errs = append(errs, s.Metrics.Validate()...)
errs = append(errs, s.Logs.Validate()...)

// TODO: validate component config, master and kubeconfig

Expand Down Expand Up @@ -459,8 +458,6 @@ func (s KubeControllerManagerOptions) Config(allControllers []string, disabledBy
}
s.Metrics.Apply()

s.Logs.Apply()

return c, nil
}

Expand Down
2 changes: 0 additions & 2 deletions cmd/kube-scheduler/app/options/options.go
Expand Up @@ -231,7 +231,6 @@ func (o *Options) ApplyTo(c *schedulerappconfig.Config) error {
}
}
o.Metrics.Apply()
o.Logs.Apply()
return nil
}

Expand All @@ -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
}
Expand Down
9 changes: 8 additions & 1 deletion cmd/kube-scheduler/app/server.go
Expand Up @@ -91,7 +91,7 @@ for more information about scheduling and the kube-scheduler component.`,

nfs := opts.Flags
verflag.AddFlags(nfs.FlagSet("global"))
globalflag.AddGlobalFlags(nfs.FlagSet("global"), cmd.Name())
globalflag.AddGlobalFlags(nfs.FlagSet("global"), cmd.Name(), logs.SkipLoggingConfigurationFlags())
fs := cmd.Flags()
for _, f := range nfs.FlagSets {
fs.AddFlagSet(f)
Expand All @@ -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())
Expand Down
2 changes: 1 addition & 1 deletion cmd/kubelet/app/options/globalflags.go
Expand Up @@ -40,7 +40,7 @@ func AddGlobalFlags(fs *pflag.FlagSet) {
addCadvisorFlags(fs)
addCredentialProviderFlags(fs)
verflag.AddFlags(fs)
logs.AddFlags(fs)
logs.AddFlags(fs, logs.SkipLoggingConfigurationFlags())
}

// normalize replaces underscores with hyphens
Expand Down
13 changes: 13 additions & 0 deletions cmd/kubelet/app/options/options.go
Expand Up @@ -391,7 +391,20 @@ func AddKubeletConfigFlags(mainfs *pflag.FlagSet, c *kubeletconfig.KubeletConfig
// e.g. if a flag was added after this deprecation function, it may not be at the end
// of its lifetime yet, even if the rest are.
deprecated := "This parameter should be set via the config file specified by the Kubelet's --config flag. See https://kubernetes.io/docs/tasks/administer-cluster/kubelet-config-file/ for more information."
// Some flags are permanently (?) meant to be available. In
// Kubernetes 1.23, the following options were added to
// LoggingConfiguration (long-term goal, more complete
// configuration file) but deprecating the flags seemed
// premature.
notDeprecated := map[string]bool{
"v": true,
"vmodule": true,
"log-flush-frequency": true,
}
fs.VisitAll(func(f *pflag.Flag) {
if notDeprecated[f.Name] {
return
}
f.Deprecated = deprecated
})
mainfs.AddFlagSet(fs)
Expand Down
7 changes: 5 additions & 2 deletions cmd/kubelet/app/server.go
Expand Up @@ -261,6 +261,11 @@ HTTP server: The kubelet can also listen for HTTP and respond to a simple API

// Config and flags parsed, now we can initialize logging.
logs.InitLogs()
logOption := &logs.Options{Config: kubeletConfig.Logging}
if err := logOption.ValidateAndApply(); err != nil {
klog.ErrorS(err, "Failed to initialize logging")
os.Exit(1)
}

// construct a KubeletServer from kubeletFlags and kubeletConfig
kubeletServer := &options.KubeletServer{
Expand Down Expand Up @@ -437,8 +442,6 @@ func UnsecuredDependencies(s *options.KubeletServer, featureGate featuregate.Fea
// Otherwise, the caller is assumed to have set up the Dependencies object and a default one will
// not be generated.
func Run(ctx context.Context, s *options.KubeletServer, kubeDeps *kubelet.Dependencies, featureGate featuregate.FeatureGate) error {
logOption := &logs.Options{Config: s.Logging}
logOption.Apply()
// To help debugging, immediately log version
klog.InfoS("Kubelet version", "kubeletVersion", version.Get())
if err := initForOS(s.KubeletFlags.WindowsService, s.KubeletFlags.WindowsPriorityClass); err != nil {
Expand Down
4 changes: 4 additions & 0 deletions pkg/kubelet/apis/config/helpers_test.go
Expand Up @@ -187,6 +187,7 @@ var (
"HairpinMode",
"HealthzBindAddress",
"HealthzPort",
"Logging.FlushFrequency",
"Logging.Format",
"Logging.Options.JSON.InfoBufferSize.Quantity.Format",
"Logging.Options.JSON.InfoBufferSize.Quantity.d.Dec.scale",
Expand All @@ -197,6 +198,9 @@ var (
"Logging.Options.JSON.InfoBufferSize.Quantity.s",
"Logging.Options.JSON.SplitStream",
"Logging.Sanitization",
"Logging.VModule[*].FilePattern",
"Logging.VModule[*].Verbosity",
"Logging.Verbosity",
"TLSCipherSuites[*]",
"TLSMinVersion",
"IPTablesDropBit",
Expand Down
Expand Up @@ -53,10 +53,12 @@ kind: KubeletConfiguration
kubeAPIBurst: 10
kubeAPIQPS: 5
logging:
flushFrequency: 5000000000
format: text
options:
json:
infoBufferSize: "0"
verbosity: 0
makeIPTablesUtilChains: true
maxOpenFiles: 1000000
maxPods: 110
Expand Down
Expand Up @@ -53,10 +53,12 @@ kind: KubeletConfiguration
kubeAPIBurst: 10
kubeAPIQPS: 5
logging:
flushFrequency: 5000000000
format: text
options:
json:
infoBufferSize: "0"
verbosity: 0
makeIPTablesUtilChains: true
maxOpenFiles: 1000000
maxPods: 110
Expand Down
26 changes: 16 additions & 10 deletions pkg/kubelet/apis/config/v1beta1/defaults_test.go
Expand Up @@ -112,7 +112,8 @@ func TestSetDefaultsKubeletConfiguration(t *testing.T) {
EnforceNodeAllocatable: DefaultNodeAllocatableEnforcement,
VolumePluginDir: DefaultVolumePluginDir,
Logging: componentbaseconfigv1alpha1.LoggingConfiguration{
Format: "text",
Format: "text",
FlushFrequency: 5 * time.Second,
},
EnableSystemLogHandler: utilpointer.BoolPtr(true),
EnableProfilingHandler: utilpointer.BoolPtr(true),
Expand Down Expand Up @@ -231,8 +232,9 @@ func TestSetDefaultsKubeletConfiguration(t *testing.T) {
ProviderID: "",
KernelMemcgNotification: false,
Logging: componentbaseconfigv1alpha1.LoggingConfiguration{
Format: "",
Sanitization: false,
Format: "",
FlushFrequency: 5 * time.Second,
Sanitization: false,
},
EnableSystemLogHandler: utilpointer.Bool(false),
ShutdownGracePeriod: zeroDuration,
Expand Down Expand Up @@ -327,8 +329,9 @@ func TestSetDefaultsKubeletConfiguration(t *testing.T) {
AllowedUnsafeSysctls: []string{},
VolumePluginDir: DefaultVolumePluginDir,
Logging: componentbaseconfigv1alpha1.LoggingConfiguration{
Format: "text",
Sanitization: false,
Format: "text",
FlushFrequency: 5 * time.Second,
Sanitization: false,
},
EnableSystemLogHandler: utilpointer.Bool(false),
ReservedMemory: []v1beta1.MemoryReservation{},
Expand Down Expand Up @@ -468,8 +471,9 @@ func TestSetDefaultsKubeletConfiguration(t *testing.T) {
ProviderID: "provider-id",
KernelMemcgNotification: true,
Logging: componentbaseconfigv1alpha1.LoggingConfiguration{
Format: "json",
Sanitization: true,
Format: "json",
FlushFrequency: 5 * time.Second,
Sanitization: true,
},
EnableSystemLogHandler: utilpointer.Bool(true),
ShutdownGracePeriod: metav1.Duration{Duration: 60 * time.Second},
Expand Down Expand Up @@ -613,8 +617,9 @@ func TestSetDefaultsKubeletConfiguration(t *testing.T) {
ProviderID: "provider-id",
KernelMemcgNotification: true,
Logging: componentbaseconfigv1alpha1.LoggingConfiguration{
Format: "json",
Sanitization: true,
Format: "json",
FlushFrequency: 5 * time.Second,
Sanitization: true,
},
EnableSystemLogHandler: utilpointer.Bool(true),
ShutdownGracePeriod: metav1.Duration{Duration: 60 * time.Second},
Expand Down Expand Up @@ -706,7 +711,8 @@ func TestSetDefaultsKubeletConfiguration(t *testing.T) {
EnforceNodeAllocatable: DefaultNodeAllocatableEnforcement,
VolumePluginDir: DefaultVolumePluginDir,
Logging: componentbaseconfigv1alpha1.LoggingConfiguration{
Format: "text",
Format: "text",
FlushFrequency: 5 * time.Second,
},
EnableSystemLogHandler: utilpointer.BoolPtr(true),
EnableProfilingHandler: utilpointer.BoolPtr(true),
Expand Down
Expand Up @@ -27,8 +27,12 @@ import (
// AddGlobalFlags explicitly registers flags that libraries (klog, verflag, etc.) register
// against the global flagsets from "flag" and "k8s.io/klog/v2".
// We do this in order to prevent unwanted flags from leaking into the component's flagset.
func AddGlobalFlags(fs *pflag.FlagSet, name string) {
logs.AddFlags(fs)
//
// k8s.io/component-base/logs.SkipLoggingConfigurationFlags must be used as
// option when the program also uses a LoggingConfiguration struct for
// configuring logging. Then only flags not covered by that get added.
func AddGlobalFlags(fs *pflag.FlagSet, name string, opts ...logs.Option) {
logs.AddFlags(fs, opts...)

fs.BoolP("help", "h", false, fmt.Sprintf("help for %s", name))
}
Expand Down