Skip to content

Commit

Permalink
namespaces: Export env var and default value
Browse files Browse the repository at this point in the history
Signed-off-by: Samuel Karp <skarp@amazon.com>
  • Loading branch information
samuelkarp committed Jun 22, 2017
1 parent 753f1a6 commit 9190f98
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 11 deletions.
5 changes: 3 additions & 2 deletions cmd/ctr/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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{
Expand Down
5 changes: 3 additions & 2 deletions cmd/dist/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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{
Expand Down
8 changes: 4 additions & 4 deletions namespaces/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import (
)

const (
namespaceEnvVar = "CONTAINERD_NAMESPACE"
defaultNamespace = "default"
NamespaceEnvVar = "CONTAINERD_NAMESPACE"
Default = "default"
)

var (
Expand All @@ -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)
}
Expand Down
6 changes: 3 additions & 3 deletions namespaces/context_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down

0 comments on commit 9190f98

Please sign in to comment.