Skip to content

Commit b92b04e

Browse files
committed
add default for loggingconfiguration struct
1 parent 3ab25f1 commit b92b04e

File tree

6 files changed

+26
-5
lines changed

6 files changed

+26
-5
lines changed

cmd/kubelet/app/server.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -405,9 +405,7 @@ func UnsecuredDependencies(s *options.KubeletServer, featureGate featuregate.Fea
405405
// not be generated.
406406
func Run(s *options.KubeletServer, kubeDeps *kubelet.Dependencies, featureGate featuregate.FeatureGate, stopCh <-chan struct{}) error {
407407
logOption := logs.NewOptions()
408-
if s.Logging.Format != "" {
409-
logOption.LogFormat = s.Logging.Format
410-
}
408+
logOption.LogFormat = s.Logging.Format
411409
logOption.Apply()
412410
// To help debugging, immediately log version
413411
klog.Infof("Version: %+v", version.Get())

pkg/kubelet/apis/config/fuzzer/fuzzer.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,9 @@ func Funcs(codecs runtimeserializer.CodecFactory) []interface{} {
100100
obj.ConfigMapAndSecretChangeDetectionStrategy = "Watch"
101101
obj.AllowedUnsafeSysctls = []string{}
102102
obj.VolumePluginDir = kubeletconfigv1beta1.DefaultVolumePluginDir
103+
if obj.Logging.Format == "" {
104+
obj.Logging.Format = "text"
105+
}
103106
},
104107
}
105108
}

pkg/kubelet/apis/config/scheme/testdata/KubeletConfiguration/after/v1beta1.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ iptablesMasqueradeBit: 14
4949
kind: KubeletConfiguration
5050
kubeAPIBurst: 10
5151
kubeAPIQPS: 5
52-
logging: {}
52+
logging:
53+
format: text
5354
makeIPTablesUtilChains: true
5455
maxOpenFiles: 1000000
5556
maxPods: 110

pkg/kubelet/apis/config/scheme/testdata/KubeletConfiguration/roundtrip/default/v1beta1.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ iptablesMasqueradeBit: 14
4949
kind: KubeletConfiguration
5050
kubeAPIBurst: 10
5151
kubeAPIQPS: 5
52-
logging: {}
52+
logging:
53+
format: text
5354
makeIPTablesUtilChains: true
5455
maxOpenFiles: 1000000
5556
maxPods: 110

pkg/kubelet/apis/config/v1beta1/defaults.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121

2222
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2323
kruntime "k8s.io/apimachinery/pkg/runtime"
24+
componentbaseconfigv1alpha1 "k8s.io/component-base/config/v1alpha1"
2425
kubeletconfigv1beta1 "k8s.io/kubelet/config/v1beta1"
2526
// TODO: Cut references to k8s.io/kubernetes, eventually there should be none from this package
2627
"k8s.io/kubernetes/pkg/kubelet/qos"
@@ -233,4 +234,6 @@ func SetDefaults_KubeletConfiguration(obj *kubeletconfigv1beta1.KubeletConfigura
233234
if obj.VolumePluginDir == "" {
234235
obj.VolumePluginDir = DefaultVolumePluginDir
235236
}
237+
// Use the Default LoggingConfiguration option
238+
componentbaseconfigv1alpha1.RecommendedLoggingConfiguration(&obj.Logging)
236239
}

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,3 +95,18 @@ func NewRecommendedDebuggingConfiguration() *DebuggingConfiguration {
9595
RecommendedDebuggingConfiguration(ret)
9696
return ret
9797
}
98+
99+
// RecommendedLoggingConfiguration defaults logging configuration.
100+
// This will set the recommended default
101+
// values, but they may be subject to change between API versions. This function
102+
// is intentionally not registered in the scheme as a "normal" `SetDefaults_Foo`
103+
// function to allow consumers of this type to set whatever defaults for their
104+
// embedded configs. Forcing consumers to use these defaults would be problematic
105+
// as defaulting in the scheme is done as part of the conversion, and there would
106+
// be no easy way to opt-out. Instead, if you want to use this defaulting method
107+
// run it in your wrapper struct of this type in its `SetDefaults_` method.
108+
func RecommendedLoggingConfiguration(obj *LoggingConfiguration) {
109+
if obj.Format == "" {
110+
obj.Format = "text"
111+
}
112+
}

0 commit comments

Comments
 (0)