kubectl/pkg/util
Patrick Ohly 466b483531 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.

Kubernetes-commit: 21d1bcd6b8498370832fa76f680d3de56837bc83
2021-09-16 18:18:35 +02:00
..
certificate Add v1 CSR support to kubectl describe 2020-06-04 12:05:51 -04:00
deployment Add --chunk-size support to kubectl describe 2021-04-20 11:24:35 -07:00
event Move pkg/kubectl/util/event into staging 2019-06-19 15:31:51 -07:00
fieldpath Move pkg/kubectl/util/fieldpath to staging 2019-06-19 17:13:57 -07:00
hash Immutable field and validation 2019-11-26 13:29:26 +01:00
i18n update translations 2021-07-06 20:43:49 +02:00
interrupt Moved pkg/kubectl/util/term, pkg/kubectl/util/templates, pkg/kubectl/util/interrupt, and pkg/kubectl/util/interrupt to staging 2019-06-19 16:31:38 +02:00
openapi remove go-openapi/spec 2021-04-20 17:48:33 +02:00
podutils kubectl: Inline the containers for the user in attach/exec 2021-02-11 11:40:25 -05:00
qos Delete duplicate resource.Quantity.Copy() 2019-08-19 17:23:14 -07:00
rbac When combining PolicyRules, don't duplicate verbs 2020-05-18 15:20:06 -04:00
resource Downward API hugepages 2020-11-06 14:22:53 -05:00
slice Move pkg/util/slice and update refs 2019-06-19 23:24:56 -04:00
storage Update helper methods to print and parse ReadWriteOncePod access mode 2021-03-10 20:51:43 -08:00
templates go1.14: fix gofmt errors 2020-06-23 15:06:11 -04:00
term generated: Run hack/update-gofmt.sh 2021-08-12 17:13:11 -04:00
apply.go Move pkg/kubectl/apply.go to staging 2019-07-24 20:40:25 -07:00
completion.go Join common functions for completion 2021-05-15 21:22:42 -04:00
completion_test.go Add tests for completion utility functions 2021-06-05 21:11:34 -04:00
pod_port.go Move pkg/kubectl/util to staging 2019-07-24 11:59:28 -07:00
pod_port_test.go Move pkg/kubectl/util to staging 2019-07-24 11:59:28 -07:00
service_port.go Move pkg/kubectl/util to staging 2019-07-24 11:59:28 -07:00
service_port_test.go Move pkg/kubectl/util to staging 2019-07-24 11:59:28 -07:00
umask.go generated: Run hack/update-gofmt.sh 2021-08-12 17:13:11 -04:00
umask_windows.go generated: Run hack/update-gofmt.sh 2021-08-12 17:13:11 -04:00
util.go cleanup: fix some error log capitalization 2020-10-28 16:44:54 +08:00
util_test.go Move pkg/kubectl/util to staging 2019-07-24 11:59:28 -07:00