Automated cherry pick of #114680: k8s.io/component-base/logs: fix usage through Go flag#115229
Merged
k8s-ci-robot merged 4 commits intokubernetes:release-1.26from Feb 10, 2023
Conversation
api/v1.AddFlags only supports a pflag.FlagSet. The assumption was that code
which wants to use flag.FlagSet can use VisitAll to copy the flags. That works,
with one caveat: the flag.FlagSet help implementation will call String for the
zero value to determine whether the flag has a non-default value. This
currently leads to additional warnings at the end of the -help output:
panic calling String method on zero v1.verbosityLevelPflag for flag v: runtime error: invalid memory address or nil pointer dereference
panic calling String method on zero v1.vmoduleConfigurationPFlag for flag vmodule: runtime error: invalid memory address or nil pointer dereference
Supporting usage of methods with the zero value is good practice anyway and
thus gets added. This then avoids these panics.
Both pflag and standard FlagSet are covered.
A full string comparison might fail when the underlying libraries change how they format the help text. A regex match is less strict, but still makes some assumptions about the implementation.
The test was meant to fail when there are unexpected additional lines like the "panic calling String method" messages. But `assert.Regexp` does a search for the regexp, not a full string match, and thus succeeded even if those lines are present. A full match needs to be requested explicitly with ^ and $.
Contributor
Author
|
I manually added #115195. |
Contributor
Author
|
/sig instrumentation |
Contributor
Author
|
/assign @liggitt This is the backport of the two PRs that you reviewed. |
Member
|
/lgtm |
Contributor
|
LGTM label has been added. DetailsGit tree hash: 4dc381a8ed3739917f6294db38de69f1cd078de2 |
Contributor
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: liggitt, pohly The full list of commands accepted by this bot can be found here. The pull request process is described here DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
Contributor
Author
|
/cc kubernetes/release-managers |
|
/triage accepted |
|
/lgtm |
Member
|
/retest |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Cherry pick of #114680 on release-1.26.
#114680: k8s.io/component-base/logs: fix usage through Go flag
For details on the cherry pick process, see the cherry pick requests page.