-
Notifications
You must be signed in to change notification settings - Fork 348
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
better deprecated option handling #255
Conversation
1ceadfb
to
e03039d
Compare
@jsafrane this is an idea that I just had. Not sure whether it's worthwhile. |
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 agree with your premise that we could do a better job handling the deprecated options. However, I think maybe we could simplify the solution. Please see the comment which I tagged "This comment supersedes all my other comments."
@@ -68,6 +81,8 @@ func init() { | |||
var config *rest.Config | |||
var err error | |||
|
|||
deprecatedOption{option: "connection-timeout"}.Define() |
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.
these should be defined at the same place as the flags to keep all flag's consolidated
// deprecatedOption can be used to define a deprecated command line | ||
// flag. Whenever it is set, regardless to which value, a warning is | ||
// triggered. | ||
type deprecatedOption struct { |
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 think these could exist in a different util
type package. Maybe a specific file for it
} | ||
|
||
func (d deprecatedOption) String() string { return "" } | ||
func (d deprecatedOption) Set(value string) error { |
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.
could you be explicit in what interface this is implementing for strict interface checking (mostly for code maintainability and my understanding)
e.g:
var _ InterfaceName := &deprecatedOption{}
return nil | ||
} | ||
func (d deprecatedOption) Type() string { return "" } | ||
func (d deprecatedOption) Define() { flag.Var(d, d.option, "This option is deprecated.") } |
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.
could the implementation of Define
just live inside Set
instead?
klog.Warningf("Warning: option %s=%q is deprecated and has no effect", d.option, value) | ||
return nil | ||
} | ||
func (d deprecatedOption) Type() string { return "" } |
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 comment supersedes all my other comments.
in general I'm not sure why we're using a struct here when maybe just a function will do. I think I would prefer that the definition of these deprecated flags more closely mirrored that of a normal flag. Maybe something as simple that would be invoked like this:
connectionTimeout = deprecatedflag.Set("connection-timeout")
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.
Yes, the API can be made nicer. Let me try something along those lines.
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.
@davidz627 please have another look. I moved the code into an utility package with a single function as interface. Actually, it's two now, because I also added support for boolean flags.
e03039d
to
bfdbff0
Compare
bfdbff0
to
029c447
Compare
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.
mostly lgtm just some final comments/questions
return nil | ||
} | ||
func (d deprecated) Type() string { return "" } | ||
func (d deprecated) IsBoolFlag() bool { return d.isBool } |
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.
same question, why do we need this?
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.
IsBoolFlag
is how the flag
package determines whether a value needs the special bool handling.
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.
Force-pushed.
return nil | ||
} | ||
func (d deprecated) Type() string { return "" } | ||
func (d deprecated) IsBoolFlag() bool { return d.isBool } |
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.
IsBoolFlag
is how the flag
package determines whether a value needs the special bool handling.
I'd appreciate this in csi-lib-utils, because more sidecars have deprecated |
I'll move the utility package to csi-lib-utils. |
This switches to the latest external-snapshotter (picked from the master branch for now). This is necessary because the latest official release is no longer compatible with other dependencies (different client-go versions). Key changes: (1/9) Wrote k8s.io/utils@master: new project (2/9) Wrote k8s.io/[email protected]: version changed (was kubernetes-1.13.0-beta.1) (3/9) Wrote k8s.io/[email protected]: version changed (was kubernetes-1.13.0-beta.1) (4/9) Wrote github.com/kubernetes-csi/external-snapshotter@master: version changed (was v1.0.1) (5/9) Wrote k8s.io/[email protected]: version changed (was kubernetes-1.13.0-beta.1)
029c447
to
bd88f46
Compare
# TODO: remove when released | ||
[[constraint]] | ||
name = "github.com/kubernetes-csi/external-snapshotter" | ||
branch = "master" |
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.
Setting it to master is not safe though. Maybe we should cut a release of external-snapshotter first.
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 think it is fine. The lock file ensures that we keep on using the correct commit. And updates are controlled
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 agree. Whoever does the next dep ensure -update
will have to check the TODOs, and thus will ensure that we do not update beyond the next external-snapshotter release.
The warning for the deprecated connection-timeout was only printed when it was set to a non-default value. When set explicitly to zero (admittedly unlikely), no warning was printed. This approach also gets rid of the actual variable and thus catches code which accidentally still uses it (see kubernetes-csi#239). This depends on a more recent csi-lib-utils. Because the previous vendoring was done with an older dep version, "dep ensure -update" cannot update just that project, so everything gets updated instead.
@msau42 force-pushed a version which passes "make test" and "make build" locally. |
/lgtm |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: msau42, pohly 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 |
379a1bb9b Merge pull request kubernetes-csi#255 from humblec/sidecar-md a5667bbbb fix typo in sidecar release process 49676850e Merge pull request kubernetes-csi#254 from bells17/add-github-actions d9bd160c2 Update skip list in codespell GitHub Action f5aebfc9f Add GitHub Actions workflows git-subtree-dir: release-tools git-subtree-split: 379a1bb9b001c0d62a091a21f1a4efaf42987248
f40f0ccd4 Merge pull request kubernetes-csi#256 from solumath/master cfa92106c Instruction update 379a1bb9b Merge pull request kubernetes-csi#255 from humblec/sidecar-md a5667bbbb fix typo in sidecar release process 49676850e Merge pull request kubernetes-csi#254 from bells17/add-github-actions d9bd160c2 Update skip list in codespell GitHub Action adb3af9df Merge pull request kubernetes-csi#252 from bells17/update-go-version f5aebfc9f Add GitHub Actions workflows b82ee3888 Merge pull request kubernetes-csi#253 from bells17/fix-typo c31745621 Fix typo 0a7850561 Bump to Go 1.22.3 edd89ad58 Merge pull request kubernetes-csi#251 from jsafrane/add-logcheck 043fd0991 Add test-logcheck target d7535ae0c Merge pull request kubernetes-csi#250 from jsafrane/go-1.22 b52e7ad35 Update go to 1.22.2 14fdb6f66 Merge pull request kubernetes-csi#247 from msau42/prow 9b4352e9f Update release playbook c7bb972cc Fix release notes script to use fixed tags 463a0e9f5 Add script to update specific go modules git-subtree-dir: release-tools git-subtree-split: f40f0ccd458f2d4555e3ca98d69b5a984bae0f14
988496a1f Merge pull request kubernetes-csi#257 from jakobmoellerdev/csi-prow-sidecar-e2e-path 028f8c698 chore: bump to Go 1.22.5 69bd71e8a chore: add CSI_PROW_SIDECAR_E2E_PATH f40f0ccd4 Merge pull request kubernetes-csi#256 from solumath/master cfa92106c Instruction update 379a1bb9b Merge pull request kubernetes-csi#255 from humblec/sidecar-md a5667bbbb fix typo in sidecar release process 49676850e Merge pull request kubernetes-csi#254 from bells17/add-github-actions d9bd160c2 Update skip list in codespell GitHub Action f5aebfc9f Add GitHub Actions workflows git-subtree-dir: release-tools git-subtree-split: 988496a1fc3849ed793e03012fdd56813d13d46c
The warning for the deprecated options was only printed
when it was set to a non-default value. When set explicitly to
zero or empty (admittedly unlikely), no warning was printed.
This approach also gets rid of the actual variables and thus catches
code which accidentally still uses it (see
#239).