-
Notifications
You must be signed in to change notification settings - Fork 39.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
kube-apiserver: fix missing global flags for --help #70204
kube-apiserver: fix missing global flags for --help #70204
Conversation
/assign @nikhiljindal |
/ok-to-test |
Thank you! Hmm, looks like there are some dependency issues. Will look into them. |
d6e087d
to
83c25d9
Compare
/retest. This should work now. |
|
||
// normalize replaces underscores with hyphens. We should always use hyphens | ||
// instead of underscores when registering kube-apiserver flags. | ||
func normalize(s string) string { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it should belong to another pull i suppose
register(global, local, "stderrthreshold") | ||
register(global, local, "vmodule") | ||
register(global, local, "log_backtrace_at") | ||
register(global, local, "log_dir") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we have to register these by hardcoding their name here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I couldn't think of a better way since the flags are initialized the moment the glog
package is used:
kubernetes/vendor/github.com/golang/glog/glog.go
Lines 399 to 404 in 5336866
flag.BoolVar(&logging.toStderr, "logtostderr", false, "log to standard error instead of files") | |
flag.BoolVar(&logging.alsoToStderr, "alsologtostderr", false, "log to standard error as well as files") | |
flag.Var(&logging.verbosity, "v", "log level for V logs") | |
flag.Var(&logging.stderrThreshold, "stderrthreshold", "logs at or above this threshold go to stderr") | |
flag.Var(&logging.vmodule, "vmodule", "comma-separated list of pattern=N settings for file-filtered logging") | |
flag.Var(&logging.traceLocation, "log_backtrace_at", "when logging hits line file:N, emit a stack trace") |
We're doing the same thing in #68054 too. Previously without the named sections, we added everything from the global flag set:
pflag.CommandLine.AddGoFlagSet(goflag.CommandLine) |
With the named logical sections, we will need to extract out relevant flags so that we could group them.
pflagFlag.Name = normalize(pflagFlag.Name) | ||
local.AddFlag(pflagFlag) | ||
} else { | ||
panic(fmt.Sprintf("failed to find flag in global flagset (flag): %s", globalName)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
dont panic, return an error instead
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
scattering multiple local functions makes it hard to read. lumping them into one is fine. also, plz keep a minimal change and put unrelated changes into another pull if u want.
cc @logicalhan |
/hold #68054 is trying to add in |
/milestone v1.13 |
// register adds a flag to local that targets the Value associated with the Flag named globalName in global | ||
func register(global *flag.FlagSet, local *pflag.FlagSet, globalName string) { | ||
if f := global.Lookup(globalName); f != nil { | ||
local.AddGoFlag(f) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why is the logic different from a77652e#diff-2fd8f885c4e1d904b7d678e5991aade4R68 ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sttts @imjching @stewart-yu we need both to match.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sttts @dims Originally I removed the normalize
part because we don't need it. It was there to ensure that all globally registered flags that use underscores will be normalized to use hyphens instead.
klog
registers flags using underscores:
https://github.com/dims/klog/blob/master/klog.go#L411-L419
Those cloud provider and admission packages register flags using hyphens instead. I have updated the code and added the normalize
part back. Do we actually need both files to match? The commit that was provided above was for klog
flags and therefore we need to normalize those flags.
Also, from documentation, the two snippets of code below are equivalent:
pflagFlag := pflag.PFlagFromGoFlag(f)
local.AddFlag(pflagFlag)
local.AddGoFlag(f)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cc @stewart-yu
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
seems below enough in here @dims
f.Name = normalize(f.Name)
local.AddFlag(f)
but add
pflagFlag := pflag.PFlagFromGoFlag(f)
i'm not obey also, but seems no need for component flag now, may be need for future
global := flag.CommandLine | ||
local := pflag.NewFlagSet(os.Args[0], pflag.ExitOnError) | ||
|
||
register(global, local, "default-not-ready-toleration-seconds") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
how do we know we did not forget flags? We need a test for that, or if that is tricky due to globals in tests, we should at least have a check with a glog.Error here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel that doing a panic here rather than returning an error would be better since it would alert us that we failed to allow libraries to globally register their flags. What do you think? @yue9944882
@imjching iiuc, assuming any flag required by register
here got deprecated in the vendored dependency, then we would be surprised w/ a panic, amiright? if u notice, we seldom do panic thru the codebase, which imho is neither user-friendly nor developer-friendly.
while i see we've been already doing that in controller, so...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sttts @yue9944882 Updated the patch by adding in tests. (It's similar to the other one that was merged earlier.) Are those sufficient?
1d7d26e
to
85b794e
Compare
func register(global *flag.FlagSet, local *pflag.FlagSet, globalName string) { | ||
if f := global.Lookup(globalName); f != nil { | ||
pflagFlag := pflag.PFlagFromGoFlag(f) | ||
pflagFlag.Name = normalize(pflagFlag.Name) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why add Line72? no need
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@imjching i am ok with "remove it" with a tracking issue (or PR) for the other piece of code for 1.14
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dims Sorry, I'm not quite sure if I understand you. If we were to remove Line 72 temporarily, i.e. pflagFlag := pflag.PFlagFromGoFlag(f)
, what should the issue track and what does the "other piece of code" refer to?
add test look much better now
2、combine
WDYT? @imjching |
Thank you for your prompt review, @stewart-yu! Here are my thoughts for your summary:
Would like to hear thoughts from everyone else as well 😄 |
85b794e
to
103066c
Compare
Signed-off-by: Jay Lim <jay@imjching.com>
103066c
to
7fbdcf8
Compare
@imjching I see the other two related PRs got closed but this is still going in, are the other two dropped for a later time (1.14) ? |
/assign @sttts |
/lgtm |
/approve |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: imjching, sttts The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
/test pull-kubernetes-verify |
/test pull-kubernetes-integration |
What type of PR is this?
/kind bug
What this PR does / why we need it: In #64517, we introduced logical sections for the
--help
output in thekube-apiserver
binary. It seems like it does not consider global flags that were registered through theflag
package. This PR fixes that issue. We will output glog related and version flags in the "global" section and everything else in the "generic" section.Which issue(s) this PR fixes (optional, in
fixes #<issue number>(, fixes #<issue_number>, ...)
format, will close the issue(s) when PR gets merged):See #70145.
Special notes for your reviewer: The original PR is in #70164. The plan to is to break it down into individual PRs.
Here's the simplified result of
kube-apiserver --help
. It now shows the appropriate global flags and generic flags that were missing.Does this PR introduce a user-facing change?:
/sig cli
/cc @stewart-yu