From b2606b91f2e6613237a75fa5955ee7e95ce91b82 Mon Sep 17 00:00:00 2001 From: Djordje Lukic Date: Thu, 30 Apr 2020 11:06:04 +0200 Subject: [PATCH] Remove useless client grpc stuff --- cli/cmd/example.go | 40 ++-------------------------------------- cli/cmd/ps.go | 10 +++------- client/client.go | 10 ---------- 3 files changed, 5 insertions(+), 55 deletions(-) diff --git a/cli/cmd/example.go b/cli/cmd/example.go index 221aa4ca0..fa2b01dc4 100644 --- a/cli/cmd/example.go +++ b/cli/cmd/example.go @@ -31,7 +31,6 @@ import ( "context" "encoding/json" "os" - "os/exec" "github.com/docker/api/client" "github.com/golang/protobuf/ptypes/empty" @@ -45,16 +44,12 @@ var ExampleCommand = cobra.Command{ RunE: func(cmd *cobra.Command, args []string) error { ctx := cmd.Context() - // get our current context - ctx = current(ctx) - - client, err := connect(ctx) + c, err := client.New(ctx) if err != nil { return errors.Wrap(err, "cannot connect to backend") } - defer client.Close() - info, err := client.BackendInformation(ctx, &empty.Empty{}) + info, err := c.BackendInformation(ctx, &empty.Empty{}) if err != nil { return errors.Wrap(err, "fetch backend information") } @@ -64,37 +59,6 @@ var ExampleCommand = cobra.Command{ }, } -// mock information for getting context -// factor out this into a context store package -func current(ctx context.Context) context.Context { - // test backend address - return context.WithValue(ctx, backendAddressKey{}, "/tmp/backend.sock") -} - -func connect(ctx context.Context) (*client.Client, error) { - address, err := BackendAddress(ctx) - if err != nil { - return nil, errors.Wrap(err, "no backend address") - } - - c, err := client.New(ctx) - if err != nil { - if err != context.DeadlineExceeded { - return nil, errors.Wrap(err, "connect to backend") - } - // the backend is not running so start it - cmd := exec.Command("backend-example", "--address", address) - go cmd.Wait() - - if err := cmd.Start(); err != nil { - return nil, errors.Wrap(err, "start backend") - } - cl, e := client.New(ctx) - return cl, e - } - return c, nil -} - type backendAddressKey struct{} func BackendAddress(ctx context.Context) (string, error) { diff --git a/cli/cmd/ps.go b/cli/cmd/ps.go index 2f980a12d..dc8a74691 100644 --- a/cli/cmd/ps.go +++ b/cli/cmd/ps.go @@ -5,7 +5,7 @@ import ( "os" "text/tabwriter" - client2 "github.com/docker/api/client" + "github.com/docker/api/client" "github.com/pkg/errors" "github.com/spf13/cobra" ) @@ -16,16 +16,12 @@ var PsCommand = cobra.Command{ RunE: func(cmd *cobra.Command, args []string) error { ctx := cmd.Context() - // get our current context - ctx = current(ctx) - - client, err := client2.New(ctx) + c, err := client.New(ctx) if err != nil { return errors.Wrap(err, "cannot connect to backend") } - defer client.Close() - containers, err := client.ContainerService(ctx).List(ctx) + containers, err := c.ContainerService(ctx).List(ctx) if err != nil { return errors.Wrap(err, "fetch containers") } diff --git a/client/client.go b/client/client.go index 145cd78dd..1d4556834 100644 --- a/client/client.go +++ b/client/client.go @@ -31,8 +31,6 @@ import ( "context" "errors" - "google.golang.org/grpc" - "github.com/docker/api/backend" v1 "github.com/docker/api/backend/v1" "github.com/docker/api/containers" @@ -66,7 +64,6 @@ func New(ctx context.Context) (*Client, error) { } type Client struct { - conn *grpc.ClientConn v1.BackendClient backendType string cc containers.ContainerService @@ -75,10 +72,3 @@ type Client struct { func (c *Client) ContainerService(ctx context.Context) containers.ContainerService { return c.cc } - -func (c *Client) Close() error { - if c.conn != nil { - return c.conn.Close() - } - return nil -}