Skip to content

Commit e9d502e

Browse files
authored
Merge pull request kubernetes#88663 from deads2k/enable-profiling-by-default
update kube-controller-manager and kube-scheduler to match kube-apiserver defaults
2 parents 39ed64e + aa07992 commit e9d502e

File tree

6 files changed

+40
-4
lines changed

6 files changed

+40
-4
lines changed

cmd/cloud-controller-manager/app/options/options_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ func TestDefaultFlags(t *testing.T) {
6161
},
6262
Debugging: &cmoptions.DebuggingOptions{
6363
DebuggingConfiguration: &componentbaseconfig.DebuggingConfiguration{
64+
EnableProfiling: true,
6465
EnableContentionProfiling: false,
6566
},
6667
},
@@ -192,6 +193,7 @@ func TestAddFlags(t *testing.T) {
192193
},
193194
Debugging: &cmoptions.DebuggingOptions{
194195
DebuggingConfiguration: &componentbaseconfig.DebuggingConfiguration{
196+
EnableProfiling: false,
195197
EnableContentionProfiling: true,
196198
},
197199
},

cmd/controller-manager/app/options/debugging.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,16 @@ type DebuggingOptions struct {
2727
*componentbaseconfig.DebuggingConfiguration
2828
}
2929

30+
// RecommendedDebuggingOptions returns the currently recommended debugging options. These are subject to change
31+
// between releases as we add options and decide which features should be exposed or not by default.
32+
func RecommendedDebuggingOptions() *DebuggingOptions {
33+
return &DebuggingOptions{
34+
DebuggingConfiguration: &componentbaseconfig.DebuggingConfiguration{
35+
EnableProfiling: true, // profile debugging is cheap to have exposed and standard on kube binaries
36+
},
37+
}
38+
}
39+
3040
// AddFlags adds flags related to debugging for controller manager to the specified FlagSet.
3141
func (o *DebuggingOptions) AddFlags(fs *pflag.FlagSet) {
3242
if o == nil {

cmd/controller-manager/app/options/generic.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import (
2222

2323
"k8s.io/apimachinery/pkg/util/sets"
2424
cliflag "k8s.io/component-base/cli/flag"
25-
componentbaseconfig "k8s.io/component-base/config"
2625
"k8s.io/kubernetes/pkg/client/leaderelectionconfig"
2726
kubectrlmgrconfig "k8s.io/kubernetes/pkg/controller/apis/config"
2827
)
@@ -39,9 +38,7 @@ type GenericControllerManagerConfigurationOptions struct {
3938
func NewGenericControllerManagerConfigurationOptions(cfg *kubectrlmgrconfig.GenericControllerManagerConfiguration) *GenericControllerManagerConfigurationOptions {
4039
o := &GenericControllerManagerConfigurationOptions{
4140
GenericControllerManagerConfiguration: cfg,
42-
Debugging: &DebuggingOptions{
43-
DebuggingConfiguration: &componentbaseconfig.DebuggingConfiguration{},
44-
},
41+
Debugging: RecommendedDebuggingOptions(),
4542
}
4643

4744
return o

cmd/kube-scheduler/app/options/BUILD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ go_library(
4242
"//staging/src/k8s.io/component-base/cli/flag:go_default_library",
4343
"//staging/src/k8s.io/component-base/codec:go_default_library",
4444
"//staging/src/k8s.io/component-base/config:go_default_library",
45+
"//staging/src/k8s.io/component-base/config/v1alpha1:go_default_library",
4546
"//staging/src/k8s.io/component-base/metrics:go_default_library",
4647
"//staging/src/k8s.io/kube-scheduler/config/v1alpha2:go_default_library",
4748
"//vendor/github.com/spf13/pflag:go_default_library",

cmd/kube-scheduler/app/options/options.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ import (
3939
"k8s.io/client-go/tools/record"
4040
cliflag "k8s.io/component-base/cli/flag"
4141
componentbaseconfig "k8s.io/component-base/config"
42+
configv1alpha1 "k8s.io/component-base/config/v1alpha1"
4243
"k8s.io/component-base/metrics"
4344
"k8s.io/klog"
4445
kubeschedulerconfigv1alpha2 "k8s.io/kube-scheduler/config/v1alpha2"
@@ -136,6 +137,8 @@ func splitHostIntPort(s string) (string, int, error) {
136137

137138
func newDefaultComponentConfig() (*kubeschedulerconfig.KubeSchedulerConfiguration, error) {
138139
versionedCfg := kubeschedulerconfigv1alpha2.KubeSchedulerConfiguration{}
140+
versionedCfg.DebuggingConfiguration = *configv1alpha1.NewRecommendedDebuggingConfiguration()
141+
139142
kubeschedulerscheme.Scheme.Default(&versionedCfg)
140143
cfg := kubeschedulerconfig.KubeSchedulerConfiguration{}
141144
if err := kubeschedulerscheme.Scheme.Convert(&versionedCfg, &cfg, nil); err != nil {

staging/src/k8s.io/component-base/config/v1alpha1/defaults.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,3 +72,26 @@ func RecommendedDefaultClientConnectionConfiguration(obj *ClientConnectionConfig
7272
obj.Burst = 100
7373
}
7474
}
75+
76+
// RecommendedDebuggingConfiguration defaults profiling and debugging configuration.
77+
// This will set the recommended default
78+
// values, but they may be subject to change between API versions. This function
79+
// is intentionally not registered in the scheme as a "normal" `SetDefaults_Foo`
80+
// function to allow consumers of this type to set whatever defaults for their
81+
// embedded configs. Forcing consumers to use these defaults would be problematic
82+
// as defaulting in the scheme is done as part of the conversion, and there would
83+
// be no easy way to opt-out. Instead, if you want to use this defaulting method
84+
// run it in your wrapper struct of this type in its `SetDefaults_` method.
85+
func RecommendedDebuggingConfiguration(obj *DebuggingConfiguration) {
86+
if obj.EnableProfiling == nil {
87+
obj.EnableProfiling = utilpointer.BoolPtr(true) // profile debugging is cheap to have exposed and standard on kube binaries
88+
}
89+
}
90+
91+
// NewRecommendedDebuggingConfiguration returns the current recommended DebuggingConfiguration.
92+
// This may change between releases as recommendations shift.
93+
func NewRecommendedDebuggingConfiguration() *DebuggingConfiguration {
94+
ret := &DebuggingConfiguration{}
95+
RecommendedDebuggingConfiguration(ret)
96+
return ret
97+
}

0 commit comments

Comments
 (0)