add loggingConfig struct to kubelet config

This commit is contained in:
amash 2020-06-16 15:17:14 +04:30
parent ba8189a4f2
commit ac8d2e8978
12 changed files with 102 additions and 14 deletions

View File

@ -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

View File

@ -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.")

View File

@ -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

View File

@ -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",

View File

@ -49,6 +49,7 @@ iptablesMasqueradeBit: 14
kind: KubeletConfiguration
kubeAPIBurst: 10
kubeAPIQPS: 5
loggingConfig: {}
makeIPTablesUtilChains: true
maxOpenFiles: 1000000
maxPods: 110

View File

@ -49,6 +49,7 @@ iptablesMasqueradeBit: 14
kind: KubeletConfiguration
kubeAPIBurst: 10
kubeAPIQPS: 5
loggingConfig: {}
makeIPTablesUtilChains: true
maxOpenFiles: 1000000
maxPods: 110

View File

@ -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
}

View File

@ -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

View File

@ -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()...)

View File

@ -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

View File

@ -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"`
}

View File

@ -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