From aa07992a44186452de261ba0bdd3a4afb5dfe678 Mon Sep 17 00:00:00 2001 From: David Eads Date: Fri, 28 Feb 2020 09:23:23 -0500 Subject: [PATCH] update kube-controller-manager and kube-scheduler to match kube-apiserver defaults --- .../app/options/options_test.go | 2 ++ .../app/options/debugging.go | 10 ++++++++ cmd/controller-manager/app/options/generic.go | 5 +--- cmd/kube-scheduler/app/options/BUILD | 1 + cmd/kube-scheduler/app/options/options.go | 3 +++ .../config/v1alpha1/defaults.go | 23 +++++++++++++++++++ 6 files changed, 40 insertions(+), 4 deletions(-) diff --git a/cmd/cloud-controller-manager/app/options/options_test.go b/cmd/cloud-controller-manager/app/options/options_test.go index cb5ef9e7af6..272cfca5d01 100644 --- a/cmd/cloud-controller-manager/app/options/options_test.go +++ b/cmd/cloud-controller-manager/app/options/options_test.go @@ -61,6 +61,7 @@ func TestDefaultFlags(t *testing.T) { }, Debugging: &cmoptions.DebuggingOptions{ DebuggingConfiguration: &componentbaseconfig.DebuggingConfiguration{ + EnableProfiling: true, EnableContentionProfiling: false, }, }, @@ -192,6 +193,7 @@ func TestAddFlags(t *testing.T) { }, Debugging: &cmoptions.DebuggingOptions{ DebuggingConfiguration: &componentbaseconfig.DebuggingConfiguration{ + EnableProfiling: false, EnableContentionProfiling: true, }, }, diff --git a/cmd/controller-manager/app/options/debugging.go b/cmd/controller-manager/app/options/debugging.go index 05aa05f947a..eafd78a886e 100644 --- a/cmd/controller-manager/app/options/debugging.go +++ b/cmd/controller-manager/app/options/debugging.go @@ -27,6 +27,16 @@ type DebuggingOptions struct { *componentbaseconfig.DebuggingConfiguration } +// RecommendedDebuggingOptions returns the currently recommended debugging options. These are subject to change +// between releases as we add options and decide which features should be exposed or not by default. +func RecommendedDebuggingOptions() *DebuggingOptions { + return &DebuggingOptions{ + DebuggingConfiguration: &componentbaseconfig.DebuggingConfiguration{ + EnableProfiling: true, // profile debugging is cheap to have exposed and standard on kube binaries + }, + } +} + // AddFlags adds flags related to debugging for controller manager to the specified FlagSet. func (o *DebuggingOptions) AddFlags(fs *pflag.FlagSet) { if o == nil { diff --git a/cmd/controller-manager/app/options/generic.go b/cmd/controller-manager/app/options/generic.go index 59dc6784467..7488ea34b9c 100644 --- a/cmd/controller-manager/app/options/generic.go +++ b/cmd/controller-manager/app/options/generic.go @@ -22,7 +22,6 @@ import ( "k8s.io/apimachinery/pkg/util/sets" cliflag "k8s.io/component-base/cli/flag" - componentbaseconfig "k8s.io/component-base/config" "k8s.io/kubernetes/pkg/client/leaderelectionconfig" kubectrlmgrconfig "k8s.io/kubernetes/pkg/controller/apis/config" ) @@ -39,9 +38,7 @@ type GenericControllerManagerConfigurationOptions struct { func NewGenericControllerManagerConfigurationOptions(cfg *kubectrlmgrconfig.GenericControllerManagerConfiguration) *GenericControllerManagerConfigurationOptions { o := &GenericControllerManagerConfigurationOptions{ GenericControllerManagerConfiguration: cfg, - Debugging: &DebuggingOptions{ - DebuggingConfiguration: &componentbaseconfig.DebuggingConfiguration{}, - }, + Debugging: RecommendedDebuggingOptions(), } return o diff --git a/cmd/kube-scheduler/app/options/BUILD b/cmd/kube-scheduler/app/options/BUILD index 931c6e9f117..efd0a6bee74 100644 --- a/cmd/kube-scheduler/app/options/BUILD +++ b/cmd/kube-scheduler/app/options/BUILD @@ -42,6 +42,7 @@ go_library( "//staging/src/k8s.io/component-base/cli/flag:go_default_library", "//staging/src/k8s.io/component-base/codec:go_default_library", "//staging/src/k8s.io/component-base/config:go_default_library", + "//staging/src/k8s.io/component-base/config/v1alpha1:go_default_library", "//staging/src/k8s.io/component-base/metrics:go_default_library", "//staging/src/k8s.io/kube-scheduler/config/v1alpha2:go_default_library", "//vendor/github.com/spf13/pflag:go_default_library", diff --git a/cmd/kube-scheduler/app/options/options.go b/cmd/kube-scheduler/app/options/options.go index c371ca48f16..46c1821d0f3 100644 --- a/cmd/kube-scheduler/app/options/options.go +++ b/cmd/kube-scheduler/app/options/options.go @@ -39,6 +39,7 @@ import ( "k8s.io/client-go/tools/record" cliflag "k8s.io/component-base/cli/flag" componentbaseconfig "k8s.io/component-base/config" + configv1alpha1 "k8s.io/component-base/config/v1alpha1" "k8s.io/component-base/metrics" "k8s.io/klog" kubeschedulerconfigv1alpha2 "k8s.io/kube-scheduler/config/v1alpha2" @@ -136,6 +137,8 @@ func splitHostIntPort(s string) (string, int, error) { func newDefaultComponentConfig() (*kubeschedulerconfig.KubeSchedulerConfiguration, error) { versionedCfg := kubeschedulerconfigv1alpha2.KubeSchedulerConfiguration{} + versionedCfg.DebuggingConfiguration = *configv1alpha1.NewRecommendedDebuggingConfiguration() + kubeschedulerscheme.Scheme.Default(&versionedCfg) cfg := kubeschedulerconfig.KubeSchedulerConfiguration{} if err := kubeschedulerscheme.Scheme.Convert(&versionedCfg, &cfg, nil); err != nil { diff --git a/staging/src/k8s.io/component-base/config/v1alpha1/defaults.go b/staging/src/k8s.io/component-base/config/v1alpha1/defaults.go index 258e9db4570..05ad82d3eb0 100644 --- a/staging/src/k8s.io/component-base/config/v1alpha1/defaults.go +++ b/staging/src/k8s.io/component-base/config/v1alpha1/defaults.go @@ -72,3 +72,26 @@ func RecommendedDefaultClientConnectionConfiguration(obj *ClientConnectionConfig obj.Burst = 100 } } + +// RecommendedDebuggingConfiguration defaults profiling and debugging configuration. +// This will set the recommended default +// values, but they may be subject to change between API versions. This function +// is intentionally not registered in the scheme as a "normal" `SetDefaults_Foo` +// function to allow consumers of this type to set whatever defaults for their +// embedded configs. Forcing consumers to use these defaults would be problematic +// as defaulting in the scheme is done as part of the conversion, and there would +// be no easy way to opt-out. Instead, if you want to use this defaulting method +// run it in your wrapper struct of this type in its `SetDefaults_` method. +func RecommendedDebuggingConfiguration(obj *DebuggingConfiguration) { + if obj.EnableProfiling == nil { + obj.EnableProfiling = utilpointer.BoolPtr(true) // profile debugging is cheap to have exposed and standard on kube binaries + } +} + +// NewRecommendedDebuggingConfiguration returns the current recommended DebuggingConfiguration. +// This may change between releases as recommendations shift. +func NewRecommendedDebuggingConfiguration() *DebuggingConfiguration { + ret := &DebuggingConfiguration{} + RecommendedDebuggingConfiguration(ret) + return ret +}