Navigation Menu

Skip to content

Commit

Permalink
Merge pull request kubernetes#91532 from afrouzMashaykhi/log-flag-kub…
Browse files Browse the repository at this point in the history
…elet

add --logging-format flag to kubelet
  • Loading branch information
k8s-ci-robot committed Jul 2, 2020
2 parents 2fd2d1b + b92b04e commit 13a4a71
Show file tree
Hide file tree
Showing 27 changed files with 143 additions and 0 deletions.
2 changes: 2 additions & 0 deletions cmd/kubeadm/app/componentconfigs/kubelet_test.go
Expand Up @@ -76,6 +76,7 @@ var kubeletMarshalCases = []struct {
httpCheckFrequency: 0s
imageMinimumGCAge: 0s
kind: KubeletConfiguration
logging: {}
nodeStatusReportFrequency: 0s
nodeStatusUpdateFrequency: 0s
runtimeRequestTimeout: 0s
Expand Down Expand Up @@ -118,6 +119,7 @@ var kubeletMarshalCases = []struct {
httpCheckFrequency: 0s
imageMinimumGCAge: 0s
kind: KubeletConfiguration
logging: {}
nodeStatusReportFrequency: 0s
nodeStatusUpdateFrequency: 0s
port: 12345
Expand Down
1 change: 1 addition & 0 deletions cmd/kubelet/app/BUILD
Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions cmd/kubelet/app/options/options.go
Expand Up @@ -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.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.")
Expand Down
4 changes: 4 additions & 0 deletions cmd/kubelet/app/server.go
Expand Up @@ -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"
Expand Down Expand Up @@ -403,6 +404,9 @@ 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()
logOption.LogFormat = s.Logging.Format
logOption.Apply()
// To help debugging, immediately log version
klog.Infof("Version: %+v", version.Get())
if err := initForOS(s.KubeletFlags.WindowsService); err != nil {
Expand Down
1 change: 1 addition & 0 deletions pkg/kubelet/apis/config/BUILD
Expand Up @@ -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",
],
)

Expand Down
3 changes: 3 additions & 0 deletions pkg/kubelet/apis/config/fuzzer/fuzzer.go
Expand Up @@ -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"
}
},
}
}
1 change: 1 addition & 0 deletions pkg/kubelet/apis/config/helpers_test.go
Expand Up @@ -182,6 +182,7 @@ var (
"HairpinMode",
"HealthzBindAddress",
"HealthzPort",
"Logging.Format",
"TLSCipherSuites[*]",
"TLSMinVersion",
"IPTablesDropBit",
Expand Down
Expand Up @@ -49,6 +49,8 @@ iptablesMasqueradeBit: 14
kind: KubeletConfiguration
kubeAPIBurst: 10
kubeAPIQPS: 5
logging:
format: text
makeIPTablesUtilChains: true
maxOpenFiles: 1000000
maxPods: 110
Expand Down
Expand Up @@ -49,6 +49,8 @@ iptablesMasqueradeBit: 14
kind: KubeletConfiguration
kubeAPIBurst: 10
kubeAPIQPS: 5
logging:
format: text
makeIPTablesUtilChains: true
maxOpenFiles: 1000000
maxPods: 110
Expand Down
4 changes: 4 additions & 0 deletions pkg/kubelet/apis/config/types.go
Expand Up @@ -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
Expand Down Expand Up @@ -357,6 +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
// Logging specifies the options of logging.
// Refer [Logs Options](https://github.com/kubernetes/component-base/blob/master/logs/options.go) for more information.
Logging componentbaseconfig.LoggingConfiguration
}

// KubeletAuthorizationMode denotes the authorization mode for the kubelet
Expand Down
1 change: 1 addition & 0 deletions pkg/kubelet/apis/config/v1beta1/BUILD
Expand Up @@ -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",
],
Expand Down
3 changes: 3 additions & 0 deletions pkg/kubelet/apis/config/v1beta1/defaults.go
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
}
7 changes: 7 additions & 0 deletions pkg/kubelet/apis/config/v1beta1/zz_generated.conversion.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pkg/kubelet/apis/config/validation/BUILD
Expand Up @@ -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",
],
)
Expand Down
8 changes: 8 additions & 0 deletions pkg/kubelet/apis/config/validation/validation.go
Expand Up @@ -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"
Expand Down Expand Up @@ -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.Logging.Format != "" {
logOption.LogFormat = kc.Logging.Format
}
allErrors = append(allErrors, logOption.Validate()...)

return utilerrors.NewAggregate(allErrors)
}
1 change: 1 addition & 0 deletions pkg/kubelet/apis/config/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions staging/src/k8s.io/component-base/config/types.go
Expand Up @@ -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
}
Expand Up @@ -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)
}
15 changes: 15 additions & 0 deletions staging/src/k8s.io/component-base/config/v1alpha1/defaults.go
Expand Up @@ -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"
}
}
8 changes: 8 additions & 0 deletions staging/src/k8s.io/component-base/config/v1alpha1/types.go
Expand Up @@ -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"`
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions staging/src/k8s.io/component-base/config/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions staging/src/k8s.io/kubelet/config/v1beta1/BUILD
Expand Up @@ -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",
],
)

Expand Down
7 changes: 7 additions & 0 deletions staging/src/k8s.io/kubelet/config/v1beta1/types.go
Expand Up @@ -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
Expand Down Expand Up @@ -793,6 +794,12 @@ type KubeletConfiguration struct {
// Default: false
// +optional
KernelMemcgNotification bool `json:"kernelMemcgNotification,omitempty"`
// Logging specifies the options of logging.
// Refer [Logs Options](https://github.com/kubernetes/component-base/blob/master/logs/options.go) for more information.
// Defaults:
// Format: text
// + optional
Logging componentbaseconfigv1alpha1.LoggingConfiguration `json:"logging,omitempty"`
}

type KubeletAuthorizationMode string
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions staging/src/k8s.io/kubelet/go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 13a4a71

Please sign in to comment.