Merge pull request #7291 from lengrongfu/feat_client_defaultnamespace
feature: use client default namespace
This commit is contained in:
commit
217aa160cf
@ -625,6 +625,11 @@ func (c *Client) SnapshotService(snapshotterName string) snapshots.Snapshotter {
|
|||||||
return snproxy.NewSnapshotter(snapshotsapi.NewSnapshotsClient(c.conn), snapshotterName)
|
return snproxy.NewSnapshotter(snapshotsapi.NewSnapshotsClient(c.conn), snapshotterName)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// DefaultNamespace return the default namespace
|
||||||
|
func (c *Client) DefaultNamespace() string {
|
||||||
|
return c.defaultns
|
||||||
|
}
|
||||||
|
|
||||||
// TaskService returns the underlying TasksClient
|
// TaskService returns the underlying TasksClient
|
||||||
func (c *Client) TaskService() tasks.TasksClient {
|
func (c *Client) TaskService() tasks.TasksClient {
|
||||||
if c.taskService != nil {
|
if c.taskService != nil {
|
||||||
|
@ -26,6 +26,7 @@ import (
|
|||||||
"github.com/containerd/containerd/content"
|
"github.com/containerd/containerd/content"
|
||||||
"github.com/containerd/containerd/errdefs"
|
"github.com/containerd/containerd/errdefs"
|
||||||
"github.com/containerd/containerd/images"
|
"github.com/containerd/containerd/images"
|
||||||
|
"github.com/containerd/containerd/namespaces"
|
||||||
"github.com/containerd/containerd/oci"
|
"github.com/containerd/containerd/oci"
|
||||||
"github.com/containerd/containerd/protobuf"
|
"github.com/containerd/containerd/protobuf"
|
||||||
"github.com/containerd/containerd/snapshots"
|
"github.com/containerd/containerd/snapshots"
|
||||||
@ -307,6 +308,9 @@ func WithContainerExtension(name string, extension interface{}) NewContainerOpts
|
|||||||
// WithNewSpec generates a new spec for a new container
|
// WithNewSpec generates a new spec for a new container
|
||||||
func WithNewSpec(opts ...oci.SpecOpts) NewContainerOpts {
|
func WithNewSpec(opts ...oci.SpecOpts) NewContainerOpts {
|
||||||
return func(ctx context.Context, client *Client, c *containers.Container) error {
|
return func(ctx context.Context, client *Client, c *containers.Container) error {
|
||||||
|
if _, ok := namespaces.Namespace(ctx); !ok {
|
||||||
|
ctx = namespaces.WithNamespace(ctx, client.DefaultNamespace())
|
||||||
|
}
|
||||||
s, err := oci.GenerateSpec(ctx, client, c, opts...)
|
s, err := oci.GenerateSpec(ctx, client, c, opts...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
Loading…
Reference in New Issue
Block a user