-
Notifications
You must be signed in to change notification settings - Fork 596
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
Remove handling code for glog #2325
Conversation
f0af5ee
to
aae1a87
Compare
seems all test failed, is it related to gate issue or this PR? |
I think it's because I converted it to a draft and Prow doesn't run jobs on drafts so they got aborted. In any case, there's still work to do here. |
@stephenfin you want to rebase and re-submit this PR? |
Yup, I will pick this up again. Just side tracked on other stuff at the moment. Hopefully later this week |
This is already handled by the earlier call to the (confusingly named) 'InitFlags' function provided by 'k8s.io/component-base/cli/flag' [1]. [1] https://github.com/kubernetes/component-base/blob/v0.28.1/cli/flag/flags.go#L51-L59 Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
This is already handled by the earlier call to the (confusingly named) 'InitFlags' function provided by 'k8s.io/component-base/cli/flag' [1]. We need to move the handling for the '--version' flag to after this to ensure we parse the flags first. [1] https://github.com/kubernetes/component-base/blob/v0.28.1/cli/flag/flags.go#L51-L59 Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
The comment here seems to have been left over when this module was extensively reworked in commit 7f1e9ed (kubernetes#2278). In any case, it's unnecessary: the call to 'klog.InitFlags' with a 'nil' argument results in the flags being registered against the global 'flag.CommandLine' flagset [1], but since cobra uses pflag rather than flag this doesn't do anything useful. You can validate this by simply building the binary without this change: you'll note that we only have '-v' and '-vmodule' arguments, which are actually added by 'cli.Run' [2][3][4]. As such, we can simply remove the calls. [1] https://github.com/kubernetes/klog/blob/v2.100.1/klog.go#L432-L434 [2] https://github.com/kubernetes/component-base/blob/v0.28.1/cli/run.go#L46 [3] https://github.com/kubernetes/component-base/blob/v0.28.1/cli/run.go#L120 [4] https://github.com/kubernetes/component-base/blob/v0.28.1/logs/logs.go#L73-L105 Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
The kubernetes ecosystem has migrated to klog now and the flags registered are for klog [1]. As such, there is no need to continue translating from glog to klog. [1] https://github.com/kubernetes/component-base/blob/v0.28.1/logs/logs.go#L73-L105 Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
Remove the code to handle translation of legacy glog options to klog options since glog is no longer a thing in kubernetes. Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
As with our earlier change to cinder-csi-plugin, the handling code for glog is no longer necessary now that the kubernetes ecosystem has migrated to klog. However, unlike that change, client-keystone-auth is not using cobra but rather plain old pflag. As a result, it is still actually registering all the klog options. We preserve this behavior. Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
This is quite similar but not identical to the earlier removal of glog handling in client-keystone-auth. As with that utility, we are using pflag rather than cobra here, but unlike that utility the klog options are not being registered. Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
aae1a87
to
c57e0ad
Compare
This is respun now. One thing that I noticed while reworking (and called out in many of the commit messages) is that we don't appear to be consistently registering the many options that klog provides, namely:
It seems that only the (Verified with the rather dumb script below) #!/usr/bin/env bash
for release in "1.20" "1.24" "1.28"; do
echo "Building $release"
# build package
git checkout "release-${release}"
make build
# store '--help' strings to directory
dir="/tmp/help-comparisons/${release}"
mkdir -p "$dir"
for binary in "barbican-kms-plugin" "cinder-csi-plugin" "client-keystone-auth" "k8s-keystone-auth" "magnum-auto-healer" "manila-csi-plugin" "octavia-ingress-controller" "openstack-cloud-controller-manager"; do
"$binary" --help > "${dir}/${binary}"
done
done
echo "Comparing help pages"
for binary in "barbican-kms-plugin" "cinder-csi-plugin" "client-keystone-auth" "k8s-keystone-auth" "magnum-auto-healer" "manila-csi-plugin" "octavia-ingress-controller" "openstack-cloud-controller-manager"; do
if ! grep -q 'alsologtostderr' "/tmp/help-comparisons/1.20/${binary}"; then
echo "${binary} was not registering klog options in 1.20"
continue
fi
if ! grep -q 'alsologtostderr' "/tmp/help-comparisons/1.24/${binary}"; then
echo "FAIL: ${binary} has dropped klog options in 1.24!"
elif ! grep -q 'alsologtostderr' "/tmp/help-comparisons/1.28/${binary}"; then
echo "FAIL: ${binary} has dropped klog options in 1.28!"
fail=1
else
echo "OK: ${binary} still has klog options"
fi
done which yields:
|
Looking at the above further, I see the following in the 1.24 help strings:
Based on the KEP, I'm guessing the two users in |
Looks like it. I would personally be in favour of getting ahead of that change. It is doubtful that we have implemented these features thoughtfully, they're most likely just cribbed from elsewhere. Probably best to do that in a separate PR, though. Also worth posting about it in slack in case anybody knows of existing users. |
Yes, to be clear, we removed them for the other executables at some point between 1.24 and 1.28 (or rather, they were removed for us via a change to the utility functions in
Can do. |
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.
IIUC we're removing handling here for a bunch of command line options which are no longer used, which is good.
My concern, which is mostly based on ignorance of the multiple different types of flag handling we have here, is that we might be dropping flags in a way which would cause the binary not to start if given those flags. Is that what your multiple version test script was doing?
If not, I think this is good to go.
If so, I think we need to come up with a deprecation process which gives users notice that they need to update their deployments.
|
||
pflag.Parse() | ||
kflag.InitFlags() |
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.
// This is a temporary hack to enable proper logging until upstream dependencies | ||
// are migrated to fully utilize klog instead of glog. | ||
klogFlags := flag.NewFlagSet("klog", flag.ExitOnError) | ||
klog.InitFlags(klogFlags) |
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.
Reviewer note: This copies all the options from the commandLine
flagset defined here to klogFlags.
This includes --log_dir, --log_file, et al.
cmd.Flags().VisitAll(func(f1 *pflag.Flag) { | ||
f2 := klogFlags.Lookup(f1.Name) | ||
if f2 != nil { | ||
value := f1.Value.String() | ||
_ = f2.Value.Set(value) | ||
} | ||
}) |
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.
This iterates over the cobra flags. For each one it looks up a correspondingly named klog flag and sets its value to the value of the cobra flag.
IOW it has no effect on the cobra flags, which are the only flags now in use.
// This is a temporary hack to enable proper logging until upstream dependencies | ||
// are migrated to fully utilize klog instead of glog. | ||
klogFlags := flag.NewFlagSet("klog", flag.ExitOnError) | ||
klog.InitFlags(klogFlags) |
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.
Now done below, so we keep the same flags.
flag.CommandLine.VisitAll(func(f1 *flag.Flag) { | ||
f2 := klogFlags.Lookup(f1.Name) | ||
if f2 != nil { | ||
value := f1.Value.String() | ||
_ = f2.Value.Set(value) | ||
} | ||
}) |
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.
Sets flags in flag.CommandLine with a corresponding klogflag to the value of the klog flag.
Nothing is now using these flags, so this is redundant.
// Sync the glog and klog flags. | ||
flag.CommandLine.VisitAll(func(f1 *flag.Flag) { | ||
f2 := klogFlags.Lookup(f1.Name) | ||
if f2 != nil { | ||
value := f1.Value.String() | ||
_ = f2.Value.Set(value) | ||
} | ||
}) |
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.
This appears to set values in flag.CommandLine, although nothing is using it?
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.
Oh it's used alright: the kflag.InitFlags
call below adds flag.CommandLine
as a flagset. However, it's not doing anything useful since no upstream dependency should be using glog any more, which means there's nothing valuable to copy. You can test this by sticking some debug printf calls in here (which is what I did 😅)
Incidentally, I wonder if we could move the outliers to using cobra as part of the same process. The inconsistency is expensive. |
Agreed, and I have a local series to do this. I just haven't pushed it yet cos sucky GitHub PR model presents everything together rather than as tidy atomic changes 🙃 |
No, it was simply testing for the presence of the various klog-specific options in
fwiw, the klog options were marked as deprecated for a release or two before they were removed. If you build and look at the help string for e.g.
Note all the
Personally, I think we can safely remove them outright (in a separate PR) but if someone wants to go through the deprecation dance again, I guess we could... EDIT: Oh, and concerning the glog options: there were 6. 2 of them - |
/lgtm Thanks, Stephen. This is very thorough, and carefully removes some very confusing code. |
@mdbooth Anything else needed to move this along? |
/approve thanks for the great update~ |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: jichenjc 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 |
* client-keystone-auth: Remove duplicate pflag.Parse call This is already handled by the earlier call to the (confusingly named) 'InitFlags' function provided by 'k8s.io/component-base/cli/flag' [1]. [1] https://github.com/kubernetes/component-base/blob/v0.28.1/cli/flag/flags.go#L51-L59 Signed-off-by: Stephen Finucane <stephenfin@redhat.com> * k8s-keystone-auth: Remove duplicate pflag.Parse call This is already handled by the earlier call to the (confusingly named) 'InitFlags' function provided by 'k8s.io/component-base/cli/flag' [1]. We need to move the handling for the '--version' flag to after this to ensure we parse the flags first. [1] https://github.com/kubernetes/component-base/blob/v0.28.1/cli/flag/flags.go#L51-L59 Signed-off-by: Stephen Finucane <stephenfin@redhat.com> * barbican-kms-plugin: Remove unnecessary klog flag calls The comment here seems to have been left over when this module was extensively reworked in commit 7f1e9ed (kubernetes#2278). In any case, it's unnecessary: the call to 'klog.InitFlags' with a 'nil' argument results in the flags being registered against the global 'flag.CommandLine' flagset [1], but since cobra uses pflag rather than flag this doesn't do anything useful. You can validate this by simply building the binary without this change: you'll note that we only have '-v' and '-vmodule' arguments, which are actually added by 'cli.Run' [2][3][4]. As such, we can simply remove the calls. [1] https://github.com/kubernetes/klog/blob/v2.100.1/klog.go#L432-L434 [2] https://github.com/kubernetes/component-base/blob/v0.28.1/cli/run.go#L46 [3] https://github.com/kubernetes/component-base/blob/v0.28.1/cli/run.go#L120 [4] https://github.com/kubernetes/component-base/blob/v0.28.1/logs/logs.go#L73-L105 Signed-off-by: Stephen Finucane <stephenfin@redhat.com> * cinder-csi-plugin: Remove handling for glog The kubernetes ecosystem has migrated to klog now and the flags registered are for klog [1]. As such, there is no need to continue translating from glog to klog. [1] https://github.com/kubernetes/component-base/blob/v0.28.1/logs/logs.go#L73-L105 Signed-off-by: Stephen Finucane <stephenfin@redhat.com> * manila-csi-plugin: Remove handling for glog Remove the code to handle translation of legacy glog options to klog options since glog is no longer a thing in kubernetes. Signed-off-by: Stephen Finucane <stephenfin@redhat.com> * client-keystone-auth: Remove handling for glog As with our earlier change to cinder-csi-plugin, the handling code for glog is no longer necessary now that the kubernetes ecosystem has migrated to klog. However, unlike that change, client-keystone-auth is not using cobra but rather plain old pflag. As a result, it is still actually registering all the klog options. We preserve this behavior. Signed-off-by: Stephen Finucane <stephenfin@redhat.com> * k8s-keystone-auth: Remove handling for glog This is quite similar but not identical to the earlier removal of glog handling in client-keystone-auth. As with that utility, we are using pflag rather than cobra here, but unlike that utility the klog options are not being registered. Signed-off-by: Stephen Finucane <stephenfin@redhat.com> --------- Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
/cherry-pick release-1.28 |
/cherry-pick release-1.27 |
/cherry-pick release-1.26 |
@jichenjc: #2325 failed to apply on top of branch "release-1.27":
In response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
@jichenjc: new pull request created: #2534 In response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
@jichenjc: #2325 failed to apply on top of branch "release-1.26":
In response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
* client-keystone-auth: Remove duplicate pflag.Parse call This is already handled by the earlier call to the (confusingly named) 'InitFlags' function provided by 'k8s.io/component-base/cli/flag' [1]. [1] https://github.com/kubernetes/component-base/blob/v0.28.1/cli/flag/flags.go#L51-L59 Signed-off-by: Stephen Finucane <stephenfin@redhat.com> * k8s-keystone-auth: Remove duplicate pflag.Parse call This is already handled by the earlier call to the (confusingly named) 'InitFlags' function provided by 'k8s.io/component-base/cli/flag' [1]. We need to move the handling for the '--version' flag to after this to ensure we parse the flags first. [1] https://github.com/kubernetes/component-base/blob/v0.28.1/cli/flag/flags.go#L51-L59 Signed-off-by: Stephen Finucane <stephenfin@redhat.com> * barbican-kms-plugin: Remove unnecessary klog flag calls The comment here seems to have been left over when this module was extensively reworked in commit 7f1e9ed (kubernetes#2278). In any case, it's unnecessary: the call to 'klog.InitFlags' with a 'nil' argument results in the flags being registered against the global 'flag.CommandLine' flagset [1], but since cobra uses pflag rather than flag this doesn't do anything useful. You can validate this by simply building the binary without this change: you'll note that we only have '-v' and '-vmodule' arguments, which are actually added by 'cli.Run' [2][3][4]. As such, we can simply remove the calls. [1] https://github.com/kubernetes/klog/blob/v2.100.1/klog.go#L432-L434 [2] https://github.com/kubernetes/component-base/blob/v0.28.1/cli/run.go#L46 [3] https://github.com/kubernetes/component-base/blob/v0.28.1/cli/run.go#L120 [4] https://github.com/kubernetes/component-base/blob/v0.28.1/logs/logs.go#L73-L105 Signed-off-by: Stephen Finucane <stephenfin@redhat.com> * cinder-csi-plugin: Remove handling for glog The kubernetes ecosystem has migrated to klog now and the flags registered are for klog [1]. As such, there is no need to continue translating from glog to klog. [1] https://github.com/kubernetes/component-base/blob/v0.28.1/logs/logs.go#L73-L105 Signed-off-by: Stephen Finucane <stephenfin@redhat.com> * manila-csi-plugin: Remove handling for glog Remove the code to handle translation of legacy glog options to klog options since glog is no longer a thing in kubernetes. Signed-off-by: Stephen Finucane <stephenfin@redhat.com> * client-keystone-auth: Remove handling for glog As with our earlier change to cinder-csi-plugin, the handling code for glog is no longer necessary now that the kubernetes ecosystem has migrated to klog. However, unlike that change, client-keystone-auth is not using cobra but rather plain old pflag. As a result, it is still actually registering all the klog options. We preserve this behavior. Signed-off-by: Stephen Finucane <stephenfin@redhat.com> * k8s-keystone-auth: Remove handling for glog This is quite similar but not identical to the earlier removal of glog handling in client-keystone-auth. As with that utility, we are using pflag rather than cobra here, but unlike that utility the klog options are not being registered. Signed-off-by: Stephen Finucane <stephenfin@redhat.com> --------- Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
What this PR does / why we need it:
Everything in k8s has switched to klog for some time now. Lots more context in the individual commit messages.
Some minor issues introduced in #2324 are addressed. Again, there's lots more context in the commit messages.
Which issue this PR fixes(if applicable):
N/A
Special notes for reviewers:
N/A
Release note: