Repository navigation
util/def: add def.Bool and def.Duration default parse helpers - #20022
Conversation
717125a to
e750128
Compare
sfllaw
left a comment
There was a problem hiding this comment.
@ibobgunardi, thanks for picking up this issue that was just filed.
I left some feedback, with only one blocking concern. To keep things bite-sized, you might want to just start with the obviously correct replacements and then submit a follow-up PR for the defaultEnv functions.
| } | ||
| v, _ := opt.Bool(vs).Get() | ||
| return v | ||
| return parsefallback.Bool(os.Getenv(envName), defVal) |
There was a problem hiding this comment.
🐞 Bug (blocking): As you called out in your PR description, this is a behaviour change. I’m pretty sure we chose to use opt.Bool on purpose, so let’s not break that.
There was a problem hiding this comment.
I think there might be a way to make this behave exactly the same using your new Bool function, but I would double-check with a fuzz-test just to be sure.
| if defBool(r.FormValue("probe"), false) { | ||
| timeout := defDuration(r.FormValue("timeout"), routecheck.DefaultTimeout) | ||
| if parsefallback.Bool(r.FormValue("probe"), false) { | ||
| timeout := parsefallback.Duration(r.FormValue("timeout"), routecheck.DefaultTimeout) |
There was a problem hiding this comment.
📛 Naming (non-blocking): I suggest naming this package tailscale.com/util/def, so that you call def.Bool and def.Duration.
| // Copyright (c) Tailscale Inc & contributors | ||
| // SPDX-License-Identifier: BSD-3-Clause | ||
|
|
||
| package parsefallback |
There was a problem hiding this comment.
🧪 Testing (non-blocking): Unless strictly necessary, let’s prefer blackbox testing by putting this test in a *_test package and using only exported symbols.
e750128 to
19f8c1c
Compare
|
Thanks, I narrowed this down. The k8s/containerboot env helpers are back to their original code now, so this PR only covers the localapi form cases. I also renamed the package to util/def, moved the tests to def_test, and amended the commit with Updates #20018. |
Updates #20018 Signed-off-by: Bobby <[email protected]>
19f8c1c to
9324239
Compare
|
Thanks for the review. I trimmed this back to the straightforward replacements only: the I reran: |
sfllaw
left a comment
There was a problem hiding this comment.
Thanks for the revisions! I have noticed a couple new blocking concerns, which we definitely should address. And then some non-blocking suggestions that you can either incorporate or disagree.
Signed-off-by: Bobby <[email protected]>
994ecdc to
e54ed56
Compare
| "tailscale.com/net/netmon" | ||
| "tailscale.com/net/portmapper" | ||
| "tailscale.com/types/logger" | ||
| "tailscale.com/util/def" |
There was a problem hiding this comment.
🐞 Bug (blocking): One last problem, you need to run make updatedeps:
+ exec /home/runner/.cache/tsgo/c803676bcc7f2b195b167a53d49d728045cd9b36/bin/go run github.com/tailscale/depaware --check --vendor --internal tailscale.com/cmd/tailscaled tailscale.com/cmd/tailscale tailscale.com/cmd/derper tailscale.com/cmd/k8s-operator tailscale.com/cmd/stund tailscale.com/cmd/tsidp
go: downloading github.com/tailscale/depaware v0.0.0-20251001183927-9c2ad255ef3f
go: downloading github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e
go: downloading golang.org/x/tools v0.44.0
go: downloading golang.org/x/sync v0.20.0
go: downloading golang.org/x/mod v0.35.0
The list of dependencies in /home/runner/work/tailscale/tailscale/src/cmd/tailscaled/depaware.txt is out of date.
--- before
+++ after
@@ -443,6 +443,7 @@
tailscale.com/util/cmpver from tailscale.com/net/dns+
tailscale.com/util/ctxkey from tailscale.com/ipn/ipnlocal+
💣 tailscale.com/util/deephash from tailscale.com/util/syspolicy/setting
+ tailscale.com/util/def from tailscale.com/feature/debugportmapper+
L 💣 tailscale.com/util/dirwalk from tailscale.com/metrics+
tailscale.com/util/dnsname from tailscale.com/appc+
tailscale.com/util/eventbus from tailscale.com/tsd+
exit status 1
There was a problem hiding this comment.
I have done this in ad18daf so this PR gets unstuck.
Signed-off-by: Simon Law <[email protected]>
There was a problem hiding this comment.
All tests pass. Thanks for your first contribution, @ibobgunardi!
Please submit another PR if you want to tackle the default Getenv parsers.
util/def: add def.Bool and def.Duration default parse helpers Replace multiple instances of def.Bool and def.Duration with a new util/def package. Updates tailscale#20018 Co-authored-by: Bobby <[email protected]> Co-authored-by: Simon Law <[email protected]> Signed-off-by: Bobby <[email protected]> Signed-off-by: Simon Law <[email protected]>
Keeps this one small: adds util/def for parse-with-default helpers, then uses it in the routecheck and debugportmapper localapi form parsing paths.
Tests:
Updates #20018