diff --git a/client/client.go b/client/client.go index 0c2eb1b19..714c57c25 100644 --- a/client/client.go +++ b/client/client.go @@ -82,7 +82,7 @@ func init() { // New returns a new containerd client that is connected to the containerd // instance provided by address -func New(address string, opts ...ClientOpt) (*Client, error) { +func New(address string, opts ...Opt) (*Client, error) { var copts clientOpts for _, o := range opts { if err := o(&copts); err != nil { @@ -174,7 +174,7 @@ func New(address string, opts ...ClientOpt) (*Client, error) { // NewWithConn returns a new containerd client that is connected to the containerd // instance provided by the connection -func NewWithConn(conn *grpc.ClientConn, opts ...ClientOpt) (*Client, error) { +func NewWithConn(conn *grpc.ClientConn, opts ...Opt) (*Client, error) { var copts clientOpts for _, o := range opts { if err := o(&copts); err != nil { diff --git a/client/client_opts.go b/client/client_opts.go index 9520510fe..ffc49a43c 100644 --- a/client/client_opts.go +++ b/client/client_opts.go @@ -38,14 +38,14 @@ type clientOpts struct { timeout time.Duration } -// ClientOpt allows callers to set options on the containerd client -type ClientOpt func(c *clientOpts) error +// Opt allows callers to set options on the containerd client +type Opt func(c *clientOpts) error // WithDefaultNamespace sets the default namespace on the client // // Any operation that does not have a namespace set on the context will // be provided the default namespace -func WithDefaultNamespace(ns string) ClientOpt { +func WithDefaultNamespace(ns string) Opt { return func(c *clientOpts) error { c.defaultns = ns return nil @@ -53,7 +53,7 @@ func WithDefaultNamespace(ns string) ClientOpt { } // WithDefaultRuntime sets the default runtime on the client -func WithDefaultRuntime(rt string) ClientOpt { +func WithDefaultRuntime(rt string) Opt { return func(c *clientOpts) error { c.defaultRuntime = rt return nil @@ -61,7 +61,7 @@ func WithDefaultRuntime(rt string) ClientOpt { } // WithDefaultPlatform sets the default platform matcher on the client -func WithDefaultPlatform(platform platforms.MatchComparer) ClientOpt { +func WithDefaultPlatform(platform platforms.MatchComparer) Opt { return func(c *clientOpts) error { c.defaultPlatform = platform return nil @@ -69,7 +69,7 @@ func WithDefaultPlatform(platform platforms.MatchComparer) ClientOpt { } // WithDialOpts allows grpc.DialOptions to be set on the connection -func WithDialOpts(opts []grpc.DialOption) ClientOpt { +func WithDialOpts(opts []grpc.DialOption) Opt { return func(c *clientOpts) error { c.dialOptions = opts return nil @@ -77,7 +77,7 @@ func WithDialOpts(opts []grpc.DialOption) ClientOpt { } // WithCallOpts allows grpc.CallOptions to be set on the connection -func WithCallOpts(opts []grpc.CallOption) ClientOpt { +func WithCallOpts(opts []grpc.CallOption) Opt { return func(c *clientOpts) error { c.callOptions = opts return nil @@ -85,7 +85,7 @@ func WithCallOpts(opts []grpc.CallOption) ClientOpt { } // WithServices sets services used by the client. -func WithServices(opts ...ServicesOpt) ClientOpt { +func WithServices(opts ...ServicesOpt) Opt { return func(c *clientOpts) error { c.services = &services{} for _, o := range opts { @@ -96,7 +96,7 @@ func WithServices(opts ...ServicesOpt) ClientOpt { } // WithTimeout sets the connection timeout for the client -func WithTimeout(d time.Duration) ClientOpt { +func WithTimeout(d time.Duration) Opt { return func(c *clientOpts) error { c.timeout = d return nil diff --git a/client/services.go b/client/services.go index 87cd46afd..392d3d720 100644 --- a/client/services.go +++ b/client/services.go @@ -183,7 +183,7 @@ func WithSandboxStore(client sandbox.Store) ServicesOpt { // WithInMemoryServices is suitable for cases when there is need to use containerd's client from // another (in-memory) containerd plugin (such as CRI). -func WithInMemoryServices(ic *plugin.InitContext) ClientOpt { +func WithInMemoryServices(ic *plugin.InitContext) Opt { return func(c *clientOpts) error { var opts []ServicesOpt for t, fn := range map[plugin.Type]func(interface{}) ServicesOpt{ diff --git a/cmd/ctr/commands/client.go b/cmd/ctr/commands/client.go index f52f2de2a..0caa9a77b 100644 --- a/cmd/ctr/commands/client.go +++ b/cmd/ctr/commands/client.go @@ -54,7 +54,7 @@ func AppContext(context *cli.Context) (gocontext.Context, gocontext.CancelFunc) } // NewClient returns a new containerd client -func NewClient(context *cli.Context, opts ...containerd.ClientOpt) (*containerd.Client, gocontext.Context, gocontext.CancelFunc, error) { +func NewClient(context *cli.Context, opts ...containerd.Opt) (*containerd.Client, gocontext.Context, gocontext.CancelFunc, error) { timeoutOpt := containerd.WithTimeout(context.GlobalDuration("connect-timeout")) opts = append(opts, timeoutOpt) client, err := containerd.New(context.GlobalString("address"), opts...) diff --git a/integration/client/client_test.go b/integration/client/client_test.go index e552970e7..690f18c4c 100644 --- a/integration/client/client_test.go +++ b/integration/client/client_test.go @@ -189,7 +189,7 @@ func TestMain(m *testing.M) { os.Exit(status) } -func newClient(t testing.TB, address string, opts ...ClientOpt) (*Client, error) { +func newClient(t testing.TB, address string, opts ...Opt) (*Client, error) { if testing.Short() { t.Skip() }