feature: use client default namespace
Signed-off-by: rongfu.leng <1275177125@qq.com>
This commit is contained in:
		| @@ -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 | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 lengrongfu
					lengrongfu