Skip to content

Commit

Permalink
Don't try and create default namespace (hashicorp#396)
Browse files Browse the repository at this point in the history
  • Loading branch information
lkysow authored Nov 20, 2020
1 parent fc60149 commit ce728d6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
7 changes: 5 additions & 2 deletions namespaces/namespaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,16 @@ import (
capi "github.com/hashicorp/consul/api"
)

const WildcardNamespace string = "*"
const (
WildcardNamespace = "*"
DefaultNamespace = "default"
)

// EnsureExists ensures a Consul namespace with name ns exists. If it doesn't,
// it will create it and set crossNSACLPolicy as a policy default.
// Boolean return value indicates if the namespace was created by this call.
func EnsureExists(client *capi.Client, ns string, crossNSAClPolicy string) (bool, error) {
if ns == WildcardNamespace {
if ns == WildcardNamespace || ns == DefaultNamespace {
return false, nil
}
// Check if the Consul namespace exists.
Expand Down
7 changes: 7 additions & 0 deletions namespaces/namespaces_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,13 @@ func TestEnsureExists_WildcardNamespace_AlreadyExists(tt *testing.T) {
require.False(tt, created)
}

// Test that if the default namespace is passed in the function succeeds.
func TestEnsureExists_DefaultNamespace(tt *testing.T) {
created, err := EnsureExists(nil, DefaultNamespace, "")
require.NoError(tt, err)
require.False(tt, created)
}

// Test that it creates the namespace if it doesn't exist.
func TestEnsureExists_CreatesNS(tt *testing.T) {
for _, c := range []struct {
Expand Down

0 comments on commit ce728d6

Please sign in to comment.