Skip to content

Commit 13a4a71

Browse files
authored
Merge pull request kubernetes#91532 from afrouzMashaykhi/log-flag-kubelet
add --logging-format flag to kubelet
2 parents 2fd2d1b + b92b04e commit 13a4a71

File tree

27 files changed

+143
-0
lines changed

27 files changed

+143
-0
lines changed

cmd/kubeadm/app/componentconfigs/kubelet_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ var kubeletMarshalCases = []struct {
7676
httpCheckFrequency: 0s
7777
imageMinimumGCAge: 0s
7878
kind: KubeletConfiguration
79+
logging: {}
7980
nodeStatusReportFrequency: 0s
8081
nodeStatusUpdateFrequency: 0s
8182
runtimeRequestTimeout: 0s
@@ -118,6 +119,7 @@ var kubeletMarshalCases = []struct {
118119
httpCheckFrequency: 0s
119120
imageMinimumGCAge: 0s
120121
kind: KubeletConfiguration
122+
logging: {}
121123
nodeStatusReportFrequency: 0s
122124
nodeStatusUpdateFrequency: 0s
123125
port: 12345

cmd/kubelet/app/BUILD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ go_library(
111111
"//staging/src/k8s.io/component-base/cli/flag:go_default_library",
112112
"//staging/src/k8s.io/component-base/configz:go_default_library",
113113
"//staging/src/k8s.io/component-base/featuregate:go_default_library",
114+
"//staging/src/k8s.io/component-base/logs:go_default_library",
114115
"//staging/src/k8s.io/component-base/metrics:go_default_library",
115116
"//staging/src/k8s.io/component-base/metrics/legacyregistry:go_default_library",
116117
"//staging/src/k8s.io/component-base/version:go_default_library",

cmd/kubelet/app/options/options.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -540,6 +540,7 @@ func AddKubeletConfigFlags(mainfs *pflag.FlagSet, c *kubeletconfig.KubeletConfig
540540
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.")
541541
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='']")
542542
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='']")
543+
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.`)
543544

544545
// Graduated experimental flags, kept for backward compatibility
545546
fs.BoolVar(&c.KernelMemcgNotification, "experimental-kernel-memcg-notification", c.KernelMemcgNotification, "Use kernelMemcgNotification configuration, this flag will be removed in 1.23.")

cmd/kubelet/app/server.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ import (
6363
cliflag "k8s.io/component-base/cli/flag"
6464
"k8s.io/component-base/configz"
6565
"k8s.io/component-base/featuregate"
66+
"k8s.io/component-base/logs"
6667
"k8s.io/component-base/metrics"
6768
"k8s.io/component-base/metrics/legacyregistry"
6869
"k8s.io/component-base/version"
@@ -403,6 +404,9 @@ func UnsecuredDependencies(s *options.KubeletServer, featureGate featuregate.Fea
403404
// Otherwise, the caller is assumed to have set up the Dependencies object and a default one will
404405
// not be generated.
405406
func Run(s *options.KubeletServer, kubeDeps *kubelet.Dependencies, featureGate featuregate.FeatureGate, stopCh <-chan struct{}) error {
407+
logOption := logs.NewOptions()
408+
logOption.LogFormat = s.Logging.Format
409+
logOption.Apply()
406410
// To help debugging, immediately log version
407411
klog.Infof("Version: %+v", version.Get())
408412
if err := initForOS(s.KubeletFlags.WindowsService); err != nil {

pkg/kubelet/apis/config/BUILD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ go_library(
2121
"//staging/src/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
2222
"//staging/src/k8s.io/apimachinery/pkg/runtime:go_default_library",
2323
"//staging/src/k8s.io/apimachinery/pkg/runtime/schema:go_default_library",
24+
"//staging/src/k8s.io/component-base/config:go_default_library",
2425
],
2526
)
2627

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

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

pkg/kubelet/apis/config/helpers_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@ var (
182182
"HairpinMode",
183183
"HealthzBindAddress",
184184
"HealthzPort",
185+
"Logging.Format",
185186
"TLSCipherSuites[*]",
186187
"TLSMinVersion",
187188
"IPTablesDropBit",

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ iptablesMasqueradeBit: 14
4949
kind: KubeletConfiguration
5050
kubeAPIBurst: 10
5151
kubeAPIQPS: 5
52+
logging:
53+
format: text
5254
makeIPTablesUtilChains: true
5355
maxOpenFiles: 1000000
5456
maxPods: 110

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ iptablesMasqueradeBit: 14
4949
kind: KubeletConfiguration
5050
kubeAPIBurst: 10
5151
kubeAPIQPS: 5
52+
logging:
53+
format: text
5254
makeIPTablesUtilChains: true
5355
maxOpenFiles: 1000000
5456
maxPods: 110

pkg/kubelet/apis/config/types.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package config
1919
import (
2020
v1 "k8s.io/api/core/v1"
2121
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
22+
componentbaseconfig "k8s.io/component-base/config"
2223
)
2324

2425
// HairpinMode denotes how the kubelet should configure networking to handle
@@ -357,6 +358,9 @@ type KubeletConfiguration struct {
357358
// The purpose of this format is make sure you have the opportunity to notice if the next release hides additional metrics,
358359
// rather than being surprised when they are permanently removed in the release after that.
359360
ShowHiddenMetricsForVersion string
361+
// Logging specifies the options of logging.
362+
// Refer [Logs Options](https://github.com/kubernetes/component-base/blob/master/logs/options.go) for more information.
363+
Logging componentbaseconfig.LoggingConfiguration
360364
}
361365

362366
// KubeletAuthorizationMode denotes the authorization mode for the kubelet

0 commit comments

Comments
 (0)