Use direct function call.

Signed-off-by: Lantao Liu <lantaol@google.com>
This commit is contained in:
Lantao Liu
2018-03-13 04:41:21 +00:00
parent edb38dfecc
commit f0a500a390
16 changed files with 195 additions and 118 deletions

View File

@@ -19,7 +19,10 @@ package util
import (
"time"
"github.com/containerd/containerd/namespaces"
"golang.org/x/net/context"
"github.com/containerd/cri-containerd/pkg/constants"
)
// deferCleanupTimeout is the default timeout for containerd cleanup operations
@@ -28,8 +31,16 @@ const deferCleanupTimeout = 1 * time.Minute
// DeferContext returns a context for containerd cleanup operations in defer.
// A default timeout is applied to avoid cleanup operation pending forever.
// TODO(random-liu): Add namespace after local services are used.
// (containerd/containerd#2183)
func DeferContext() (context.Context, context.CancelFunc) {
return context.WithTimeout(context.Background(), deferCleanupTimeout)
return context.WithTimeout(NamespacedContext(), deferCleanupTimeout)
}
// NamespacedContext returns a context with kubernetes namespace set.
func NamespacedContext() context.Context {
return WithNamespace(context.Background())
}
// WithNamespace adds kubernetes namespace to the context.
func WithNamespace(ctx context.Context) context.Context {
return namespaces.WithNamespace(ctx, constants.K8sContainerdNamespace)
}