Rename opt to avoid stutter
Signed-off-by: Derek McGowan <derek@mcg.dev>
This commit is contained in:
parent
261e01c2ac
commit
b85df264ef
@ -82,7 +82,7 @@ func init() {
|
|||||||
|
|
||||||
// New returns a new containerd client that is connected to the containerd
|
// New returns a new containerd client that is connected to the containerd
|
||||||
// instance provided by address
|
// instance provided by address
|
||||||
func New(address string, opts ...ClientOpt) (*Client, error) {
|
func New(address string, opts ...Opt) (*Client, error) {
|
||||||
var copts clientOpts
|
var copts clientOpts
|
||||||
for _, o := range opts {
|
for _, o := range opts {
|
||||||
if err := o(&copts); err != nil {
|
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
|
// NewWithConn returns a new containerd client that is connected to the containerd
|
||||||
// instance provided by the connection
|
// 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
|
var copts clientOpts
|
||||||
for _, o := range opts {
|
for _, o := range opts {
|
||||||
if err := o(&copts); err != nil {
|
if err := o(&copts); err != nil {
|
||||||
|
@ -38,14 +38,14 @@ type clientOpts struct {
|
|||||||
timeout time.Duration
|
timeout time.Duration
|
||||||
}
|
}
|
||||||
|
|
||||||
// ClientOpt allows callers to set options on the containerd client
|
// Opt allows callers to set options on the containerd client
|
||||||
type ClientOpt func(c *clientOpts) error
|
type Opt func(c *clientOpts) error
|
||||||
|
|
||||||
// WithDefaultNamespace sets the default namespace on the client
|
// WithDefaultNamespace sets the default namespace on the client
|
||||||
//
|
//
|
||||||
// Any operation that does not have a namespace set on the context will
|
// Any operation that does not have a namespace set on the context will
|
||||||
// be provided the default namespace
|
// be provided the default namespace
|
||||||
func WithDefaultNamespace(ns string) ClientOpt {
|
func WithDefaultNamespace(ns string) Opt {
|
||||||
return func(c *clientOpts) error {
|
return func(c *clientOpts) error {
|
||||||
c.defaultns = ns
|
c.defaultns = ns
|
||||||
return nil
|
return nil
|
||||||
@ -53,7 +53,7 @@ func WithDefaultNamespace(ns string) ClientOpt {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// WithDefaultRuntime sets the default runtime on the client
|
// WithDefaultRuntime sets the default runtime on the client
|
||||||
func WithDefaultRuntime(rt string) ClientOpt {
|
func WithDefaultRuntime(rt string) Opt {
|
||||||
return func(c *clientOpts) error {
|
return func(c *clientOpts) error {
|
||||||
c.defaultRuntime = rt
|
c.defaultRuntime = rt
|
||||||
return nil
|
return nil
|
||||||
@ -61,7 +61,7 @@ func WithDefaultRuntime(rt string) ClientOpt {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// WithDefaultPlatform sets the default platform matcher on the client
|
// 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 {
|
return func(c *clientOpts) error {
|
||||||
c.defaultPlatform = platform
|
c.defaultPlatform = platform
|
||||||
return nil
|
return nil
|
||||||
@ -69,7 +69,7 @@ func WithDefaultPlatform(platform platforms.MatchComparer) ClientOpt {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// WithDialOpts allows grpc.DialOptions to be set on the connection
|
// 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 {
|
return func(c *clientOpts) error {
|
||||||
c.dialOptions = opts
|
c.dialOptions = opts
|
||||||
return nil
|
return nil
|
||||||
@ -77,7 +77,7 @@ func WithDialOpts(opts []grpc.DialOption) ClientOpt {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// WithCallOpts allows grpc.CallOptions to be set on the connection
|
// 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 {
|
return func(c *clientOpts) error {
|
||||||
c.callOptions = opts
|
c.callOptions = opts
|
||||||
return nil
|
return nil
|
||||||
@ -85,7 +85,7 @@ func WithCallOpts(opts []grpc.CallOption) ClientOpt {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// WithServices sets services used by the client.
|
// WithServices sets services used by the client.
|
||||||
func WithServices(opts ...ServicesOpt) ClientOpt {
|
func WithServices(opts ...ServicesOpt) Opt {
|
||||||
return func(c *clientOpts) error {
|
return func(c *clientOpts) error {
|
||||||
c.services = &services{}
|
c.services = &services{}
|
||||||
for _, o := range opts {
|
for _, o := range opts {
|
||||||
@ -96,7 +96,7 @@ func WithServices(opts ...ServicesOpt) ClientOpt {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// WithTimeout sets the connection timeout for the client
|
// 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 {
|
return func(c *clientOpts) error {
|
||||||
c.timeout = d
|
c.timeout = d
|
||||||
return nil
|
return nil
|
||||||
|
@ -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
|
// WithInMemoryServices is suitable for cases when there is need to use containerd's client from
|
||||||
// another (in-memory) containerd plugin (such as CRI).
|
// 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 {
|
return func(c *clientOpts) error {
|
||||||
var opts []ServicesOpt
|
var opts []ServicesOpt
|
||||||
for t, fn := range map[plugin.Type]func(interface{}) ServicesOpt{
|
for t, fn := range map[plugin.Type]func(interface{}) ServicesOpt{
|
||||||
|
@ -54,7 +54,7 @@ func AppContext(context *cli.Context) (gocontext.Context, gocontext.CancelFunc)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// NewClient returns a new containerd client
|
// 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"))
|
timeoutOpt := containerd.WithTimeout(context.GlobalDuration("connect-timeout"))
|
||||||
opts = append(opts, timeoutOpt)
|
opts = append(opts, timeoutOpt)
|
||||||
client, err := containerd.New(context.GlobalString("address"), opts...)
|
client, err := containerd.New(context.GlobalString("address"), opts...)
|
||||||
|
@ -189,7 +189,7 @@ func TestMain(m *testing.M) {
|
|||||||
os.Exit(status)
|
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() {
|
if testing.Short() {
|
||||||
t.Skip()
|
t.Skip()
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user