Skip to content

Commit 6dbec8e

Browse files
authored
Merge pull request kubernetes#112120 from pohly/klog-flag-removal
logs: remove deprecated klog flags
2 parents 17c5066 + 2f762e4 commit 6dbec8e

File tree

17 files changed

+73
-77
lines changed

17 files changed

+73
-77
lines changed

hack/jenkins/benchmark-dockerized.sh

+2-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,8 @@ cd "${GOPATH}/src/k8s.io/kubernetes"
6666
./hack/install-etcd.sh
6767

6868
# Run the benchmark tests and pretty-print the results into a separate file.
69-
make test-integration WHAT="$*" KUBE_TEST_ARGS="-run='XXX' -bench=${TEST_PREFIX:-.} -benchtime=${BENCHTIME:-1s} -benchmem -alsologtostderr=false -logtostderr=false -data-items-dir=${ARTIFACTS}" \
69+
# Log output of the tests go to stderr.
70+
make test-integration WHAT="$*" KUBE_TEST_ARGS="-run='XXX' -bench=${TEST_PREFIX:-.} -benchtime=${BENCHTIME:-1s} -benchmem -data-items-dir=${ARTIFACTS}" \
7071
| (go run test/integration/benchmark/extractlog/main.go) \
7172
| tee \
7273
>(prettybench -no-passthrough > "${ARTIFACTS}/BenchmarkResults.txt") \

hack/make-rules/test-e2e-node.sh

+3-3
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ if [ "${remote}" = true ] && [ "${remote_mode}" = gce ] ; then
162162
echo "Kubelet Config File: ${kubelet_config_file}"
163163

164164
# Invoke the runner
165-
go run test/e2e_node/runner/remote/run_remote.go --logtostderr --vmodule=*=4 --ssh-env="gce" \
165+
go run test/e2e_node/runner/remote/run_remote.go --vmodule=*=4 --ssh-env="gce" \
166166
--zone="${zone}" --project="${project}" --gubernator="${gubernator}" \
167167
--hosts="${hosts}" --images="${images}" --cleanup="${cleanup}" \
168168
--results-dir="${artifacts}" --ginkgo-flags="${ginkgoflags}" --runtime-config="${runtime_config}" \
@@ -189,7 +189,7 @@ elif [ "${remote}" = true ] && [ "${remote_mode}" = ssh ] ; then
189189
test_args='--kubelet-flags="--cluster-domain='${KUBE_DNS_DOMAIN:-cluster.local}'" '${test_args}
190190

191191
# Invoke the runner
192-
go run test/e2e_node/runner/remote/run_remote.go --mode="ssh" --logtostderr --vmodule=*=4 \
192+
go run test/e2e_node/runner/remote/run_remote.go --mode="ssh" --vmodule=*=4 \
193193
--hosts="${hosts}" --results-dir="${artifacts}" --ginkgo-flags="${ginkgoflags}" \
194194
--test_args="${test_args}" --system-spec-name="${system_spec_name}" \
195195
--runtime-config="${runtime_config}" \
@@ -222,7 +222,7 @@ else
222222
go run test/e2e_node/runner/local/run_local.go \
223223
--system-spec-name="${system_spec_name}" --extra-envs="${extra_envs}" \
224224
--ginkgo-flags="${ginkgoflags}" \
225-
--test-flags="--alsologtostderr --v 4 --report-dir=${artifacts} --node-name $(hostname) ${test_args}" \
225+
--test-flags="--v 4 --report-dir=${artifacts} --node-name $(hostname) ${test_args}" \
226226
--runtime-config="${runtime_config}" \
227227
--kubelet-config-file="${kubelet_config_file}" \
228228
--build-dependencies=true 2>&1 | tee -i "${artifacts}/build-log.txt"

hack/make-rules/test-integration.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ runTests() {
7878
make -C "${KUBE_ROOT}" test \
7979
WHAT="${WHAT:-$(kube::test::find_integration_test_dirs | paste -sd' ' -)}" \
8080
GOFLAGS="${GOFLAGS:-}" \
81-
KUBE_TEST_ARGS="--alsologtostderr=true ${SHORT:--short=true} --vmodule=${KUBE_TEST_VMODULE} ${KUBE_TEST_ARGS:-}" \
81+
KUBE_TEST_ARGS="${SHORT:--short=true} --vmodule=${KUBE_TEST_VMODULE} ${KUBE_TEST_ARGS:-}" \
8282
KUBE_TIMEOUT="${KUBE_TIMEOUT}" \
8383
KUBE_RACE=""
8484

hack/update-openapi-spec.sh

-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,6 @@ kube::log::status "Starting kube-apiserver"
8484
--service-account-lookup="${SERVICE_ACCOUNT_LOOKUP}" \
8585
--service-account-issuer="https://kubernetes.default.svc" \
8686
--service-account-signing-key-file="${SERVICE_ACCOUNT_KEY}" \
87-
--logtostderr \
8887
--v=2 \
8988
--service-cluster-ip-range="10.0.0.0/24" >"${API_LOGFILE}" 2>&1 &
9089
APISERVER_PID=$!

staging/src/k8s.io/component-base/cli/globalflag/globalflags_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ func TestAddGlobalFlags(t *testing.T) {
6262
}{
6363
{
6464
// Happy case
65-
expectedFlag: []string{"add-dir-header", "alsologtostderr", "help", "log-backtrace-at", "log-dir", "log-file", "log-file-max-size", "log-flush-frequency", "logtostderr", "one-output", "skip-headers", "skip-log-headers", "stderrthreshold", "v", "vmodule"},
65+
expectedFlag: []string{"help", "log-flush-frequency", "v", "vmodule"},
6666
matchExpected: false,
6767
},
6868
{

staging/src/k8s.io/component-base/logs/api/v1/options.go

+3-20
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import (
2020
"flag"
2121
"fmt"
2222
"math"
23-
"sort"
2423
"strings"
2524
"time"
2625

@@ -32,6 +31,7 @@ import (
3231
"k8s.io/apimachinery/pkg/util/validation/field"
3332
cliflag "k8s.io/component-base/cli/flag"
3433
"k8s.io/component-base/featuregate"
34+
"k8s.io/component-base/logs/klogflags"
3535
)
3636

3737
const (
@@ -183,12 +183,8 @@ func apply(c *LoggingConfiguration, featureGate featuregate.FeatureGate) error {
183183

184184
// AddFlags adds command line flags for the configuration.
185185
func AddFlags(c *LoggingConfiguration, fs *pflag.FlagSet) {
186-
// The help text is generated assuming that flags will eventually use
187-
// hyphens, even if currently no normalization function is set for the
188-
// flag set yet.
189-
unsupportedFlags := strings.Join(unsupportedLoggingFlagNames(cliflag.WordSepNormalizeFunc), ", ")
190186
formats := logRegistry.list()
191-
fs.StringVar(&c.Format, "logging-format", c.Format, fmt.Sprintf("Sets the log format. Permitted formats: %s.\nNon-default formats don't honor these flags: %s.\nNon-default choices are currently alpha and subject to change without warning.", formats, unsupportedFlags))
187+
fs.StringVar(&c.Format, "logging-format", c.Format, fmt.Sprintf("Sets the log format. Permitted formats: %s.", formats))
192188
// No new log formats should be added after generation is of flag options
193189
logRegistry.freeze()
194190

@@ -236,14 +232,13 @@ var loggingFlags pflag.FlagSet
236232

237233
func init() {
238234
var fs flag.FlagSet
239-
klog.InitFlags(&fs)
235+
klogflags.Init(&fs)
240236
loggingFlags.AddGoFlagSet(&fs)
241237
}
242238

243239
// List of logs (k8s.io/klog + k8s.io/component-base/logs) flags supported by all logging formats
244240
var supportedLogsFlags = map[string]struct{}{
245241
"v": {},
246-
// TODO: support vmodule after 1.19 Alpha
247242
}
248243

249244
// unsupportedLoggingFlags lists unsupported logging flags. The normalize
@@ -268,15 +263,3 @@ func unsupportedLoggingFlags(normalizeFunc func(f *pflag.FlagSet, name string) p
268263
})
269264
return allFlags
270265
}
271-
272-
// unsupportedLoggingFlagNames lists unsupported logging flags by name, with
273-
// optional normalization and sorted.
274-
func unsupportedLoggingFlagNames(normalizeFunc func(f *pflag.FlagSet, name string) pflag.NormalizedName) []string {
275-
unsupportedFlags := unsupportedLoggingFlags(normalizeFunc)
276-
names := make([]string, 0, len(unsupportedFlags))
277-
for _, f := range unsupportedFlags {
278-
names = append(names, "--"+f.Name)
279-
}
280-
sort.Strings(names)
281-
return names
282-
}

staging/src/k8s.io/component-base/logs/api/v1/options_test.go

+1-3
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,7 @@ func TestFlags(t *testing.T) {
3939
fs.SetOutput(&output)
4040
fs.PrintDefaults()
4141
want := ` --log-flush-frequency duration Maximum number of seconds between log flushes (default 5s)
42-
--logging-format string Sets the log format. Permitted formats: "text".
43-
Non-default formats don't honor these flags: --add-dir-header, --alsologtostderr, --log-backtrace-at, --log-dir, --log-file, --log-file-max-size, --logtostderr, --one-output, --skip-headers, --skip-log-headers, --stderrthreshold, --vmodule.
44-
Non-default choices are currently alpha and subject to change without warning. (default "text")
42+
--logging-format string Sets the log format. Permitted formats: "text". (default "text")
4543
-v, --v Level number for the log level verbosity
4644
--vmodule pattern=N,... comma-separated list of pattern=N settings for file-filtered logging (only works for text log format)
4745
`
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
Copyright 2022 The Kubernetes Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package klogflags
18+
19+
import (
20+
"flag"
21+
22+
"k8s.io/klog/v2"
23+
)
24+
25+
// Init is a replacement for klog.InitFlags which only adds those flags
26+
// that are still supported for Kubernetes components (i.e. -v and -vmodule).
27+
// See
28+
// https://github.com/kubernetes/enhancements/tree/master/keps/sig-instrumentation/2845-deprecate-klog-specific-flags-in-k8s-components.
29+
func Init(fs *flag.FlagSet) {
30+
var allFlags flag.FlagSet
31+
klog.InitFlags(&allFlags)
32+
if fs == nil {
33+
fs = flag.CommandLine
34+
}
35+
allFlags.VisitAll(func(f *flag.Flag) {
36+
switch f.Name {
37+
case "v", "vmodule":
38+
fs.Var(f.Value, f.Name, f.Usage)
39+
}
40+
})
41+
}

staging/src/k8s.io/component-base/logs/logs.go

+11-37
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,11 @@ import (
2727

2828
"github.com/spf13/pflag"
2929
logsapi "k8s.io/component-base/logs/api/v1"
30+
"k8s.io/component-base/logs/klogflags"
3031
"k8s.io/klog/v2"
3132
)
3233

33-
const deprecated = "will be removed in a future release, see https://github.com/kubernetes/enhancements/tree/master/keps/sig-instrumentation/2845-deprecate-klog-specific-flags-in-k8s-components"
34-
35-
// TODO (https://github.com/kubernetes/kubernetes/issues/105310): once klog
36-
// flags are removed, stop warning about "Non-default formats don't honor these
37-
// flags" in config.go and instead add this remark here.
38-
//
39-
// const vmoduleUsage = " (only works for the default text log format)"
34+
const vmoduleUsage = " (only works for the default text log format)"
4035

4136
var (
4237
packageFlags = flag.NewFlagSet("logging", flag.ContinueOnError)
@@ -47,7 +42,7 @@ var (
4742
)
4843

4944
func init() {
50-
klog.InitFlags(packageFlags)
45+
klogflags.Init(packageFlags)
5146
packageFlags.DurationVar(&logFlushFreq, logsapi.LogFlushFreqFlagName, logsapi.LogFlushFreqDefault, "Maximum number of seconds between log flushes")
5247
}
5348

@@ -81,42 +76,29 @@ var NewOptions = logsapi.NewLoggingConfiguration
8176
//
8277
// May be called more than once.
8378
func AddFlags(fs *pflag.FlagSet, opts ...Option) {
84-
// Determine whether the flags are already present by looking up one
85-
// which always should exist.
86-
if fs.Lookup("logtostderr") != nil {
87-
return
88-
}
89-
9079
o := addFlagsOptions{}
9180
for _, opt := range opts {
9281
opt(&o)
9382
}
9483

95-
// Add flags with pflag deprecation remark for some klog flags.
84+
// Add all supported flags.
9685
packageFlags.VisitAll(func(f *flag.Flag) {
9786
pf := pflag.PFlagFromGoFlag(f)
9887
switch f.Name {
99-
case "v":
100-
// unchanged, potentially skip it
101-
if o.skipLoggingConfigurationFlags {
102-
return
103-
}
104-
case logsapi.LogFlushFreqFlagName:
88+
case "v", logsapi.LogFlushFreqFlagName:
10589
// unchanged, potentially skip it
10690
if o.skipLoggingConfigurationFlags {
10791
return
10892
}
10993
case "vmodule":
110-
// TODO: see above
111-
// pf.Usage += vmoduleUsage
11294
if o.skipLoggingConfigurationFlags {
11395
return
11496
}
115-
default:
116-
// deprecated, but not hidden
117-
pf.Deprecated = deprecated
97+
pf.Usage += vmoduleUsage
98+
}
99+
if fs.Lookup(pf.Name) == nil {
100+
fs.AddFlag(pf)
118101
}
119-
fs.AddFlag(pf)
120102
})
121103
}
122104

@@ -137,24 +119,16 @@ func AddGoFlags(fs *flag.FlagSet, opts ...Option) {
137119
packageFlags.VisitAll(func(f *flag.Flag) {
138120
usage := f.Usage
139121
switch f.Name {
140-
case "v":
141-
// unchanged
142-
if o.skipLoggingConfigurationFlags {
143-
return
144-
}
145-
case logsapi.LogFlushFreqFlagName:
122+
case "v", logsapi.LogFlushFreqFlagName:
146123
// unchanged
147124
if o.skipLoggingConfigurationFlags {
148125
return
149126
}
150127
case "vmodule":
151-
// TODO: see above
152-
// usage += vmoduleUsage
153128
if o.skipLoggingConfigurationFlags {
154129
return
155130
}
156-
default:
157-
usage += " (DEPRECATED: " + deprecated + ")"
131+
usage += vmoduleUsage
158132
}
159133
fs.Var(f.Value, f.Name, usage)
160134
})

test/e2e_node/conformance/run_test.sh

-1
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,6 @@ start_kubelet --kubeconfig "${KUBELET_KUBECONFIG}" \
201201
--system-cgroups=/system \
202202
--cgroup-root=/ \
203203
--v=$log_level \
204-
--logtostderr
205204

206205
wait_kubelet
207206

test/e2e_node/jenkins/conformance/conformance-jenkins.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ TIMEOUT=${TIMEOUT:-"45m"}
3333
mkdir -p "${ARTIFACTS}"
3434

3535
go run test/e2e_node/runner/remote/run_remote.go --test-suite=conformance \
36-
--logtostderr --vmodule=*=4 --ssh-env="gce" --ssh-user="$GCE_USER" \
36+
--vmodule=*=4 --ssh-env="gce" --ssh-user="$GCE_USER" \
3737
--zone="$GCE_ZONE" --project="$GCE_PROJECT" --hosts="$GCE_HOSTS" \
3838
--images="$GCE_IMAGES" --image-project="$GCE_IMAGE_PROJECT" \
3939
--image-config-file="$GCE_IMAGE_CONFIG_PATH" --cleanup="$CLEANUP" \

test/e2e_node/remote/node_conformance.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ func launchKubelet(host, workspace, results, testArgs, bearerToken string) error
181181
return fmt.Errorf("failed to create kubelet pod manifest path %q: error - %v output - %q",
182182
podManifestPath, err, output)
183183
}
184-
startKubeletCmd := fmt.Sprintf("./%s --run-kubelet-mode --logtostderr --node-name=%s"+
184+
startKubeletCmd := fmt.Sprintf("./%s --run-kubelet-mode --node-name=%s"+
185185
" --bearer-token=%s"+
186186
" --report-dir=%s %s --kubelet-flags=--pod-manifest-path=%s > %s 2>&1",
187187
conformanceTestBinary, host, bearerToken, results, testArgs, podManifestPath, filepath.Join(results, kubeletLauncherLog))

test/e2e_node/remote/node_e2e.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ func (n *NodeE2ERemote) RunTest(host, workspace, results, imageDesc, junitFilePr
200200
klog.V(2).Infof("Starting tests on %q", host)
201201
cmd := getSSHCommand(" && ",
202202
fmt.Sprintf("cd %s", workspace),
203-
fmt.Sprintf("timeout -k 30s %fs ./ginkgo %s ./e2e_node.test -- --system-spec-name=%s --system-spec-file=%s --extra-envs=%s --runtime-config=%s --logtostderr --v 4 --node-name=%s --report-dir=%s --report-prefix=%s --image-description=\"%s\" %s",
203+
fmt.Sprintf("timeout -k 30s %fs ./ginkgo %s ./e2e_node.test -- --system-spec-name=%s --system-spec-file=%s --extra-envs=%s --runtime-config=%s --v 4 --node-name=%s --report-dir=%s --report-prefix=%s --image-description=\"%s\" %s",
204204
timeout.Seconds(), ginkgoArgs, systemSpecName, systemSpecFile, extraEnvs, runtimeConfig, host, results, junitFilePrefix, imageDesc, testArgs),
205205
)
206206
return SSH(host, "sh", "-c", cmd)

test/e2e_node/runner/remote/run_remote.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ limitations under the License.
1515
*/
1616

1717
// To run the node e2e tests remotely against one or more hosts on gce:
18-
// $ go run run_remote.go --logtostderr --v 2 --ssh-env gce --hosts <comma separated hosts>
18+
// $ go run run_remote.go --v 2 --ssh-env gce --hosts <comma separated hosts>
1919
// To run the node e2e tests remotely against one or more images on gce and provision them:
20-
// $ go run run_remote.go --logtostderr --v 2 --project <project> --zone <zone> --ssh-env gce --images <comma separated images>
20+
// $ go run run_remote.go --v 2 --project <project> --zone <zone> --ssh-env gce --images <comma separated images>
2121
package main
2222

2323
import (

test/e2e_node/services/kubelet.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ func (e *E2EServices) startKubelet(featureGates map[string]bool) (*server, error
252252
cmdArgs = append(cmdArgs,
253253
"--kubeconfig", kubeconfigPath,
254254
"--root-dir", KubeletRootDirectory,
255-
"--v", LogVerbosityLevel, "--logtostderr",
255+
"--v", LogVerbosityLevel,
256256
)
257257

258258
// Apply test framework feature gates by default. This could also be overridden

test/integration/scheduler_perf/README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ How To Run
3232

3333
```shell
3434
# In Kubernetes root path
35-
make test-integration WHAT=./test/integration/scheduler_perf ETCD_LOGLEVEL=warn KUBE_TEST_VMODULE="''" KUBE_TEST_ARGS="-alsologtostderr=false -logtostderr=false -run=^$$ -benchtime=1ns -bench=BenchmarkPerfScheduling"
35+
make test-integration WHAT=./test/integration/scheduler_perf ETCD_LOGLEVEL=warn KUBE_TEST_VMODULE="''" KUBE_TEST_ARGS="-run=^$$ -benchtime=1ns -bench=BenchmarkPerfScheduling"
3636
```
3737

3838
The benchmark suite runs all the tests specified under config/performance-config.yaml.
@@ -47,14 +47,14 @@ Otherwise, the golang benchmark framework will try to run a test more than once
4747

4848
```shell
4949
# In Kubernetes root path
50-
make test-integration WHAT=./test/integration/scheduler_perf ETCD_LOGLEVEL=warn KUBE_TEST_VMODULE="''" KUBE_TEST_ARGS="-alsologtostderr=false -logtostderr=false -run=^$$ -benchtime=1ns -bench=BenchmarkPerfScheduling/SchedulingBasic/5000Nodes/5000InitPods/1000PodsToSchedule"
50+
make test-integration WHAT=./test/integration/scheduler_perf ETCD_LOGLEVEL=warn KUBE_TEST_VMODULE="''" KUBE_TEST_ARGS="-run=^$$ -benchtime=1ns -bench=BenchmarkPerfScheduling/SchedulingBasic/5000Nodes/5000InitPods/1000PodsToSchedule"
5151
```
5252

5353
To produce a cpu profile:
5454

5555
```shell
5656
# In Kubernetes root path
57-
make test-integration WHAT=./test/integration/scheduler_perf KUBE_TIMEOUT="-timeout=3600s" ETCD_LOGLEVEL=warn KUBE_TEST_VMODULE="''" KUBE_TEST_ARGS="-alsologtostderr=false -logtostderr=false -run=^$$ -benchtime=1ns -bench=BenchmarkPerfScheduling -cpuprofile ~/cpu-profile.out"
57+
make test-integration WHAT=./test/integration/scheduler_perf KUBE_TIMEOUT="-timeout=3600s" ETCD_LOGLEVEL=warn KUBE_TEST_VMODULE="''" KUBE_TEST_ARGS="-run=^$$ -benchtime=1ns -bench=BenchmarkPerfScheduling -cpuprofile ~/cpu-profile.out"
5858
```
5959

6060
### How to configure benchmark tests

vendor/modules.txt

+1
Original file line numberDiff line numberDiff line change
@@ -2014,6 +2014,7 @@ k8s.io/component-base/logs
20142014
k8s.io/component-base/logs/api/v1
20152015
k8s.io/component-base/logs/json
20162016
k8s.io/component-base/logs/json/register
2017+
k8s.io/component-base/logs/klogflags
20172018
k8s.io/component-base/logs/logreduction
20182019
k8s.io/component-base/logs/testinit
20192020
k8s.io/component-base/metrics

0 commit comments

Comments
 (0)