diff --git a/client_ttrpc_test.go b/client_ttrpc_test.go index ee75553dc..b12da5f27 100644 --- a/client_ttrpc_test.go +++ b/client_ttrpc_test.go @@ -23,13 +23,14 @@ import ( v1 "github.com/containerd/containerd/api/services/ttrpc/events/v1" "github.com/containerd/containerd/namespaces" + "github.com/containerd/containerd/pkg/ttrpcutil" "github.com/containerd/ttrpc" "github.com/gogo/protobuf/types" "gotest.tools/assert" ) func TestClientTTRPC_New(t *testing.T) { - client, err := NewTTRPC(address + ".ttrpc") + client, err := ttrpcutil.NewClient(address + ".ttrpc") assert.NilError(t, err) err = client.Close() @@ -37,7 +38,7 @@ func TestClientTTRPC_New(t *testing.T) { } func TestClientTTRPC_Reconnect(t *testing.T) { - client, err := NewTTRPC(address + ".ttrpc") + client, err := ttrpcutil.NewClient(address + ".ttrpc") assert.NilError(t, err) err = client.Reconnect() @@ -59,7 +60,7 @@ func TestClientTTRPC_Reconnect(t *testing.T) { } func TestClientTTRPC_Close(t *testing.T) { - client, err := NewTTRPC(address + ".ttrpc") + client, err := ttrpcutil.NewClient(address + ".ttrpc") assert.NilError(t, err) err = client.Close() diff --git a/client_ttrpc.go b/pkg/ttrpcutil/client.go similarity index 78% rename from client_ttrpc.go rename to pkg/ttrpcutil/client.go index 1dc249065..ba3d51d51 100644 --- a/client_ttrpc.go +++ b/pkg/ttrpcutil/client.go @@ -14,7 +14,7 @@ limitations under the License. */ -package containerd +package ttrpcutil import ( "sync" @@ -29,16 +29,16 @@ const ttrpcDialTimeout = 5 * time.Second type ttrpcConnector func() (*ttrpc.Client, error) -// ClientTTRPC is the client to interact with TTRPC part of containerd server (plugins, events) -type ClientTTRPC struct { +// Client is the client to interact with TTRPC part of containerd server (plugins, events) +type Client struct { mu sync.Mutex connector ttrpcConnector client *ttrpc.Client closed bool } -// NewTTRPC returns a new containerd TTRPC client that is connected to the containerd instance provided by address -func NewTTRPC(address string, opts ...ttrpc.ClientOpts) (*ClientTTRPC, error) { +// NewClient returns a new containerd TTRPC client that is connected to the containerd instance provided by address +func NewClient(address string, opts ...ttrpc.ClientOpts) (*Client, error) { connector := func() (*ttrpc.Client, error) { conn, err := ttrpcDial(address, ttrpcDialTimeout) if err != nil { @@ -54,14 +54,14 @@ func NewTTRPC(address string, opts ...ttrpc.ClientOpts) (*ClientTTRPC, error) { return nil, err } - return &ClientTTRPC{ + return &Client{ connector: connector, client: client, }, nil } // Reconnect re-establishes the TTRPC connection to the containerd daemon -func (c *ClientTTRPC) Reconnect() error { +func (c *Client) Reconnect() error { c.mu.Lock() defer c.mu.Unlock() @@ -83,12 +83,12 @@ func (c *ClientTTRPC) Reconnect() error { } // EventsService creates an EventsService client -func (c *ClientTTRPC) EventsService() v1.EventsService { +func (c *Client) EventsService() v1.EventsService { return v1.NewEventsClient(c.Client()) } // Client returns the underlying TTRPC client object -func (c *ClientTTRPC) Client() *ttrpc.Client { +func (c *Client) Client() *ttrpc.Client { c.mu.Lock() defer c.mu.Unlock() @@ -96,7 +96,7 @@ func (c *ClientTTRPC) Client() *ttrpc.Client { } // Close closes the clients TTRPC connection to containerd -func (c *ClientTTRPC) Close() error { +func (c *Client) Close() error { c.mu.Lock() defer c.mu.Unlock() diff --git a/client_ttrpc_unix.go b/pkg/ttrpcutil/client_unix.go similarity index 97% rename from client_ttrpc_unix.go rename to pkg/ttrpcutil/client_unix.go index b3f0ba3b4..16fb64954 100644 --- a/client_ttrpc_unix.go +++ b/pkg/ttrpcutil/client_unix.go @@ -16,7 +16,7 @@ limitations under the License. */ -package containerd +package ttrpcutil import ( "net" diff --git a/client_ttrpc_windows.go b/pkg/ttrpcutil/client_windows.go similarity index 98% rename from client_ttrpc_windows.go rename to pkg/ttrpcutil/client_windows.go index b6ef39ba3..1fc4fc164 100644 --- a/client_ttrpc_windows.go +++ b/pkg/ttrpcutil/client_windows.go @@ -16,7 +16,7 @@ limitations under the License. */ -package containerd +package ttrpcutil import ( "net" diff --git a/runtime/v2/shim/publisher.go b/runtime/v2/shim/publisher.go index 4c3519388..d1f2a0c28 100644 --- a/runtime/v2/shim/publisher.go +++ b/runtime/v2/shim/publisher.go @@ -21,14 +21,13 @@ import ( "sync" "time" - "github.com/containerd/ttrpc" - "github.com/containerd/typeurl" - "github.com/sirupsen/logrus" - - "github.com/containerd/containerd" v1 "github.com/containerd/containerd/api/services/ttrpc/events/v1" "github.com/containerd/containerd/events" "github.com/containerd/containerd/namespaces" + "github.com/containerd/containerd/pkg/ttrpcutil" + "github.com/containerd/ttrpc" + "github.com/containerd/typeurl" + "github.com/sirupsen/logrus" ) const ( @@ -43,7 +42,7 @@ type item struct { } func newPublisher(address string) (*remoteEventsPublisher, error) { - client, err := containerd.NewTTRPC(address) + client, err := ttrpcutil.NewClient(address) if err != nil { return nil, err } @@ -59,7 +58,7 @@ func newPublisher(address string) (*remoteEventsPublisher, error) { } type remoteEventsPublisher struct { - client *containerd.ClientTTRPC + client *ttrpcutil.Client closed chan struct{} closer sync.Once requeue chan *item