-
Notifications
You must be signed in to change notification settings - Fork 247
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
Change nfd-worker to use Ticker instead of After. #1050
Conversation
✅ Deploy Preview for kubernetes-sigs-nfd ready!
To edit notification comments on pull requests, go to your Netlify site settings. |
|
Welcome @VillePihlava! |
Hi @VillePihlava. Thanks for your PR. I'm waiting for a kubernetes-sigs member to verify that this patch is reasonable to test. If it is, they should reply with Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. 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. |
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.
Patch looks good, thanks for this @VillePihlava !!
Just a small comment
/ok-to-test
The rest I'll leave it to
/assign @marquiz
pkg/nfd-worker/nfd-worker.go
Outdated
func (w *nfdWorker) createTicker() *time.Ticker { | ||
if w.config.Core.SleepInterval.Duration > 0 { | ||
return time.NewTicker(w.config.Core.SleepInterval.Duration) | ||
} else { |
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 Else is not needed
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.
The else is now removed
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.
TO me this looks better like a https://gobyexample.com/switch since the func doesn't have a return
a Switch will be more elegant here
/assign @marquiz |
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.
Looks good. Can you perhaps squash the commits?
pkg/nfd-worker/nfd-worker.go
Outdated
t := time.NewTicker(time.Hour) | ||
t.Stop() | ||
return t |
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 you could simplify this a bit with just
t := time.NewTicker(time.Hour) | |
t.Stop() | |
return t | |
return &time.Ticker{} |
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'm not entirely sure what happens when calling Stop()
with an uninitialized ticker, so I changed the implementation a little to not call it on an uninitialized one and incorporated this change in a sense
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.
Mm, that's a fair point. Even if it works now it's not clearly specified (from what I can tell) if calling Stop() on uninitialized Ticker is legit which might cause a breakage later.
7450a0b
to
6e473e8
Compare
Done |
pkg/nfd-worker/nfd-worker.go
Outdated
func (infiniteTicker *infiniteTicker) startTicker(w *nfdWorker) { | ||
// If the sleep interval is not a positive number, the ticker will act as if it was set to an infinite duration by not ticking. | ||
if w.config.Core.SleepInterval.Duration > 0 { | ||
infiniteTicker.T = time.NewTicker(w.config.Core.SleepInterval.Duration) | ||
infiniteTicker.initialized = true | ||
} | ||
} |
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.
Thanks for the update @VillePihlava. Quite a bike-shedding on this PR, but somehow this latest version feels just a tad too complicated (in terms of lines-of-code) for such a simple thing 😇
How about using struct composition to wrap the Ticker type, with something like
type infiniteTicker struct {
*time.Ticker
}
func (i *infiniteTicker) Reset(d time.Duration) {
if d > 0 {
i.Ticker.Reset(d)
} else {
i.Ticker.Stop()
}
}
...then you'd initialize with smth like (you could specify a dedicated create function if this looks too bad):
labelTrigger := infiniteTicker{Ticker: time.NewTicker(1)} // just any non-zero duration here, we'll do the actual configuration below
labelTrigger.Reset(w.config.Core.SleepInterval.Duration)
use the channel directly:
case <-labelTrigger.C:
and simply use reset for re-configuring (instead of creating a new Ticker instance)
labelTrigger.Reset(w.config.Core.SleepInterval.Duration)
WDYT? Haven't tested but I think that should work out
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.
Yeah this makes sense, I made these changes now. Also tested manually that making changes to the sleepinterval in the config worked
6e473e8
to
803c7e6
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.
Thanks @VillePihlava! Looks good to me 🤓
/assign @ArangoGutierrez |
pkg/nfd-worker/nfd-worker.go
Outdated
func (w *nfdWorker) createTicker() *time.Ticker { | ||
if w.config.Core.SleepInterval.Duration > 0 { | ||
return time.NewTicker(w.config.Core.SleepInterval.Duration) | ||
} else { |
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.
TO me this looks better like a https://gobyexample.com/switch since the func doesn't have a return
a Switch will be more elegant here
i.Ticker.Reset(d) | ||
} else { | ||
// If the sleep interval is not a positive number the ticker will act as if it was set to an infinite duration by not ticking. | ||
i.Ticker.Stop() |
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 format this comment to fit in 80 columns, see how other comments when too long they are several lines. makes it easier to read
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 changed the if-else to a switch and made the comment fit into 80 columns
803c7e6
to
2101cb2
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.
Thanks for the effort @VillePihlava !
/lgtm
LGTM label has been added. Git tree hash: 922bfb8952a57ef5029c26b9e548a31ed048895e
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: ArangoGutierrez, marquiz, VillePihlava 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 |
This pull request changes the nfd-worker to use
time.Ticker
instead oftime.After
to implementcore.sleepInterval
. An infinite interval is represented by stopping the Ticker.Issue: #899