Commit Graph

44 Commits

Author SHA1 Message Date
Patrick Ohly
00e4a599f6 command lines: always show flags with hyphens
All Kubernetes commands should show flags with hyphens in their help text even
when the flag originally was defined with underscore. Converting a command to
this style is not breaking its command line API because the old-style parameter
with underscore is accepted as alias.

The easiest solution to achieve this is to set normalization shortly before
running the command in the new central cli.Run or the few places where that
function isn't used yet.

There may be some texts which depends on normalization at flag definition time,
like the --logging-format usage warning. Those get generated assuming that
hyphens will be used.
2021-09-30 13:46:49 +02:00
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
Han Kang
866ea74326 remove pkg/version and some of redundant copies of it
Change-Id: Ia58367c1b1274bfb49c8a4784051463abaf795de
2019-09-16 16:24:35 -07:00
Han Kang
0895ac212d migrate kube-proxy metrics to stability framework 2019-08-28 12:49:54 -07:00
Odin Ugedal
7caf51daa4
Remove duplicate error messages from cli commands
Since we never use the cobras "SilenceErrors" or "SilenceUsage",
a command executed with "cmd.Execute()" will never return an error
without printing it.

The current behavior results in all error messages being printed twice:

Example:

$ kubectl abc
Error: unknown command "abc" for "kubectl"
Run 'kubectl --help' for usage.
unknown command "abc" for "kubectl"

This applies to all cli commands using Cobra. To verify, follow the code
path of the Execute function:

https://github.com/spf13/cobra/blob/c439c4fa0937/command.go#L793
Signed-off-by: Odin Ugedal <odin@ugedal.com>
2019-06-27 21:55:14 +02:00
Marek Counts
7744f90830 Moved flag and globalflag
Moved all flag code from `staging/src/k8s.io/apiserver/pkg/util/[flag|globalflag]` to `component-base/cli/[flag|globalflag]` except for the term function because of unwanted dependencies.
2019-02-15 10:28:13 -05:00
Marek Counts
ba81a5409a move logs into component-base
all the code changes to move move /apiserver/pkg/util/logs into /component-base/logs
2019-01-17 09:16:21 -05:00
Mikhail Mazurskiy
3a243090a5
Simplify random seed initialization
There is no need to set the time zone as the result does not
depend on it
2018-10-11 21:01:15 +11:00
Davanum Srinivas
fc4426f040 Partial revert to fix local-up-cluster.sh 2018-02-24 14:10:27 -05:00
stewart-yu
25e110dffc [kube-proxy]enhance kubeproxy init flag 2018-02-23 17:14:19 +08:00
David Eads
d7ddcca231 low hanging fruit for using cobra commands 2018-01-17 13:43:43 -05:00
huzhifeng
3196300fc2
Run go fmt
Signed-off-by: huzhifeng <huzhifeng@douyu.tv>
2017-08-18 16:03:25 +08:00
netroby
ac2729ed0a If command.Execute() return err, print to stdErr 2017-08-18 13:05:58 +08:00
Andy Goldstein
f51c2c445c Restore kube-proxy --version 2017-05-19 14:40:35 -04:00
Zihong Zheng
ca59d909cf Separate healthz server from metrics server in kube-proxy
- /healthz will be served on 0.0.0.0:10256 by default.
- /metrics and /proxyMode will be served on port 10249
  as before.
- Healthz handler will verify timestamp in iptables mode.
2017-05-05 14:43:44 -07:00
Andy Goldstein
43cb024402 Add kube-proxy config file support
Add support for configuring kube-proxy via a config file instead of
command line flags.
2017-05-01 18:02:47 -04:00
deads2k
78d8a8efa8 copy pkg/util/logs to apiserver 2017-02-13 12:07:15 -05:00
Dr. Stefan Schimanski
82826ec273 pkg/util/flag: move to k8s.io/apiserver 2017-01-24 20:56:03 +01:00
Dr. Stefan Schimanski
3d9449a353 genericapiserver: fix imports 2017-01-19 13:06:47 +01:00
deads2k
4d7fcae85a mechanicals 2017-01-05 11:14:27 -05:00
Kris
1740358573 Split the version metric out to its own package 2016-08-24 11:47:16 -07:00
Kris
8d6ce0dcc6 Remove implicit Prometheus metrics from client 2016-08-19 10:11:45 -07:00
Chao Xu
a771578a1c move pkg/util/ files to their own package to reduce client-go dependencies 2016-08-05 23:32:02 -07:00
Lucas Käldström
88ea80b572 Remove GOMAXPROCS() calls because they are unnecessary 2016-07-19 11:08:21 +03:00
David McMahon
ef0c9f0c5b Remove "All rights reserved" from all the headers. 2016-06-29 17:47:36 -07:00
harry
f19d59cf35 Move flag into sub pkg 2016-03-14 21:30:38 +08:00
Clayton Coleman
715b77cbcd Split proxy and scheduler arguments
Keep options and flags distinct from initialization
2016-01-06 21:34:31 -05:00
gmarek
1c25c2cd99 Refactor KubeProxy to allow mocking of all moving parts. 2015-09-23 18:47:05 +02:00
Mike Danese
8e33cbfa28 rewrite go imports 2015-08-05 17:30:03 -07:00
Eric Paris
6b3a6e6b98 Make copyright ownership statement generic
Instead of saying "Google Inc." (which is not always correct) say "The
Kubernetes Authors", which is generic.
2015-05-01 17:49:56 -04:00
Eric Paris
036937227f Use Fprintf to print formatted strings
Shouldn't be using Fprint() with a format string.
2015-04-14 10:51:57 -04:00
Eric Paris
8e7d14196f Fix printing errors from failed binary runs
I had the kublet die on startup and the only error was "0x401da0"  Which
I assume is an address of the err.Error function.  The other way to fix
this, I think, would be to use err.Error(), however that could cause
fmt.Fprintf() problems, debuging on the error message people used.

Now I get a nice clean error I can understand:

"cAdvisor.New() err = mountpoint for cpu not found"
2015-04-10 17:56:47 -04:00
Clayton Coleman
015bc3b7bd Remove global map from healthz
It currently is impossible to use two healthz handlers on different
ports in the same process.  This removes the global variables in favor
of requiring the consumer to specify all health checks up front.
2015-03-19 19:49:44 -04:00
Tim Hockin
8c2ff81ae0 move pkg/proxy/server to cmd/kube-proxy/app 2015-02-20 08:49:12 -08:00
Daniel Smith
fcddefa184 Set GOMAXPROCS. Print errors on stderr. 2015-02-19 10:30:31 -08:00
Joe Beda
638069b879 Convert proxy server to hyperkube 2015-02-02 14:03:13 -08:00
Joe Beda
6bd6b905f5 Address code review comments
Add some documentation.
Create new util.InitFlags() function to merge and parse in one step.
2015-01-15 09:12:20 -08:00
Joe Beda
dcd00c936e Move all kubernetes to posix flags 2015-01-15 09:12:19 -08:00
Vishnu Kannan
6f53f33fda Set oom_score_adj for kubelet and kube-proxy to a low value to help them survive system memory pressure. 2014-12-24 00:34:28 +00:00
James DeFelice
e27b8f0df7 proxy should fail fast if proxier is nil, rather than panic later 2014-12-15 12:56:35 -05:00
Eric Tune
0c2a4302f5 Fix race that drops the first event on restart.
RegisterHandlers was called after the listening for events had already begun.
So, there was a race where sometimes the first update would, with the
initial state, would notify an empty list of listeners.
This showed up in services.sh e2e test as empty service and endpoint maps
after the test step which restarts the kube-proxy.

Perhaps due to timing, this doesn't show up with etcd source, but does
show up with apiserver as a source.  A separate PR makes APIserver
the source as a default, and depends on this.

This took me several days to debug.
2014-12-02 22:04:45 -08:00
Mike Danese
5bda95f9fe added healthz check to the proxy with configurable port 2014-11-23 09:07:19 -08:00
Joe Beda
66d287f7e4 Merge branch 'rename-to-kube' of https://github.com/eparis/kubernetes into eparis-rename-to-kube
* 'rename-to-kube' of https://github.com/eparis/kubernetes:
  rename kube server binaries to kube-

Conflicts:
	docs/salt.md
2014-11-17 09:52:10 -08:00
Eric Paris
a99c3c7963 rename kube server binaries to kube-
apiserver becomes kube-apiserver
controller-manager -> kube-controller-manager
scheduler and proxy similarly.

Only thing I promise is that right now hack/build-go.sh and
build/release.sh exit with 0.  That's it.  Who knows if any of this
actually works....
2014-11-13 20:08:26 -05:00