feature: use client default namespace

Signed-off-by: rongfu.leng <1275177125@qq.com>
This commit is contained in:
lengrongfu
2022-08-15 22:40:47 +08:00
committed by rongfu.leng
parent 6699403403
commit 5e57d463df
2 changed files with 9 additions and 0 deletions

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