Skip to content

Commit

Permalink
Dont attempt to create '*' namespace (hashicorp#382)
Browse files Browse the repository at this point in the history
* Dont attempt to create '*' namespace

Signed-off-by: Ashwin Venkatesh <[email protected]>
Signed-off-by: Luke Kysow <[email protected]>
  • Loading branch information
Ashwin Venkatesh authored Nov 6, 2020
1 parent 8e971ff commit 32ade6c
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ BUG FIXES:
* CRDs: validate custom resources can only set namespace fields if Consul namespaces are enabled [[GH-375](https://github.com/hashicorp/consul-k8s/pull/375)]
* CRDs: Ensure ACL token is global so that secondary DCs can manage custom resources.
Without this fix, controllers running in secondary datacenters would get ACL errors. [[GH-369](https://github.com/hashicorp/consul-k8s/pull/369)]
* CRDs: do not attempt to create a `*` namespace when service intentions specify `*` as destination.namespace. [[GH-382](https://github.com/hashicorp/consul-k8s/pull/382)]

## 0.19.0 (October 12, 2020)

Expand Down
5 changes: 5 additions & 0 deletions namespaces/namespaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,15 @@ import (
capi "github.com/hashicorp/consul/api"
)

const WildcardNamespace string = "*"

// 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 {
return false, nil
}
// Check if the Consul namespace exists.
namespaceInfo, _, err := client.Namespaces().Read(ns, nil)
if err != nil {
Expand Down
7 changes: 7 additions & 0 deletions namespaces/namespaces_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,13 @@ func TestEnsureExists_AlreadyExists(tt *testing.T) {
}
}

// Test that if the namespace already exists the function succeeds.
func TestEnsureExists_WildcardNamespace_AlreadyExists(tt *testing.T) {
created, err := EnsureExists(nil, WildcardNamespace, "")
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 32ade6c

Please sign in to comment.