Skip to content
This repository was archived by the owner on Aug 15, 2022. It is now read-only.

kd/machine: Add supervised client. - #10306

Merged
rjeczalik merged 8 commits into
masterfrom
machine_mount_client_supervised
Jan 19, 2017
Merged

kd/machine: Add supervised client.#10306
rjeczalik merged 8 commits into
masterfrom
machine_mount_client_supervised

Conversation

@ppknap

@ppknap ppknap commented Jan 12, 2017

Copy link
Copy Markdown
Contributor

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 klientctl and klient tests haven't been handled by codecov yet. @mehmetalisavas are these packages going to be scanned by codeconv?

Types of changes

  • New feature (non-breaking change which adds functionality)

return err
}
return f(c)
case <-timer.C:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instead of using another timer what about creating the context with a deadline?

}

ctx, cancel := context.WithCancel(context.Background())
defer cancel()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this context is already cancelled when the function returns

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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()
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

defer timer.Stop()

@ppknap
ppknap force-pushed the machine_mount_client_supervised branch from 5284833 to 3317c8d Compare January 14, 2017 00:27
return "", e
}

return

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"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)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 <=> arg1

I will change this anyway.

@ppknap
ppknap force-pushed the machine_mount_client_supervised branch from 3317c8d to 8436495 Compare January 16, 2017 16:41
@mehmetalisavas

Copy link
Copy Markdown
Contributor

@ppknap i forgot to mention for you that is normally should cover, but there is a problem i think. Im still investigating

@ppknap

ppknap commented Jan 16, 2017

Copy link
Copy Markdown
Contributor Author

@mehmetalisavas no problem, just noticed that and wanted to let you know 👍

@rjeczalik
rjeczalik merged commit 2443f1c into master Jan 19, 2017
@rjeczalik
rjeczalik deleted the machine_mount_client_supervised branch January 19, 2017 01:36
@rjeczalik

Copy link
Copy Markdown
Contributor

Merging for now.

@cihangir If you'd have any comments, they're going to be addressed in a separate PR.

@cihangir

Copy link
Copy Markdown
Contributor

LGTM 👍

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants