diff --git a/cmd/ctr/main.go b/cmd/ctr/main.go index 9c39c87f11f2..3120a517ecda 100644 --- a/cmd/ctr/main.go +++ b/cmd/ctr/main.go @@ -6,6 +6,7 @@ import ( "github.com/Sirupsen/logrus" "github.com/containerd/containerd" + "github.com/containerd/containerd/namespaces" "github.com/containerd/containerd/version" "github.com/urfave/cli" ) @@ -48,8 +49,8 @@ containerd CLI cli.StringFlag{ Name: "namespace, n", Usage: "namespace to use with commands", - Value: "default", - EnvVar: "CONTAINERD_NAMESPACE", + Value: namespaces.Default, + EnvVar: namespaces.NamespaceEnvVar, }, } app.Commands = append([]cli.Command{ diff --git a/cmd/dist/main.go b/cmd/dist/main.go index d5da0ee19df1..9c7f7bd2038c 100644 --- a/cmd/dist/main.go +++ b/cmd/dist/main.go @@ -6,6 +6,7 @@ import ( "time" "github.com/Sirupsen/logrus" + namespaces2 "github.com/containerd/containerd/namespaces" "github.com/containerd/containerd/version" "github.com/urfave/cli" ) @@ -62,8 +63,8 @@ distribution tool cli.StringFlag{ Name: "namespace, n", Usage: "namespace to use with commands", - Value: "default", - EnvVar: "CONTAINERD_NAMESPACE", + Value: namespaces2.Default, + EnvVar: namespaces2.NamespaceEnvVar, }, } app.Commands = []cli.Command{ diff --git a/namespaces/context.go b/namespaces/context.go index 31c2a0410709..b08fded5b88e 100644 --- a/namespaces/context.go +++ b/namespaces/context.go @@ -8,8 +8,8 @@ import ( ) const ( - namespaceEnvVar = "CONTAINERD_NAMESPACE" - defaultNamespace = "default" + NamespaceEnvVar = "CONTAINERD_NAMESPACE" + Default = "default" ) var ( @@ -30,9 +30,9 @@ func WithNamespace(ctx context.Context, namespace string) context.Context { // NamespaceFromEnv uses the namespace defined in CONTAINERD_NAMESPACE or // default func NamespaceFromEnv(ctx context.Context) context.Context { - namespace := os.Getenv(namespaceEnvVar) + namespace := os.Getenv(NamespaceEnvVar) if namespace == "" { - namespace = defaultNamespace + namespace = Default } return WithNamespace(ctx, namespace) } diff --git a/namespaces/context_test.go b/namespaces/context_test.go index 09159efe3c4f..41eee5d7e671 100644 --- a/namespaces/context_test.go +++ b/namespaces/context_test.go @@ -31,8 +31,8 @@ func TestContext(t *testing.T) { } func TestNamespaceFromEnv(t *testing.T) { - oldenv := os.Getenv(namespaceEnvVar) - defer os.Setenv(namespaceEnvVar, oldenv) // restore old env var + oldenv := os.Getenv(NamespaceEnvVar) + defer os.Setenv(NamespaceEnvVar, oldenv) // restore old env var ctx := context.Background() namespace, ok := Namespace(ctx) @@ -45,7 +45,7 @@ func TestNamespaceFromEnv(t *testing.T) { } expected := "test-namespace" - os.Setenv(namespaceEnvVar, expected) + os.Setenv(NamespaceEnvVar, expected) nctx := NamespaceFromEnv(ctx) namespace, ok = Namespace(nctx)