From ac8d2e897876c3c823a91ce4ab9ae2a908aff8e3 Mon Sep 17 00:00:00 2001 From: amash Date: Tue, 16 Jun 2020 15:17:14 +0430 Subject: [PATCH] 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