kd/machine: Add supervised client. - #10306
Conversation
| return err | ||
| } | ||
| return f(c) | ||
| case <-timer.C: |
There was a problem hiding this comment.
instead of using another timer what about creating the context with a deadline?
| } | ||
|
|
||
| ctx, cancel := context.WithCancel(context.Background()) | ||
| defer cancel() |
There was a problem hiding this comment.
this context is already cancelled when the function returns
There was a problem hiding this comment.
I guess this is due to unreadable branch - one would expect to handle error not success. How about:
func (s *Supervised) Context() context.Context {
c, err := s.dcf()
if err != nil {
ctx, cancel := context.WithCancel(context.Background())
cancel()
return ctx
}
return c.Context()
}There was a problem hiding this comment.
yes, this is intended to return cancelled context which will prevent any other logic to run (since we don't have a valid client). This type is also going to be extended with cancellation logic so the method will change a little.
|
|
||
| ctx := c.Context() | ||
| if err = f(c); err == ErrDisconnected { | ||
| timer := time.NewTimer(s.timeout) |
5284833 to
3317c8d
Compare
| return "", e | ||
| } | ||
|
|
||
| return |
There was a problem hiding this comment.
nit: formatting, feels to me claustrophobic, wdyt?
func (s *Supervised) CurrentUser() (user string, err error) {
fn := func(c Client) error {
user, err = c.CurrentUser()
return err
}
_, err = s.call(fn)
return
}| select { | ||
| case <-hitC: | ||
| if err == client.ErrDisconnected { | ||
| t.Fatalf("want err != %[1]v; got %[1]v", client.ErrDisconnected) |
There was a problem hiding this comment.
"want err != client.ErrDisconnected" is enough msg, if it fails it's obvious why
(the real reason is that I always need to lookup the doc whether positional arguments are 0- or 1-index thus I try to avoid it if possible)
There was a problem hiding this comment.
Actually that's easy to remember:
t.Fatalf(arg0, arg1, arg2, arg3) // everything always starts from 0.
// arg0 is a formatting string so: %[1]v <=> arg1I will change this anyway.
3317c8d to
8436495
Compare
|
@ppknap i forgot to mention for you that is normally should cover, but there is a problem i think. Im still investigating |
|
@mehmetalisavas no problem, just noticed that and wanted to let you know 👍 |
|
Merging for now. @cihangir If you'd have any comments, they're going to be addressed in a separate PR. |
|
LGTM 👍 |
Supervised client type is meant to handle temporary network issues or cases when underlying client is not set up yet. Eg. when KD started but haven't made connection to remote machine.
How Has This Been Tested?
Unit tests.
Current package coverage: 59.1% of statements
Question: is seems that
klientctlandklienttests haven't been handled bycodecovyet. @mehmetalisavas are these packages going to be scanned bycodeconv?Types of changes