deployment API cleanup

The API was a bit confusing with code mixing the usage of Deployment and
DeploymentState.

This change marks a clear separation:

- Client is the only piece of code manipulating *Deployment
- CLI commands can manipulate DeploymentState objects and pass them to
  Client

Signed-off-by: Andrea Luzzardi <aluzzardi@gmail.com>
This commit is contained in:
Andrea Luzzardi
2021-04-02 14:45:11 -07:00
parent 59d934fbf0
commit 33d5add54b
7 changed files with 18 additions and 68 deletions

View File

@@ -64,10 +64,15 @@ func NewClient(ctx context.Context, host string) (*Client, error) {
type ClientDoFunc func(context.Context, *Deployment, Solver) error
// FIXME: return completed *Route, instead of *compiler.Value
func (c *Client) Do(ctx context.Context, deployment *Deployment, fn ClientDoFunc) (*compiler.Value, error) {
func (c *Client) Do(ctx context.Context, state *DeploymentState, fn ClientDoFunc) (*compiler.Value, error) {
lg := log.Ctx(ctx)
eg, gctx := errgroup.WithContext(ctx)
deployment, err := NewDeployment(state)
if err != nil {
return nil, err
}
// Spawn print function
events := make(chan *bk.SolveStatus)
eg.Go(func() error {
@@ -85,10 +90,7 @@ func (c *Client) Do(ctx context.Context, deployment *Deployment, fn ClientDoFunc
})
// Spawn output retriever
var (
out *compiler.Value
err error
)
var out *compiler.Value
eg.Go(func() error {
defer outr.Close()
out, err = c.outputfn(gctx, outr)