kubernetes/test
Patrick Ohly 21d1bcd6b8 initialize logging after flag parsing
It wasn't documented that InitLogs already uses the log flush frequency, so
some commands have called it before parsing (for example, kubectl in the
original code for logs.go). The flag never had an effect in such commands.

Fixing this turned into a major refactoring of how commands set up flags and
run their Cobra command:

- component-base/logs: implicitely registering flags during package init is an
  anti-pattern that makes it impossible to use the package in commands which
  want full control over their command line. Logging flags must be added
  explicitly now, something that the new cli.Run does automatically.

- component-base/logs: AddFlags would have crashed in kubectl-convert if it
  had been called because it relied on the global pflag.CommandLine. This
  has been fixed and kubectl-convert now has the same --log-flush-frequency
  flag as other commands.

- component-base/logs/testinit: an exception are tests where flag.CommandLine has
  to be used. This new package can be imported to add flags to that
  once per test program.

- Normalization of the klog command line flags was inconsistent. Some commands
  unintentionally didn't normalize to the recommended format with hyphens. This
  gets fixed for sample programs, but not for production programs because
  it would be a breaking change.

This refactoring has the following user-visible effects:

- The validation error for `go run ./cmd/kube-apiserver --logging-format=json
  --add-dir-header` now references `add-dir-header` instead of `add_dir_header`.

- `staging/src/k8s.io/cloud-provider/sample` uses flags with hyphen instead of
  underscore.

- `--log-flush-frequency` is not listed anymore in the --logging-format flag's
  `non-default formats don't honor these flags` usage text because it will also
  work for non-default formats once it is needed.

- `cmd/kubelet`: the description of `--logging-format` uses hyphens instead of
  underscores for the flags, which now matches what the command is using.

- `staging/src/k8s.io/component-base/logs/example/cmd`: added logging flags.

- `apiextensions-apiserver` no longer prints a useless stack trace for `main`
  when command line parsing raises an error.
2021-09-30 13:46:49 +02:00
..
cmd updates pause image references 2021-08-29 21:50:05 -07:00
conformance test/conformance/image: Update runner image to base-debian11 2021-09-20 21:05:06 -04:00
e2e initialize logging after flag parsing 2021-09-30 13:46:49 +02:00
e2e_kubeadm run hack/update-netparse-cve.sh 2021-08-20 10:42:09 +02:00
e2e_node initialize logging after flag parsing 2021-09-30 13:46:49 +02:00
fixtures updates pause image references 2021-08-29 21:50:05 -07:00
fuzz hack/update-bazel.sh 2021-02-28 15:17:29 -08:00
images initialize logging after flag parsing 2021-09-30 13:46:49 +02:00
instrumentation hack/verify fixes 2021-07-28 19:26:44 -07:00
integration initialize logging after flag parsing 2021-09-30 13:46:49 +02:00
kubemark update node-problem-detector v0.8.9 2021-07-28 01:02:56 +00:00
list Remove KubeDescribe 2021-03-04 07:54:53 +01:00
soak/serve_hostnames hack/update-bazel.sh 2021-02-28 15:17:29 -08:00
typecheck Reduce the number of parallel typechecks to 2 2021-08-26 16:53:13 +02:00
utils releng: Update build images to Debian 11 (Bullseye) 2021-09-20 20:51:32 -04:00
OWNERS add aojea to test OWNERS 2021-08-11 10:54:35 +02:00