From ba8189a4f2bc48651463ab9afe39de1860ffcf57 Mon Sep 17 00:00:00 2001 From: amash Date: Thu, 28 May 2020 18:10:17 +0430 Subject: [PATCH 1/4] add --logging-format flag to kubelet --- cmd/kubelet/app/BUILD | 1 + cmd/kubelet/app/options/options.go | 1 + cmd/kubelet/app/server.go | 6 ++++++ pkg/kubelet/apis/config/helpers_test.go | 1 + pkg/kubelet/apis/config/types.go | 4 ++++ .../apis/config/v1beta1/zz_generated.conversion.go | 2 ++ pkg/kubelet/apis/config/validation/BUILD | 1 + pkg/kubelet/apis/config/validation/validation.go | 8 ++++++++ staging/src/k8s.io/kubelet/config/v1beta1/types.go | 5 +++++ 9 files changed, 29 insertions(+) diff --git a/cmd/kubelet/app/BUILD b/cmd/kubelet/app/BUILD index 5d71a936ea9..7a175668c21 100644 --- a/cmd/kubelet/app/BUILD +++ b/cmd/kubelet/app/BUILD @@ -111,6 +111,7 @@ go_library( "//staging/src/k8s.io/component-base/cli/flag:go_default_library", "//staging/src/k8s.io/component-base/configz:go_default_library", "//staging/src/k8s.io/component-base/featuregate:go_default_library", + "//staging/src/k8s.io/component-base/logs:go_default_library", "//staging/src/k8s.io/component-base/metrics:go_default_library", "//staging/src/k8s.io/component-base/metrics/legacyregistry:go_default_library", "//staging/src/k8s.io/component-base/version:go_default_library", diff --git a/cmd/kubelet/app/options/options.go b/cmd/kubelet/app/options/options.go index c09d3b63358..156ac3de5d7 100644 --- a/cmd/kubelet/app/options/options.go +++ b/cmd/kubelet/app/options/options.go @@ -540,6 +540,7 @@ func AddKubeletConfigFlags(mainfs *pflag.FlagSet, c *kubeletconfig.KubeletConfig fs.StringSliceVar(&c.EnforceNodeAllocatable, "enforce-node-allocatable", c.EnforceNodeAllocatable, "A comma separated list of levels of node allocatable enforcement to be enforced by kubelet. Acceptable options are 'none', 'pods', 'system-reserved', and 'kube-reserved'. If the latter two options are specified, '--system-reserved-cgroup' and '--kube-reserved-cgroup' must also be set, respectively. If 'none' is specified, no additional options should be set. See https://kubernetes.io/docs/tasks/administer-cluster/reserve-compute-resources/ for more details.") fs.StringVar(&c.SystemReservedCgroup, "system-reserved-cgroup", c.SystemReservedCgroup, "Absolute name of the top level cgroup that is used to manage non-kubernetes components for which compute resources were reserved via '--system-reserved' flag. Ex. '/system-reserved'. [default='']") fs.StringVar(&c.KubeReservedCgroup, "kube-reserved-cgroup", c.KubeReservedCgroup, "Absolute name of the top level cgroup that is used to manage kubernetes components for which compute resources were reserved via '--kube-reserved' flag. Ex. '/kube-reserved'. [default='']") + fs.StringVar(&c.LogFormat, "logging-format", c.LogFormat, "Set log format of Kubelet logging. Possible value: 'text'. Default: 'text'") // Graduated experimental flags, kept for backward compatibility fs.BoolVar(&c.KernelMemcgNotification, "experimental-kernel-memcg-notification", c.KernelMemcgNotification, "Use kernelMemcgNotification configuration, this flag will be removed in 1.23.") diff --git a/cmd/kubelet/app/server.go b/cmd/kubelet/app/server.go index 7993ec8e800..c4a27c53dfd 100644 --- a/cmd/kubelet/app/server.go +++ b/cmd/kubelet/app/server.go @@ -63,6 +63,7 @@ import ( cliflag "k8s.io/component-base/cli/flag" "k8s.io/component-base/configz" "k8s.io/component-base/featuregate" + "k8s.io/component-base/logs" "k8s.io/component-base/metrics" "k8s.io/component-base/metrics/legacyregistry" "k8s.io/component-base/version" @@ -403,6 +404,11 @@ 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(s *options.KubeletServer, kubeDeps *kubelet.Dependencies, featureGate featuregate.FeatureGate, stopCh <-chan struct{}) error { + logOption := logs.NewOptions() + if s.LogFormat != "" { + logOption.LogFormat = s.LogFormat + } + logOption.Apply() // To help debugging, immediately log version klog.Infof("Version: %+v", version.Get()) if err := initForOS(s.KubeletFlags.WindowsService); err != nil { diff --git a/pkg/kubelet/apis/config/helpers_test.go b/pkg/kubelet/apis/config/helpers_test.go index e8b4581589f..50d4e4ac643 100644 --- a/pkg/kubelet/apis/config/helpers_test.go +++ b/pkg/kubelet/apis/config/helpers_test.go @@ -195,6 +195,7 @@ var ( "KubeReservedCgroup", "KubeReserved[*]", "KubeletCgroups", + "LogFormat", "MakeIPTablesUtilChains", "RotateCertificates", "ServerTLSBootstrap", diff --git a/pkg/kubelet/apis/config/types.go b/pkg/kubelet/apis/config/types.go index 6fa4370ca37..e0a64ad0dd5 100644 --- a/pkg/kubelet/apis/config/types.go +++ b/pkg/kubelet/apis/config/types.go @@ -357,6 +357,10 @@ type KubeletConfiguration struct { // The purpose of this format is make sure you have the opportunity to notice if the next release hides additional metrics, // rather than being surprised when they are permanently removed in the release after that. ShowHiddenMetricsForVersion string + // LogFormat Flag specifies the structure of log messages. + // default value of logFormat is `text` + // Refer [Logs Options](https://github.com/kubernetes/component-base/blob/master/logs/options.go) for more information. + LogFormat string } // KubeletAuthorizationMode denotes the authorization mode for the kubelet diff --git a/pkg/kubelet/apis/config/v1beta1/zz_generated.conversion.go b/pkg/kubelet/apis/config/v1beta1/zz_generated.conversion.go index 8efd41941c1..1d5a8e81830 100644 --- a/pkg/kubelet/apis/config/v1beta1/zz_generated.conversion.go +++ b/pkg/kubelet/apis/config/v1beta1/zz_generated.conversion.go @@ -342,6 +342,7 @@ func autoConvert_v1beta1_KubeletConfiguration_To_config_KubeletConfiguration(in out.VolumePluginDir = in.VolumePluginDir out.ProviderID = in.ProviderID out.KernelMemcgNotification = in.KernelMemcgNotification + out.LogFormat = in.LogFormat return nil } @@ -486,6 +487,7 @@ func autoConvert_config_KubeletConfiguration_To_v1beta1_KubeletConfiguration(in out.EnforceNodeAllocatable = *(*[]string)(unsafe.Pointer(&in.EnforceNodeAllocatable)) out.ReservedSystemCPUs = in.ReservedSystemCPUs out.ShowHiddenMetricsForVersion = in.ShowHiddenMetricsForVersion + out.LogFormat = in.LogFormat return nil } diff --git a/pkg/kubelet/apis/config/validation/BUILD b/pkg/kubelet/apis/config/validation/BUILD index 36bb98442ff..447b9d3b1a5 100644 --- a/pkg/kubelet/apis/config/validation/BUILD +++ b/pkg/kubelet/apis/config/validation/BUILD @@ -22,6 +22,7 @@ go_library( "//staging/src/k8s.io/apimachinery/pkg/util/errors:go_default_library", "//staging/src/k8s.io/apimachinery/pkg/util/validation:go_default_library", "//staging/src/k8s.io/apiserver/pkg/util/feature:go_default_library", + "//staging/src/k8s.io/component-base/logs:go_default_library", "//staging/src/k8s.io/component-base/metrics:go_default_library", ], ) diff --git a/pkg/kubelet/apis/config/validation/validation.go b/pkg/kubelet/apis/config/validation/validation.go index 5e4d37f03fa..72ddddd9deb 100644 --- a/pkg/kubelet/apis/config/validation/validation.go +++ b/pkg/kubelet/apis/config/validation/validation.go @@ -23,6 +23,7 @@ import ( utilerrors "k8s.io/apimachinery/pkg/util/errors" utilvalidation "k8s.io/apimachinery/pkg/util/validation" utilfeature "k8s.io/apiserver/pkg/util/feature" + "k8s.io/component-base/logs" "k8s.io/component-base/metrics" "k8s.io/kubernetes/pkg/features" kubeletconfig "k8s.io/kubernetes/pkg/kubelet/apis/config" @@ -158,5 +159,12 @@ func ValidateKubeletConfiguration(kc *kubeletconfig.KubeletConfiguration) error allErrors = append(allErrors, err) } allErrors = append(allErrors, metrics.ValidateShowHiddenMetricsVersion(kc.ShowHiddenMetricsForVersion)...) + + logOption := logs.NewOptions() + if kc.LogFormat != "" { + logOption.LogFormat = kc.LogFormat + } + allErrors = append(allErrors, logOption.Validate()...) + return utilerrors.NewAggregate(allErrors) } diff --git a/staging/src/k8s.io/kubelet/config/v1beta1/types.go b/staging/src/k8s.io/kubelet/config/v1beta1/types.go index 144c1d371dd..72418949a0d 100644 --- a/staging/src/k8s.io/kubelet/config/v1beta1/types.go +++ b/staging/src/k8s.io/kubelet/config/v1beta1/types.go @@ -793,6 +793,11 @@ type KubeletConfiguration struct { // Default: false // +optional KernelMemcgNotification bool `json:"kernelMemcgNotification,omitempty"` + // LogFormat specifies the structure of log messages. + // Refer [Logs Options](https://github.com/kubernetes/component-base/blob/master/logs/options.go) for more information. + // Default: "text" + // + optional + LogFormat string `json:"logFormat,omitempty"` } type KubeletAuthorizationMode string From ac8d2e897876c3c823a91ce4ab9ae2a908aff8e3 Mon Sep 17 00:00:00 2001 From: amash Date: Tue, 16 Jun 2020 15:17:14 +0430 Subject: [PATCH 2/4] add loggingConfig struct to kubelet config --- .../app/componentconfigs/kubelet_test.go | 2 + cmd/kubelet/app/options/options.go | 2 +- cmd/kubelet/app/server.go | 4 +- pkg/kubelet/apis/config/helpers_test.go | 2 +- .../KubeletConfiguration/after/v1beta1.yaml | 1 + .../roundtrip/default/v1beta1.yaml | 1 + pkg/kubelet/apis/config/types.go | 13 +++++-- .../config/v1beta1/zz_generated.conversion.go | 38 ++++++++++++++++++- .../apis/config/validation/validation.go | 4 +- .../apis/config/zz_generated.deepcopy.go | 17 +++++++++ .../k8s.io/kubelet/config/v1beta1/types.go | 15 ++++++-- .../config/v1beta1/zz_generated.deepcopy.go | 17 +++++++++ 12 files changed, 102 insertions(+), 14 deletions(-) diff --git a/cmd/kubeadm/app/componentconfigs/kubelet_test.go b/cmd/kubeadm/app/componentconfigs/kubelet_test.go index d6f86c721a1..ea2e39d12d0 100644 --- a/cmd/kubeadm/app/componentconfigs/kubelet_test.go +++ b/cmd/kubeadm/app/componentconfigs/kubelet_test.go @@ -76,6 +76,7 @@ var kubeletMarshalCases = []struct { httpCheckFrequency: 0s imageMinimumGCAge: 0s kind: KubeletConfiguration + loggingConfig: {} nodeStatusReportFrequency: 0s nodeStatusUpdateFrequency: 0s runtimeRequestTimeout: 0s @@ -118,6 +119,7 @@ var kubeletMarshalCases = []struct { httpCheckFrequency: 0s imageMinimumGCAge: 0s kind: KubeletConfiguration + loggingConfig: {} nodeStatusReportFrequency: 0s nodeStatusUpdateFrequency: 0s port: 12345 diff --git a/cmd/kubelet/app/options/options.go b/cmd/kubelet/app/options/options.go index 156ac3de5d7..cfddd73e58c 100644 --- a/cmd/kubelet/app/options/options.go +++ b/cmd/kubelet/app/options/options.go @@ -540,7 +540,7 @@ func AddKubeletConfigFlags(mainfs *pflag.FlagSet, c *kubeletconfig.KubeletConfig fs.StringSliceVar(&c.EnforceNodeAllocatable, "enforce-node-allocatable", c.EnforceNodeAllocatable, "A comma separated list of levels of node allocatable enforcement to be enforced by kubelet. Acceptable options are 'none', 'pods', 'system-reserved', and 'kube-reserved'. If the latter two options are specified, '--system-reserved-cgroup' and '--kube-reserved-cgroup' must also be set, respectively. If 'none' is specified, no additional options should be set. See https://kubernetes.io/docs/tasks/administer-cluster/reserve-compute-resources/ for more details.") fs.StringVar(&c.SystemReservedCgroup, "system-reserved-cgroup", c.SystemReservedCgroup, "Absolute name of the top level cgroup that is used to manage non-kubernetes components for which compute resources were reserved via '--system-reserved' flag. Ex. '/system-reserved'. [default='']") fs.StringVar(&c.KubeReservedCgroup, "kube-reserved-cgroup", c.KubeReservedCgroup, "Absolute name of the top level cgroup that is used to manage kubernetes components for which compute resources were reserved via '--kube-reserved' flag. Ex. '/kube-reserved'. [default='']") - fs.StringVar(&c.LogFormat, "logging-format", c.LogFormat, "Set log format of Kubelet logging. Possible value: 'text'. Default: 'text'") + fs.StringVar(&c.LoggingConfig.LoggingFormat, "logging-format", c.LoggingConfig.LoggingFormat, `Sets the log format. Permitted formats: "text", "json".\nNon-default formats don't honor these flags: -add_dir_header, --alsologtostderr, --log_backtrace_at, --log_dir, --log_file, --log_file_max_size, --logtostderr, --skip_headers, --skip_log_headers, --stderrthreshold, --log-flush-frequency.\nNon-default choices are currently alpha and subject to change without warning.`) // Graduated experimental flags, kept for backward compatibility fs.BoolVar(&c.KernelMemcgNotification, "experimental-kernel-memcg-notification", c.KernelMemcgNotification, "Use kernelMemcgNotification configuration, this flag will be removed in 1.23.") diff --git a/cmd/kubelet/app/server.go b/cmd/kubelet/app/server.go index c4a27c53dfd..add693cb655 100644 --- a/cmd/kubelet/app/server.go +++ b/cmd/kubelet/app/server.go @@ -405,8 +405,8 @@ func UnsecuredDependencies(s *options.KubeletServer, featureGate featuregate.Fea // not be generated. func Run(s *options.KubeletServer, kubeDeps *kubelet.Dependencies, featureGate featuregate.FeatureGate, stopCh <-chan struct{}) error { logOption := logs.NewOptions() - if s.LogFormat != "" { - logOption.LogFormat = s.LogFormat + if s.LoggingConfig.LoggingFormat != "" { + logOption.LogFormat = s.LoggingConfig.LoggingFormat } logOption.Apply() // To help debugging, immediately log version diff --git a/pkg/kubelet/apis/config/helpers_test.go b/pkg/kubelet/apis/config/helpers_test.go index 50d4e4ac643..04db077f8d5 100644 --- a/pkg/kubelet/apis/config/helpers_test.go +++ b/pkg/kubelet/apis/config/helpers_test.go @@ -182,6 +182,7 @@ var ( "HairpinMode", "HealthzBindAddress", "HealthzPort", + "LoggingConfig.LoggingFormat", "TLSCipherSuites[*]", "TLSMinVersion", "IPTablesDropBit", @@ -195,7 +196,6 @@ var ( "KubeReservedCgroup", "KubeReserved[*]", "KubeletCgroups", - "LogFormat", "MakeIPTablesUtilChains", "RotateCertificates", "ServerTLSBootstrap", diff --git a/pkg/kubelet/apis/config/scheme/testdata/KubeletConfiguration/after/v1beta1.yaml b/pkg/kubelet/apis/config/scheme/testdata/KubeletConfiguration/after/v1beta1.yaml index 703b742b4ab..dae88584af9 100644 --- a/pkg/kubelet/apis/config/scheme/testdata/KubeletConfiguration/after/v1beta1.yaml +++ b/pkg/kubelet/apis/config/scheme/testdata/KubeletConfiguration/after/v1beta1.yaml @@ -49,6 +49,7 @@ iptablesMasqueradeBit: 14 kind: KubeletConfiguration kubeAPIBurst: 10 kubeAPIQPS: 5 +loggingConfig: {} makeIPTablesUtilChains: true maxOpenFiles: 1000000 maxPods: 110 diff --git a/pkg/kubelet/apis/config/scheme/testdata/KubeletConfiguration/roundtrip/default/v1beta1.yaml b/pkg/kubelet/apis/config/scheme/testdata/KubeletConfiguration/roundtrip/default/v1beta1.yaml index 703b742b4ab..dae88584af9 100644 --- a/pkg/kubelet/apis/config/scheme/testdata/KubeletConfiguration/roundtrip/default/v1beta1.yaml +++ b/pkg/kubelet/apis/config/scheme/testdata/KubeletConfiguration/roundtrip/default/v1beta1.yaml @@ -49,6 +49,7 @@ iptablesMasqueradeBit: 14 kind: KubeletConfiguration kubeAPIBurst: 10 kubeAPIQPS: 5 +loggingConfig: {} makeIPTablesUtilChains: true maxOpenFiles: 1000000 maxPods: 110 diff --git a/pkg/kubelet/apis/config/types.go b/pkg/kubelet/apis/config/types.go index e0a64ad0dd5..bbc11293ef2 100644 --- a/pkg/kubelet/apis/config/types.go +++ b/pkg/kubelet/apis/config/types.go @@ -357,10 +357,9 @@ type KubeletConfiguration struct { // The purpose of this format is make sure you have the opportunity to notice if the next release hides additional metrics, // rather than being surprised when they are permanently removed in the release after that. ShowHiddenMetricsForVersion string - // LogFormat Flag specifies the structure of log messages. - // default value of logFormat is `text` + // LoggingConfig specifies the options of logging. // Refer [Logs Options](https://github.com/kubernetes/component-base/blob/master/logs/options.go) for more information. - LogFormat string + LoggingConfig LoggingConfig } // KubeletAuthorizationMode denotes the authorization mode for the kubelet @@ -438,3 +437,11 @@ type SerializedNodeConfigSource struct { // +optional Source v1.NodeConfigSource } + +// LoggingConfig contains logging options +type LoggingConfig struct { + // LoggingFormat Flag specifies the structure of log messages. + // default value of loggingFormat is `text` + // Refer [Logs Options](https://github.com/kubernetes/component-base/blob/master/logs/options.go) for more information. + LoggingFormat string +} diff --git a/pkg/kubelet/apis/config/v1beta1/zz_generated.conversion.go b/pkg/kubelet/apis/config/v1beta1/zz_generated.conversion.go index 1d5a8e81830..767c90a7d89 100644 --- a/pkg/kubelet/apis/config/v1beta1/zz_generated.conversion.go +++ b/pkg/kubelet/apis/config/v1beta1/zz_generated.conversion.go @@ -107,6 +107,16 @@ func RegisterConversions(s *runtime.Scheme) error { }); err != nil { return err } + if err := s.AddGeneratedConversionFunc((*v1beta1.LoggingConfig)(nil), (*config.LoggingConfig)(nil), func(a, b interface{}, scope conversion.Scope) error { + return Convert_v1beta1_LoggingConfig_To_config_LoggingConfig(a.(*v1beta1.LoggingConfig), b.(*config.LoggingConfig), scope) + }); err != nil { + return err + } + if err := s.AddGeneratedConversionFunc((*config.LoggingConfig)(nil), (*v1beta1.LoggingConfig)(nil), func(a, b interface{}, scope conversion.Scope) error { + return Convert_config_LoggingConfig_To_v1beta1_LoggingConfig(a.(*config.LoggingConfig), b.(*v1beta1.LoggingConfig), scope) + }); err != nil { + return err + } if err := s.AddGeneratedConversionFunc((*v1beta1.SerializedNodeConfigSource)(nil), (*config.SerializedNodeConfigSource)(nil), func(a, b interface{}, scope conversion.Scope) error { return Convert_v1beta1_SerializedNodeConfigSource_To_config_SerializedNodeConfigSource(a.(*v1beta1.SerializedNodeConfigSource), b.(*config.SerializedNodeConfigSource), scope) }); err != nil { @@ -342,7 +352,9 @@ func autoConvert_v1beta1_KubeletConfiguration_To_config_KubeletConfiguration(in out.VolumePluginDir = in.VolumePluginDir out.ProviderID = in.ProviderID out.KernelMemcgNotification = in.KernelMemcgNotification - out.LogFormat = in.LogFormat + if err := Convert_v1beta1_LoggingConfig_To_config_LoggingConfig(&in.LoggingConfig, &out.LoggingConfig, s); err != nil { + return err + } return nil } @@ -487,7 +499,9 @@ func autoConvert_config_KubeletConfiguration_To_v1beta1_KubeletConfiguration(in out.EnforceNodeAllocatable = *(*[]string)(unsafe.Pointer(&in.EnforceNodeAllocatable)) out.ReservedSystemCPUs = in.ReservedSystemCPUs out.ShowHiddenMetricsForVersion = in.ShowHiddenMetricsForVersion - out.LogFormat = in.LogFormat + if err := Convert_config_LoggingConfig_To_v1beta1_LoggingConfig(&in.LoggingConfig, &out.LoggingConfig, s); err != nil { + return err + } return nil } @@ -564,6 +578,26 @@ func Convert_config_KubeletX509Authentication_To_v1beta1_KubeletX509Authenticati return autoConvert_config_KubeletX509Authentication_To_v1beta1_KubeletX509Authentication(in, out, s) } +func autoConvert_v1beta1_LoggingConfig_To_config_LoggingConfig(in *v1beta1.LoggingConfig, out *config.LoggingConfig, s conversion.Scope) error { + out.LoggingFormat = in.LoggingFormat + return nil +} + +// Convert_v1beta1_LoggingConfig_To_config_LoggingConfig is an autogenerated conversion function. +func Convert_v1beta1_LoggingConfig_To_config_LoggingConfig(in *v1beta1.LoggingConfig, out *config.LoggingConfig, s conversion.Scope) error { + return autoConvert_v1beta1_LoggingConfig_To_config_LoggingConfig(in, out, s) +} + +func autoConvert_config_LoggingConfig_To_v1beta1_LoggingConfig(in *config.LoggingConfig, out *v1beta1.LoggingConfig, s conversion.Scope) error { + out.LoggingFormat = in.LoggingFormat + return nil +} + +// Convert_config_LoggingConfig_To_v1beta1_LoggingConfig is an autogenerated conversion function. +func Convert_config_LoggingConfig_To_v1beta1_LoggingConfig(in *config.LoggingConfig, out *v1beta1.LoggingConfig, s conversion.Scope) error { + return autoConvert_config_LoggingConfig_To_v1beta1_LoggingConfig(in, out, s) +} + func autoConvert_v1beta1_SerializedNodeConfigSource_To_config_SerializedNodeConfigSource(in *v1beta1.SerializedNodeConfigSource, out *config.SerializedNodeConfigSource, s conversion.Scope) error { out.Source = in.Source return nil diff --git a/pkg/kubelet/apis/config/validation/validation.go b/pkg/kubelet/apis/config/validation/validation.go index 72ddddd9deb..b5ee7baf2f3 100644 --- a/pkg/kubelet/apis/config/validation/validation.go +++ b/pkg/kubelet/apis/config/validation/validation.go @@ -161,8 +161,8 @@ func ValidateKubeletConfiguration(kc *kubeletconfig.KubeletConfiguration) error allErrors = append(allErrors, metrics.ValidateShowHiddenMetricsVersion(kc.ShowHiddenMetricsForVersion)...) logOption := logs.NewOptions() - if kc.LogFormat != "" { - logOption.LogFormat = kc.LogFormat + if kc.LoggingConfig.LoggingFormat != "" { + logOption.LogFormat = kc.LoggingConfig.LoggingFormat } allErrors = append(allErrors, logOption.Validate()...) diff --git a/pkg/kubelet/apis/config/zz_generated.deepcopy.go b/pkg/kubelet/apis/config/zz_generated.deepcopy.go index 35acde4a0d6..7d423a29007 100644 --- a/pkg/kubelet/apis/config/zz_generated.deepcopy.go +++ b/pkg/kubelet/apis/config/zz_generated.deepcopy.go @@ -185,6 +185,7 @@ func (in *KubeletConfiguration) DeepCopyInto(out *KubeletConfiguration) { *out = make([]string, len(*in)) copy(*out, *in) } + out.LoggingConfig = in.LoggingConfig return } @@ -257,6 +258,22 @@ func (in *KubeletX509Authentication) DeepCopy() *KubeletX509Authentication { return out } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *LoggingConfig) DeepCopyInto(out *LoggingConfig) { + *out = *in + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new LoggingConfig. +func (in *LoggingConfig) DeepCopy() *LoggingConfig { + if in == nil { + return nil + } + out := new(LoggingConfig) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *SerializedNodeConfigSource) DeepCopyInto(out *SerializedNodeConfigSource) { *out = *in diff --git a/staging/src/k8s.io/kubelet/config/v1beta1/types.go b/staging/src/k8s.io/kubelet/config/v1beta1/types.go index 72418949a0d..bb9c91174ef 100644 --- a/staging/src/k8s.io/kubelet/config/v1beta1/types.go +++ b/staging/src/k8s.io/kubelet/config/v1beta1/types.go @@ -793,11 +793,12 @@ type KubeletConfiguration struct { // Default: false // +optional KernelMemcgNotification bool `json:"kernelMemcgNotification,omitempty"` - // LogFormat specifies the structure of log messages. + // LoggingConfig specifies the options of logging. // Refer [Logs Options](https://github.com/kubernetes/component-base/blob/master/logs/options.go) for more information. - // Default: "text" + // Defaults: + // loggingFormat: text // + optional - LogFormat string `json:"logFormat,omitempty"` + LoggingConfig LoggingConfig `json:"loggingConfig,omitempty"` } type KubeletAuthorizationMode string @@ -878,3 +879,11 @@ type SerializedNodeConfigSource struct { // +optional Source v1.NodeConfigSource `json:"source,omitempty" protobuf:"bytes,1,opt,name=source"` } + +// LoggingConfig contains logging options +type LoggingConfig struct { + // LoggingFormat Flag specifies the structure of log messages. + // default value of loggingFormat is `text` + // Refer [Logs Options](https://github.com/kubernetes/component-base/blob/master/logs/options.go) for more information. + LoggingFormat string `json:"loggingFormat,omitempty"` +} diff --git a/staging/src/k8s.io/kubelet/config/v1beta1/zz_generated.deepcopy.go b/staging/src/k8s.io/kubelet/config/v1beta1/zz_generated.deepcopy.go index 176d1643235..6d381892efc 100644 --- a/staging/src/k8s.io/kubelet/config/v1beta1/zz_generated.deepcopy.go +++ b/staging/src/k8s.io/kubelet/config/v1beta1/zz_generated.deepcopy.go @@ -295,6 +295,7 @@ func (in *KubeletConfiguration) DeepCopyInto(out *KubeletConfiguration) { *out = make([]string, len(*in)) copy(*out, *in) } + out.LoggingConfig = in.LoggingConfig return } @@ -372,6 +373,22 @@ func (in *KubeletX509Authentication) DeepCopy() *KubeletX509Authentication { return out } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *LoggingConfig) DeepCopyInto(out *LoggingConfig) { + *out = *in + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new LoggingConfig. +func (in *LoggingConfig) DeepCopy() *LoggingConfig { + if in == nil { + return nil + } + out := new(LoggingConfig) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *SerializedNodeConfigSource) DeepCopyInto(out *SerializedNodeConfigSource) { *out = *in From 3ab25f18766d83ca56672880aae77fa4cece0e91 Mon Sep 17 00:00:00 2001 From: amash Date: Fri, 26 Jun 2020 01:03:27 +0430 Subject: [PATCH 3/4] add LoggingConfiguration struct to component-base/config --- .../app/componentconfigs/kubelet_test.go | 4 +-- cmd/kubelet/app/options/options.go | 2 +- cmd/kubelet/app/server.go | 4 +-- pkg/kubelet/apis/config/BUILD | 1 + pkg/kubelet/apis/config/helpers_test.go | 2 +- .../KubeletConfiguration/after/v1beta1.yaml | 2 +- .../roundtrip/default/v1beta1.yaml | 2 +- pkg/kubelet/apis/config/types.go | 13 ++----- pkg/kubelet/apis/config/v1beta1/BUILD | 1 + .../config/v1beta1/zz_generated.conversion.go | 35 ++----------------- .../apis/config/validation/validation.go | 4 +-- .../apis/config/zz_generated.deepcopy.go | 18 +--------- .../src/k8s.io/component-base/config/types.go | 8 +++++ .../config/v1alpha1/conversion.go | 8 +++++ .../component-base/config/v1alpha1/types.go | 8 +++++ .../v1alpha1/zz_generated.conversion.go | 20 +++++++++++ .../config/v1alpha1/zz_generated.deepcopy.go | 16 +++++++++ .../config/zz_generated.deepcopy.go | 16 +++++++++ .../src/k8s.io/kubelet/config/v1beta1/BUILD | 1 + .../k8s.io/kubelet/config/v1beta1/types.go | 15 +++----- .../config/v1beta1/zz_generated.deepcopy.go | 18 +--------- staging/src/k8s.io/kubelet/go.sum | 1 + 22 files changed, 102 insertions(+), 97 deletions(-) diff --git a/cmd/kubeadm/app/componentconfigs/kubelet_test.go b/cmd/kubeadm/app/componentconfigs/kubelet_test.go index ea2e39d12d0..b23106c4021 100644 --- a/cmd/kubeadm/app/componentconfigs/kubelet_test.go +++ b/cmd/kubeadm/app/componentconfigs/kubelet_test.go @@ -76,7 +76,7 @@ var kubeletMarshalCases = []struct { httpCheckFrequency: 0s imageMinimumGCAge: 0s kind: KubeletConfiguration - loggingConfig: {} + logging: {} nodeStatusReportFrequency: 0s nodeStatusUpdateFrequency: 0s runtimeRequestTimeout: 0s @@ -119,7 +119,7 @@ var kubeletMarshalCases = []struct { httpCheckFrequency: 0s imageMinimumGCAge: 0s kind: KubeletConfiguration - loggingConfig: {} + logging: {} nodeStatusReportFrequency: 0s nodeStatusUpdateFrequency: 0s port: 12345 diff --git a/cmd/kubelet/app/options/options.go b/cmd/kubelet/app/options/options.go index cfddd73e58c..9c5fa11b66b 100644 --- a/cmd/kubelet/app/options/options.go +++ b/cmd/kubelet/app/options/options.go @@ -540,7 +540,7 @@ func AddKubeletConfigFlags(mainfs *pflag.FlagSet, c *kubeletconfig.KubeletConfig fs.StringSliceVar(&c.EnforceNodeAllocatable, "enforce-node-allocatable", c.EnforceNodeAllocatable, "A comma separated list of levels of node allocatable enforcement to be enforced by kubelet. Acceptable options are 'none', 'pods', 'system-reserved', and 'kube-reserved'. If the latter two options are specified, '--system-reserved-cgroup' and '--kube-reserved-cgroup' must also be set, respectively. If 'none' is specified, no additional options should be set. See https://kubernetes.io/docs/tasks/administer-cluster/reserve-compute-resources/ for more details.") fs.StringVar(&c.SystemReservedCgroup, "system-reserved-cgroup", c.SystemReservedCgroup, "Absolute name of the top level cgroup that is used to manage non-kubernetes components for which compute resources were reserved via '--system-reserved' flag. Ex. '/system-reserved'. [default='']") fs.StringVar(&c.KubeReservedCgroup, "kube-reserved-cgroup", c.KubeReservedCgroup, "Absolute name of the top level cgroup that is used to manage kubernetes components for which compute resources were reserved via '--kube-reserved' flag. Ex. '/kube-reserved'. [default='']") - fs.StringVar(&c.LoggingConfig.LoggingFormat, "logging-format", c.LoggingConfig.LoggingFormat, `Sets the log format. Permitted formats: "text", "json".\nNon-default formats don't honor these flags: -add_dir_header, --alsologtostderr, --log_backtrace_at, --log_dir, --log_file, --log_file_max_size, --logtostderr, --skip_headers, --skip_log_headers, --stderrthreshold, --log-flush-frequency.\nNon-default choices are currently alpha and subject to change without warning.`) + fs.StringVar(&c.Logging.Format, "logging-format", c.Logging.Format, `Sets the log format. Permitted formats: "text", "json".\nNon-default formats don't honor these flags: -add_dir_header, --alsologtostderr, --log_backtrace_at, --log_dir, --log_file, --log_file_max_size, --logtostderr, --skip_headers, --skip_log_headers, --stderrthreshold, --log-flush-frequency.\nNon-default choices are currently alpha and subject to change without warning.`) // Graduated experimental flags, kept for backward compatibility fs.BoolVar(&c.KernelMemcgNotification, "experimental-kernel-memcg-notification", c.KernelMemcgNotification, "Use kernelMemcgNotification configuration, this flag will be removed in 1.23.") diff --git a/cmd/kubelet/app/server.go b/cmd/kubelet/app/server.go index add693cb655..b5dfd9ddf35 100644 --- a/cmd/kubelet/app/server.go +++ b/cmd/kubelet/app/server.go @@ -405,8 +405,8 @@ func UnsecuredDependencies(s *options.KubeletServer, featureGate featuregate.Fea // not be generated. func Run(s *options.KubeletServer, kubeDeps *kubelet.Dependencies, featureGate featuregate.FeatureGate, stopCh <-chan struct{}) error { logOption := logs.NewOptions() - if s.LoggingConfig.LoggingFormat != "" { - logOption.LogFormat = s.LoggingConfig.LoggingFormat + if s.Logging.Format != "" { + logOption.LogFormat = s.Logging.Format } logOption.Apply() // To help debugging, immediately log version diff --git a/pkg/kubelet/apis/config/BUILD b/pkg/kubelet/apis/config/BUILD index 5063004da2a..53d67a8ee21 100644 --- a/pkg/kubelet/apis/config/BUILD +++ b/pkg/kubelet/apis/config/BUILD @@ -21,6 +21,7 @@ go_library( "//staging/src/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library", "//staging/src/k8s.io/apimachinery/pkg/runtime:go_default_library", "//staging/src/k8s.io/apimachinery/pkg/runtime/schema:go_default_library", + "//staging/src/k8s.io/component-base/config:go_default_library", ], ) diff --git a/pkg/kubelet/apis/config/helpers_test.go b/pkg/kubelet/apis/config/helpers_test.go index 04db077f8d5..115ec8150ce 100644 --- a/pkg/kubelet/apis/config/helpers_test.go +++ b/pkg/kubelet/apis/config/helpers_test.go @@ -182,7 +182,7 @@ var ( "HairpinMode", "HealthzBindAddress", "HealthzPort", - "LoggingConfig.LoggingFormat", + "Logging.Format", "TLSCipherSuites[*]", "TLSMinVersion", "IPTablesDropBit", diff --git a/pkg/kubelet/apis/config/scheme/testdata/KubeletConfiguration/after/v1beta1.yaml b/pkg/kubelet/apis/config/scheme/testdata/KubeletConfiguration/after/v1beta1.yaml index dae88584af9..e73f503301e 100644 --- a/pkg/kubelet/apis/config/scheme/testdata/KubeletConfiguration/after/v1beta1.yaml +++ b/pkg/kubelet/apis/config/scheme/testdata/KubeletConfiguration/after/v1beta1.yaml @@ -49,7 +49,7 @@ iptablesMasqueradeBit: 14 kind: KubeletConfiguration kubeAPIBurst: 10 kubeAPIQPS: 5 -loggingConfig: {} +logging: {} makeIPTablesUtilChains: true maxOpenFiles: 1000000 maxPods: 110 diff --git a/pkg/kubelet/apis/config/scheme/testdata/KubeletConfiguration/roundtrip/default/v1beta1.yaml b/pkg/kubelet/apis/config/scheme/testdata/KubeletConfiguration/roundtrip/default/v1beta1.yaml index dae88584af9..e73f503301e 100644 --- a/pkg/kubelet/apis/config/scheme/testdata/KubeletConfiguration/roundtrip/default/v1beta1.yaml +++ b/pkg/kubelet/apis/config/scheme/testdata/KubeletConfiguration/roundtrip/default/v1beta1.yaml @@ -49,7 +49,7 @@ iptablesMasqueradeBit: 14 kind: KubeletConfiguration kubeAPIBurst: 10 kubeAPIQPS: 5 -loggingConfig: {} +logging: {} makeIPTablesUtilChains: true maxOpenFiles: 1000000 maxPods: 110 diff --git a/pkg/kubelet/apis/config/types.go b/pkg/kubelet/apis/config/types.go index bbc11293ef2..bead9bad55e 100644 --- a/pkg/kubelet/apis/config/types.go +++ b/pkg/kubelet/apis/config/types.go @@ -19,6 +19,7 @@ package config import ( v1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + componentbaseconfig "k8s.io/component-base/config" ) // HairpinMode denotes how the kubelet should configure networking to handle @@ -357,9 +358,9 @@ type KubeletConfiguration struct { // The purpose of this format is make sure you have the opportunity to notice if the next release hides additional metrics, // rather than being surprised when they are permanently removed in the release after that. ShowHiddenMetricsForVersion string - // LoggingConfig specifies the options of logging. + // Logging specifies the options of logging. // Refer [Logs Options](https://github.com/kubernetes/component-base/blob/master/logs/options.go) for more information. - LoggingConfig LoggingConfig + Logging componentbaseconfig.LoggingConfiguration } // KubeletAuthorizationMode denotes the authorization mode for the kubelet @@ -437,11 +438,3 @@ type SerializedNodeConfigSource struct { // +optional Source v1.NodeConfigSource } - -// LoggingConfig contains logging options -type LoggingConfig struct { - // LoggingFormat Flag specifies the structure of log messages. - // default value of loggingFormat is `text` - // Refer [Logs Options](https://github.com/kubernetes/component-base/blob/master/logs/options.go) for more information. - LoggingFormat string -} diff --git a/pkg/kubelet/apis/config/v1beta1/BUILD b/pkg/kubelet/apis/config/v1beta1/BUILD index c747871adbc..40aac29fe9c 100644 --- a/pkg/kubelet/apis/config/v1beta1/BUILD +++ b/pkg/kubelet/apis/config/v1beta1/BUILD @@ -27,6 +27,7 @@ go_library( "//staging/src/k8s.io/apimachinery/pkg/conversion:go_default_library", "//staging/src/k8s.io/apimachinery/pkg/runtime:go_default_library", "//staging/src/k8s.io/apimachinery/pkg/runtime/schema:go_default_library", + "//staging/src/k8s.io/component-base/config/v1alpha1:go_default_library", "//staging/src/k8s.io/kubelet/config/v1beta1:go_default_library", "//vendor/k8s.io/utils/pointer:go_default_library", ], diff --git a/pkg/kubelet/apis/config/v1beta1/zz_generated.conversion.go b/pkg/kubelet/apis/config/v1beta1/zz_generated.conversion.go index 767c90a7d89..f8f4c947616 100644 --- a/pkg/kubelet/apis/config/v1beta1/zz_generated.conversion.go +++ b/pkg/kubelet/apis/config/v1beta1/zz_generated.conversion.go @@ -26,6 +26,7 @@ import ( v1 "k8s.io/apimachinery/pkg/apis/meta/v1" conversion "k8s.io/apimachinery/pkg/conversion" runtime "k8s.io/apimachinery/pkg/runtime" + v1alpha1 "k8s.io/component-base/config/v1alpha1" v1beta1 "k8s.io/kubelet/config/v1beta1" config "k8s.io/kubernetes/pkg/kubelet/apis/config" ) @@ -107,16 +108,6 @@ func RegisterConversions(s *runtime.Scheme) error { }); err != nil { return err } - if err := s.AddGeneratedConversionFunc((*v1beta1.LoggingConfig)(nil), (*config.LoggingConfig)(nil), func(a, b interface{}, scope conversion.Scope) error { - return Convert_v1beta1_LoggingConfig_To_config_LoggingConfig(a.(*v1beta1.LoggingConfig), b.(*config.LoggingConfig), scope) - }); err != nil { - return err - } - if err := s.AddGeneratedConversionFunc((*config.LoggingConfig)(nil), (*v1beta1.LoggingConfig)(nil), func(a, b interface{}, scope conversion.Scope) error { - return Convert_config_LoggingConfig_To_v1beta1_LoggingConfig(a.(*config.LoggingConfig), b.(*v1beta1.LoggingConfig), scope) - }); err != nil { - return err - } if err := s.AddGeneratedConversionFunc((*v1beta1.SerializedNodeConfigSource)(nil), (*config.SerializedNodeConfigSource)(nil), func(a, b interface{}, scope conversion.Scope) error { return Convert_v1beta1_SerializedNodeConfigSource_To_config_SerializedNodeConfigSource(a.(*v1beta1.SerializedNodeConfigSource), b.(*config.SerializedNodeConfigSource), scope) }); err != nil { @@ -352,7 +343,7 @@ func autoConvert_v1beta1_KubeletConfiguration_To_config_KubeletConfiguration(in out.VolumePluginDir = in.VolumePluginDir out.ProviderID = in.ProviderID out.KernelMemcgNotification = in.KernelMemcgNotification - if err := Convert_v1beta1_LoggingConfig_To_config_LoggingConfig(&in.LoggingConfig, &out.LoggingConfig, s); err != nil { + if err := v1alpha1.Convert_v1alpha1_LoggingConfiguration_To_config_LoggingConfiguration(&in.Logging, &out.Logging, s); err != nil { return err } return nil @@ -499,7 +490,7 @@ func autoConvert_config_KubeletConfiguration_To_v1beta1_KubeletConfiguration(in out.EnforceNodeAllocatable = *(*[]string)(unsafe.Pointer(&in.EnforceNodeAllocatable)) out.ReservedSystemCPUs = in.ReservedSystemCPUs out.ShowHiddenMetricsForVersion = in.ShowHiddenMetricsForVersion - if err := Convert_config_LoggingConfig_To_v1beta1_LoggingConfig(&in.LoggingConfig, &out.LoggingConfig, s); err != nil { + if err := v1alpha1.Convert_config_LoggingConfiguration_To_v1alpha1_LoggingConfiguration(&in.Logging, &out.Logging, s); err != nil { return err } return nil @@ -578,26 +569,6 @@ func Convert_config_KubeletX509Authentication_To_v1beta1_KubeletX509Authenticati return autoConvert_config_KubeletX509Authentication_To_v1beta1_KubeletX509Authentication(in, out, s) } -func autoConvert_v1beta1_LoggingConfig_To_config_LoggingConfig(in *v1beta1.LoggingConfig, out *config.LoggingConfig, s conversion.Scope) error { - out.LoggingFormat = in.LoggingFormat - return nil -} - -// Convert_v1beta1_LoggingConfig_To_config_LoggingConfig is an autogenerated conversion function. -func Convert_v1beta1_LoggingConfig_To_config_LoggingConfig(in *v1beta1.LoggingConfig, out *config.LoggingConfig, s conversion.Scope) error { - return autoConvert_v1beta1_LoggingConfig_To_config_LoggingConfig(in, out, s) -} - -func autoConvert_config_LoggingConfig_To_v1beta1_LoggingConfig(in *config.LoggingConfig, out *v1beta1.LoggingConfig, s conversion.Scope) error { - out.LoggingFormat = in.LoggingFormat - return nil -} - -// Convert_config_LoggingConfig_To_v1beta1_LoggingConfig is an autogenerated conversion function. -func Convert_config_LoggingConfig_To_v1beta1_LoggingConfig(in *config.LoggingConfig, out *v1beta1.LoggingConfig, s conversion.Scope) error { - return autoConvert_config_LoggingConfig_To_v1beta1_LoggingConfig(in, out, s) -} - func autoConvert_v1beta1_SerializedNodeConfigSource_To_config_SerializedNodeConfigSource(in *v1beta1.SerializedNodeConfigSource, out *config.SerializedNodeConfigSource, s conversion.Scope) error { out.Source = in.Source return nil diff --git a/pkg/kubelet/apis/config/validation/validation.go b/pkg/kubelet/apis/config/validation/validation.go index b5ee7baf2f3..9afa64205e0 100644 --- a/pkg/kubelet/apis/config/validation/validation.go +++ b/pkg/kubelet/apis/config/validation/validation.go @@ -161,8 +161,8 @@ func ValidateKubeletConfiguration(kc *kubeletconfig.KubeletConfiguration) error allErrors = append(allErrors, metrics.ValidateShowHiddenMetricsVersion(kc.ShowHiddenMetricsForVersion)...) logOption := logs.NewOptions() - if kc.LoggingConfig.LoggingFormat != "" { - logOption.LogFormat = kc.LoggingConfig.LoggingFormat + if kc.Logging.Format != "" { + logOption.LogFormat = kc.Logging.Format } allErrors = append(allErrors, logOption.Validate()...) diff --git a/pkg/kubelet/apis/config/zz_generated.deepcopy.go b/pkg/kubelet/apis/config/zz_generated.deepcopy.go index 7d423a29007..87b3969325c 100644 --- a/pkg/kubelet/apis/config/zz_generated.deepcopy.go +++ b/pkg/kubelet/apis/config/zz_generated.deepcopy.go @@ -185,7 +185,7 @@ func (in *KubeletConfiguration) DeepCopyInto(out *KubeletConfiguration) { *out = make([]string, len(*in)) copy(*out, *in) } - out.LoggingConfig = in.LoggingConfig + out.Logging = in.Logging return } @@ -258,22 +258,6 @@ func (in *KubeletX509Authentication) DeepCopy() *KubeletX509Authentication { return out } -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *LoggingConfig) DeepCopyInto(out *LoggingConfig) { - *out = *in - return -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new LoggingConfig. -func (in *LoggingConfig) DeepCopy() *LoggingConfig { - if in == nil { - return nil - } - out := new(LoggingConfig) - in.DeepCopyInto(out) - return out -} - // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *SerializedNodeConfigSource) DeepCopyInto(out *SerializedNodeConfigSource) { *out = *in diff --git a/staging/src/k8s.io/component-base/config/types.go b/staging/src/k8s.io/component-base/config/types.go index da11e03c2c6..489cd880b15 100644 --- a/staging/src/k8s.io/component-base/config/types.go +++ b/staging/src/k8s.io/component-base/config/types.go @@ -78,3 +78,11 @@ type DebuggingConfiguration struct { // enableProfiling is true. EnableContentionProfiling bool } + +// LoggingConfiguration contains logging options +type LoggingConfiguration struct { + // Format Flag specifies the structure of log messages. + // default value of format is `text` + // Refer [Logs Options](https://github.com/kubernetes/component-base/blob/master/logs/options.go) for more information. + Format string +} diff --git a/staging/src/k8s.io/component-base/config/v1alpha1/conversion.go b/staging/src/k8s.io/component-base/config/v1alpha1/conversion.go index e2951e310d5..abf35c6d910 100644 --- a/staging/src/k8s.io/component-base/config/v1alpha1/conversion.go +++ b/staging/src/k8s.io/component-base/config/v1alpha1/conversion.go @@ -51,3 +51,11 @@ func Convert_v1alpha1_LeaderElectionConfiguration_To_config_LeaderElectionConfig func Convert_config_LeaderElectionConfiguration_To_v1alpha1_LeaderElectionConfiguration(in *config.LeaderElectionConfiguration, out *LeaderElectionConfiguration, s conversion.Scope) error { return autoConvert_config_LeaderElectionConfiguration_To_v1alpha1_LeaderElectionConfiguration(in, out, s) } + +func Convert_v1alpha1_LoggingConfiguration_To_config_LoggingConfiguration(in *LoggingConfiguration, out *config.LoggingConfiguration, s conversion.Scope) error { + return autoConvert_v1alpha1_LoggingConfiguration_To_config_LoggingConfiguration(in, out, s) +} + +func Convert_config_LoggingConfiguration_To_v1alpha1_LoggingConfiguration(in *config.LoggingConfiguration, out *LoggingConfiguration, s conversion.Scope) error { + return autoConvert_config_LoggingConfiguration_To_v1alpha1_LoggingConfiguration(in, out, s) +} diff --git a/staging/src/k8s.io/component-base/config/v1alpha1/types.go b/staging/src/k8s.io/component-base/config/v1alpha1/types.go index c9d05525d43..1bbbc691c72 100644 --- a/staging/src/k8s.io/component-base/config/v1alpha1/types.go +++ b/staging/src/k8s.io/component-base/config/v1alpha1/types.go @@ -80,3 +80,11 @@ type ClientConnectionConfiguration struct { // burst allows extra queries to accumulate when a client is exceeding its rate. Burst int32 `json:"burst"` } + +// LoggingConfiguration contains logging options +type LoggingConfiguration struct { + // Format Flag specifies the structure of log messages. + // default value of format is `text` + // Refer [Logs Options](https://github.com/kubernetes/component-base/blob/master/logs/options.go) for more information. + Format string `json:"format,omitempty"` +} diff --git a/staging/src/k8s.io/component-base/config/v1alpha1/zz_generated.conversion.go b/staging/src/k8s.io/component-base/config/v1alpha1/zz_generated.conversion.go index 4e4acf309ea..00f28738869 100644 --- a/staging/src/k8s.io/component-base/config/v1alpha1/zz_generated.conversion.go +++ b/staging/src/k8s.io/component-base/config/v1alpha1/zz_generated.conversion.go @@ -49,6 +49,11 @@ func RegisterConversions(s *runtime.Scheme) error { }); err != nil { return err } + if err := s.AddConversionFunc((*config.LoggingConfiguration)(nil), (*LoggingConfiguration)(nil), func(a, b interface{}, scope conversion.Scope) error { + return Convert_config_LoggingConfiguration_To_v1alpha1_LoggingConfiguration(a.(*config.LoggingConfiguration), b.(*LoggingConfiguration), scope) + }); err != nil { + return err + } if err := s.AddConversionFunc((*ClientConnectionConfiguration)(nil), (*config.ClientConnectionConfiguration)(nil), func(a, b interface{}, scope conversion.Scope) error { return Convert_v1alpha1_ClientConnectionConfiguration_To_config_ClientConnectionConfiguration(a.(*ClientConnectionConfiguration), b.(*config.ClientConnectionConfiguration), scope) }); err != nil { @@ -64,6 +69,11 @@ func RegisterConversions(s *runtime.Scheme) error { }); err != nil { return err } + if err := s.AddConversionFunc((*LoggingConfiguration)(nil), (*config.LoggingConfiguration)(nil), func(a, b interface{}, scope conversion.Scope) error { + return Convert_v1alpha1_LoggingConfiguration_To_config_LoggingConfiguration(a.(*LoggingConfiguration), b.(*config.LoggingConfiguration), scope) + }); err != nil { + return err + } return nil } @@ -130,3 +140,13 @@ func autoConvert_config_LeaderElectionConfiguration_To_v1alpha1_LeaderElectionCo out.ResourceNamespace = in.ResourceNamespace return nil } + +func autoConvert_v1alpha1_LoggingConfiguration_To_config_LoggingConfiguration(in *LoggingConfiguration, out *config.LoggingConfiguration, s conversion.Scope) error { + out.Format = in.Format + return nil +} + +func autoConvert_config_LoggingConfiguration_To_v1alpha1_LoggingConfiguration(in *config.LoggingConfiguration, out *LoggingConfiguration, s conversion.Scope) error { + out.Format = in.Format + return nil +} diff --git a/staging/src/k8s.io/component-base/config/v1alpha1/zz_generated.deepcopy.go b/staging/src/k8s.io/component-base/config/v1alpha1/zz_generated.deepcopy.go index 629bf65f9d9..f5f2a0e91ee 100644 --- a/staging/src/k8s.io/component-base/config/v1alpha1/zz_generated.deepcopy.go +++ b/staging/src/k8s.io/component-base/config/v1alpha1/zz_generated.deepcopy.go @@ -85,3 +85,19 @@ func (in *LeaderElectionConfiguration) DeepCopy() *LeaderElectionConfiguration { in.DeepCopyInto(out) return out } + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *LoggingConfiguration) DeepCopyInto(out *LoggingConfiguration) { + *out = *in + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new LoggingConfiguration. +func (in *LoggingConfiguration) DeepCopy() *LoggingConfiguration { + if in == nil { + return nil + } + out := new(LoggingConfiguration) + in.DeepCopyInto(out) + return out +} diff --git a/staging/src/k8s.io/component-base/config/zz_generated.deepcopy.go b/staging/src/k8s.io/component-base/config/zz_generated.deepcopy.go index 9812234f130..77260a06f00 100644 --- a/staging/src/k8s.io/component-base/config/zz_generated.deepcopy.go +++ b/staging/src/k8s.io/component-base/config/zz_generated.deepcopy.go @@ -70,3 +70,19 @@ func (in *LeaderElectionConfiguration) DeepCopy() *LeaderElectionConfiguration { in.DeepCopyInto(out) return out } + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *LoggingConfiguration) DeepCopyInto(out *LoggingConfiguration) { + *out = *in + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new LoggingConfiguration. +func (in *LoggingConfiguration) DeepCopy() *LoggingConfiguration { + if in == nil { + return nil + } + out := new(LoggingConfiguration) + in.DeepCopyInto(out) + return out +} diff --git a/staging/src/k8s.io/kubelet/config/v1beta1/BUILD b/staging/src/k8s.io/kubelet/config/v1beta1/BUILD index 96809c85b2a..8cb2ba27c0b 100644 --- a/staging/src/k8s.io/kubelet/config/v1beta1/BUILD +++ b/staging/src/k8s.io/kubelet/config/v1beta1/BUILD @@ -16,6 +16,7 @@ go_library( "//staging/src/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library", "//staging/src/k8s.io/apimachinery/pkg/runtime:go_default_library", "//staging/src/k8s.io/apimachinery/pkg/runtime/schema:go_default_library", + "//staging/src/k8s.io/component-base/config/v1alpha1:go_default_library", ], ) diff --git a/staging/src/k8s.io/kubelet/config/v1beta1/types.go b/staging/src/k8s.io/kubelet/config/v1beta1/types.go index bb9c91174ef..254a3e1fec9 100644 --- a/staging/src/k8s.io/kubelet/config/v1beta1/types.go +++ b/staging/src/k8s.io/kubelet/config/v1beta1/types.go @@ -19,6 +19,7 @@ package v1beta1 import ( v1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + componentbaseconfigv1alpha1 "k8s.io/component-base/config/v1alpha1" ) // HairpinMode denotes how the kubelet should configure networking to handle @@ -793,12 +794,12 @@ type KubeletConfiguration struct { // Default: false // +optional KernelMemcgNotification bool `json:"kernelMemcgNotification,omitempty"` - // LoggingConfig specifies the options of logging. + // Logging specifies the options of logging. // Refer [Logs Options](https://github.com/kubernetes/component-base/blob/master/logs/options.go) for more information. // Defaults: - // loggingFormat: text + // Format: text // + optional - LoggingConfig LoggingConfig `json:"loggingConfig,omitempty"` + Logging componentbaseconfigv1alpha1.LoggingConfiguration `json:"logging,omitempty"` } type KubeletAuthorizationMode string @@ -879,11 +880,3 @@ type SerializedNodeConfigSource struct { // +optional Source v1.NodeConfigSource `json:"source,omitempty" protobuf:"bytes,1,opt,name=source"` } - -// LoggingConfig contains logging options -type LoggingConfig struct { - // LoggingFormat Flag specifies the structure of log messages. - // default value of loggingFormat is `text` - // Refer [Logs Options](https://github.com/kubernetes/component-base/blob/master/logs/options.go) for more information. - LoggingFormat string `json:"loggingFormat,omitempty"` -} diff --git a/staging/src/k8s.io/kubelet/config/v1beta1/zz_generated.deepcopy.go b/staging/src/k8s.io/kubelet/config/v1beta1/zz_generated.deepcopy.go index 6d381892efc..4f998494ce7 100644 --- a/staging/src/k8s.io/kubelet/config/v1beta1/zz_generated.deepcopy.go +++ b/staging/src/k8s.io/kubelet/config/v1beta1/zz_generated.deepcopy.go @@ -295,7 +295,7 @@ func (in *KubeletConfiguration) DeepCopyInto(out *KubeletConfiguration) { *out = make([]string, len(*in)) copy(*out, *in) } - out.LoggingConfig = in.LoggingConfig + out.Logging = in.Logging return } @@ -373,22 +373,6 @@ func (in *KubeletX509Authentication) DeepCopy() *KubeletX509Authentication { return out } -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *LoggingConfig) DeepCopyInto(out *LoggingConfig) { - *out = *in - return -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new LoggingConfig. -func (in *LoggingConfig) DeepCopy() *LoggingConfig { - if in == nil { - return nil - } - out := new(LoggingConfig) - in.DeepCopyInto(out) - return out -} - // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *SerializedNodeConfigSource) DeepCopyInto(out *SerializedNodeConfigSource) { *out = *in diff --git a/staging/src/k8s.io/kubelet/go.sum b/staging/src/k8s.io/kubelet/go.sum index eab1f7fa7d4..e35c4634dac 100644 --- a/staging/src/k8s.io/kubelet/go.sum +++ b/staging/src/k8s.io/kubelet/go.sum @@ -365,6 +365,7 @@ k8s.io/klog/v2 v2.0.0/go.mod h1:PBfzABfn139FHAV07az/IF9Wp1bkk3vpT2XSJ76fSDE= k8s.io/klog/v2 v2.1.0 h1:X3+Mru/L3jy4BI4vcAYkHvL6PyU+QBsuhEqwlI4mgkA= k8s.io/klog/v2 v2.1.0/go.mod h1:PBfzABfn139FHAV07az/IF9Wp1bkk3vpT2XSJ76fSDE= k8s.io/kube-openapi v0.0.0-20200427153329-656914f816f9/go.mod h1:bfCVj+qXcEaE5SCvzBaqpOySr6tuCcpPKqF6HD8nyCw= +k8s.io/utils v0.0.0-20200619165400-6e3d28b6ed19 h1:7Nu2dTj82c6IaWvL7hImJzcXoTPz1MsSCH7r+0m6rfo= k8s.io/utils v0.0.0-20200619165400-6e3d28b6ed19/go.mod h1:jPW/WVKK9YHAvNhRxK0md/EJ228hCsBRufyofKtW8HA= rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8= sigs.k8s.io/structured-merge-diff/v3 v3.0.0-20200116222232-67a7b8c61874/go.mod h1:PlARxl6Hbt/+BC80dRLi1qAmnMqwqDg62YvvVkZjemw= From b92b04e7cd754efbf223adf4a8496a497ad8a243 Mon Sep 17 00:00:00 2001 From: amash Date: Tue, 30 Jun 2020 16:21:13 +0430 Subject: [PATCH 4/4] add default for loggingconfiguration struct --- cmd/kubelet/app/server.go | 4 +--- pkg/kubelet/apis/config/fuzzer/fuzzer.go | 3 +++ .../KubeletConfiguration/after/v1beta1.yaml | 3 ++- .../roundtrip/default/v1beta1.yaml | 3 ++- pkg/kubelet/apis/config/v1beta1/defaults.go | 3 +++ .../component-base/config/v1alpha1/defaults.go | 15 +++++++++++++++ 6 files changed, 26 insertions(+), 5 deletions(-) diff --git a/cmd/kubelet/app/server.go b/cmd/kubelet/app/server.go index b5dfd9ddf35..0c2dbc11074 100644 --- a/cmd/kubelet/app/server.go +++ b/cmd/kubelet/app/server.go @@ -405,9 +405,7 @@ func UnsecuredDependencies(s *options.KubeletServer, featureGate featuregate.Fea // not be generated. func Run(s *options.KubeletServer, kubeDeps *kubelet.Dependencies, featureGate featuregate.FeatureGate, stopCh <-chan struct{}) error { logOption := logs.NewOptions() - if s.Logging.Format != "" { - logOption.LogFormat = s.Logging.Format - } + logOption.LogFormat = s.Logging.Format logOption.Apply() // To help debugging, immediately log version klog.Infof("Version: %+v", version.Get()) diff --git a/pkg/kubelet/apis/config/fuzzer/fuzzer.go b/pkg/kubelet/apis/config/fuzzer/fuzzer.go index 06c636be2ad..2c68c3596e7 100644 --- a/pkg/kubelet/apis/config/fuzzer/fuzzer.go +++ b/pkg/kubelet/apis/config/fuzzer/fuzzer.go @@ -100,6 +100,9 @@ func Funcs(codecs runtimeserializer.CodecFactory) []interface{} { obj.ConfigMapAndSecretChangeDetectionStrategy = "Watch" obj.AllowedUnsafeSysctls = []string{} obj.VolumePluginDir = kubeletconfigv1beta1.DefaultVolumePluginDir + if obj.Logging.Format == "" { + obj.Logging.Format = "text" + } }, } } diff --git a/pkg/kubelet/apis/config/scheme/testdata/KubeletConfiguration/after/v1beta1.yaml b/pkg/kubelet/apis/config/scheme/testdata/KubeletConfiguration/after/v1beta1.yaml index e73f503301e..c97e66665ce 100644 --- a/pkg/kubelet/apis/config/scheme/testdata/KubeletConfiguration/after/v1beta1.yaml +++ b/pkg/kubelet/apis/config/scheme/testdata/KubeletConfiguration/after/v1beta1.yaml @@ -49,7 +49,8 @@ iptablesMasqueradeBit: 14 kind: KubeletConfiguration kubeAPIBurst: 10 kubeAPIQPS: 5 -logging: {} +logging: + format: text makeIPTablesUtilChains: true maxOpenFiles: 1000000 maxPods: 110 diff --git a/pkg/kubelet/apis/config/scheme/testdata/KubeletConfiguration/roundtrip/default/v1beta1.yaml b/pkg/kubelet/apis/config/scheme/testdata/KubeletConfiguration/roundtrip/default/v1beta1.yaml index e73f503301e..c97e66665ce 100644 --- a/pkg/kubelet/apis/config/scheme/testdata/KubeletConfiguration/roundtrip/default/v1beta1.yaml +++ b/pkg/kubelet/apis/config/scheme/testdata/KubeletConfiguration/roundtrip/default/v1beta1.yaml @@ -49,7 +49,8 @@ iptablesMasqueradeBit: 14 kind: KubeletConfiguration kubeAPIBurst: 10 kubeAPIQPS: 5 -logging: {} +logging: + format: text makeIPTablesUtilChains: true maxOpenFiles: 1000000 maxPods: 110 diff --git a/pkg/kubelet/apis/config/v1beta1/defaults.go b/pkg/kubelet/apis/config/v1beta1/defaults.go index 880d028e381..79005ccdcd7 100644 --- a/pkg/kubelet/apis/config/v1beta1/defaults.go +++ b/pkg/kubelet/apis/config/v1beta1/defaults.go @@ -21,6 +21,7 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" kruntime "k8s.io/apimachinery/pkg/runtime" + componentbaseconfigv1alpha1 "k8s.io/component-base/config/v1alpha1" kubeletconfigv1beta1 "k8s.io/kubelet/config/v1beta1" // TODO: Cut references to k8s.io/kubernetes, eventually there should be none from this package "k8s.io/kubernetes/pkg/kubelet/qos" @@ -233,4 +234,6 @@ func SetDefaults_KubeletConfiguration(obj *kubeletconfigv1beta1.KubeletConfigura if obj.VolumePluginDir == "" { obj.VolumePluginDir = DefaultVolumePluginDir } + // Use the Default LoggingConfiguration option + componentbaseconfigv1alpha1.RecommendedLoggingConfiguration(&obj.Logging) } 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 05ad82d3eb0..bbf08e11805 100644 --- a/staging/src/k8s.io/component-base/config/v1alpha1/defaults.go +++ b/staging/src/k8s.io/component-base/config/v1alpha1/defaults.go @@ -95,3 +95,18 @@ func NewRecommendedDebuggingConfiguration() *DebuggingConfiguration { RecommendedDebuggingConfiguration(ret) return ret } + +// RecommendedLoggingConfiguration defaults logging 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 RecommendedLoggingConfiguration(obj *LoggingConfiguration) { + if obj.Format == "" { + obj.Format = "text" + } +}