Move ttrpc client to pkg/ttrpcutil
Signed-off-by: Maksym Pavlenko <makpav@amazon.com>
This commit is contained in:
parent
7b06c9a1ce
commit
7f79fbb245
@ -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()
|
||||
|
@ -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()
|
||||
|
@ -16,7 +16,7 @@
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package containerd
|
||||
package ttrpcutil
|
||||
|
||||
import (
|
||||
"net"
|
@ -16,7 +16,7 @@
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package containerd
|
||||
package ttrpcutil
|
||||
|
||||
import (
|
||||
"net"
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user