Add WithNamespace for client
Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
This commit is contained in:
parent
bf9ad0c57f
commit
01c4c86414
26
client.go
26
client.go
@ -42,6 +42,13 @@ func init() {
|
|||||||
|
|
||||||
type NewClientOpts func(c *Client) error
|
type NewClientOpts func(c *Client) error
|
||||||
|
|
||||||
|
func WithNamespace(namespace string) NewClientOpts {
|
||||||
|
return func(c *Client) error {
|
||||||
|
c.Namespace = namespace
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// 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 ...NewClientOpts) (*Client, error) {
|
func New(address string, opts ...NewClientOpts) (*Client, error) {
|
||||||
@ -72,6 +79,7 @@ type Client struct {
|
|||||||
conn *grpc.ClientConn
|
conn *grpc.ClientConn
|
||||||
|
|
||||||
Runtime string
|
Runtime string
|
||||||
|
Namespace string
|
||||||
}
|
}
|
||||||
|
|
||||||
// Containers returns all containers created in containerd
|
// Containers returns all containers created in containerd
|
||||||
@ -89,16 +97,16 @@ func (c *Client) Containers(ctx context.Context) ([]*Container, error) {
|
|||||||
|
|
||||||
type NewContainerOpts func(ctx context.Context, client *Client, c *containers.Container) error
|
type NewContainerOpts func(ctx context.Context, client *Client, c *containers.Container) error
|
||||||
|
|
||||||
// NewContainerWithLables adds the provided labels to the container
|
// WithContainerLables adds the provided labels to the container
|
||||||
func NewContainerWithLables(labels map[string]string) NewContainerOpts {
|
func WithContainerLables(labels map[string]string) NewContainerOpts {
|
||||||
return func(_ context.Context, _ *Client, c *containers.Container) error {
|
return func(_ context.Context, _ *Client, c *containers.Container) error {
|
||||||
c.Labels = labels
|
c.Labels = labels
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewContainerWithExistingRootFS uses an existing root filesystem for the container
|
// WithExistingRootFS uses an existing root filesystem for the container
|
||||||
func NewContainerWithExistingRootFS(id string) NewContainerOpts {
|
func WithExistingRootFS(id string) NewContainerOpts {
|
||||||
return func(ctx context.Context, client *Client, c *containers.Container) error {
|
return func(ctx context.Context, client *Client, c *containers.Container) error {
|
||||||
// check that the snapshot exists, if not, fail on creation
|
// check that the snapshot exists, if not, fail on creation
|
||||||
if _, err := client.snapshotter().Mounts(ctx, id); err != nil {
|
if _, err := client.snapshotter().Mounts(ctx, id); err != nil {
|
||||||
@ -109,9 +117,9 @@ func NewContainerWithExistingRootFS(id string) NewContainerOpts {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewContainerWithNewRootFS allocates a new snapshot to be used by the container as the
|
// WithNewRootFS allocates a new snapshot to be used by the container as the
|
||||||
// root filesystem in read-write mode
|
// root filesystem in read-write mode
|
||||||
func NewContainerWithNewRootFS(id string, image *Image) NewContainerOpts {
|
func WithNewRootFS(id string, image *Image) NewContainerOpts {
|
||||||
return func(ctx context.Context, client *Client, c *containers.Container) error {
|
return func(ctx context.Context, client *Client, c *containers.Container) error {
|
||||||
diffIDs, err := image.i.RootFS(ctx, client.content())
|
diffIDs, err := image.i.RootFS(ctx, client.content())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -125,9 +133,9 @@ func NewContainerWithNewRootFS(id string, image *Image) NewContainerOpts {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewContainerWithNewReadonlyRootFS allocates a new snapshot to be used by the container as the
|
// WithNewReadonlyRootFS allocates a new snapshot to be used by the container as the
|
||||||
// root filesystem in read-only mode
|
// root filesystem in read-only mode
|
||||||
func NewContainerWithNewReadonlyRootFS(id string, image *Image) NewContainerOpts {
|
func WithNewReadonlyRootFS(id string, image *Image) NewContainerOpts {
|
||||||
return func(ctx context.Context, client *Client, c *containers.Container) error {
|
return func(ctx context.Context, client *Client, c *containers.Container) error {
|
||||||
diffIDs, err := image.i.RootFS(ctx, client.content())
|
diffIDs, err := image.i.RootFS(ctx, client.content())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -141,7 +149,7 @@ func NewContainerWithNewReadonlyRootFS(id string, image *Image) NewContainerOpts
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewContainerWithRuntime(name string) NewContainerOpts {
|
func WithRuntime(name string) NewContainerOpts {
|
||||||
return func(ctx context.Context, client *Client, c *containers.Container) error {
|
return func(ctx context.Context, client *Client, c *containers.Container) error {
|
||||||
c.Runtime = name
|
c.Runtime = name
|
||||||
return nil
|
return nil
|
||||||
|
Loading…
Reference in New Issue
Block a user