Merge pull request #7291 from lengrongfu/feat_client_defaultnamespace

feature: use client default namespace
This commit is contained in:
Kazuyoshi Kato 2022-09-06 11:54:11 -07:00 committed by GitHub
commit 217aa160cf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 0 deletions

View File

@ -625,6 +625,11 @@ func (c *Client) SnapshotService(snapshotterName string) snapshots.Snapshotter {
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
func (c *Client) TaskService() tasks.TasksClient {
if c.taskService != nil {

View File

@ -26,6 +26,7 @@ import (
"github.com/containerd/containerd/content"
"github.com/containerd/containerd/errdefs"
"github.com/containerd/containerd/images"
"github.com/containerd/containerd/namespaces"
"github.com/containerd/containerd/oci"
"github.com/containerd/containerd/protobuf"
"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
func WithNewSpec(opts ...oci.SpecOpts) NewContainerOpts {
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...)
if err != nil {
return err