This repository has been archived by the owner on Nov 1, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Add --k8s-namespace-whitelist setting that specifies namespaces to watch. #1184
Merged
Merged
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
1ae7cd4
Add --k8s-namespace-whitelist setting that specifies namespaces to wa…
6ce9add
Limit AllControllers() to only search namespaces in the whitelist
5d75e46
Change nsWhitelist to a map instead of a string, if a namespace is tr…
0b00b1d
Mark namespace whitelist feature experimental.
justinbatcf File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package kubernetes | ||
|
||
import ( | ||
apiv1 "k8s.io/api/core/v1" | ||
meta_v1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
fakekubernetes "k8s.io/client-go/kubernetes/fake" | ||
"testing" | ||
"reflect" | ||
) | ||
|
||
func newNamespace(name string) *apiv1.Namespace { | ||
return &apiv1.Namespace{ | ||
ObjectMeta: meta_v1.ObjectMeta{ | ||
Name: name, | ||
}, | ||
TypeMeta: meta_v1.TypeMeta{ | ||
APIVersion: "v1", | ||
Kind: "Namespace", | ||
}, | ||
} | ||
} | ||
|
||
func testGetNamespaces(t *testing.T, namespace []string, expected []string) { | ||
clientset := fakekubernetes.NewSimpleClientset(newNamespace("default"), | ||
newNamespace("kube-system")) | ||
|
||
c := NewCluster(clientset, nil, nil, nil, nil, namespace) | ||
|
||
namespaces, err := c.getNamespaces() | ||
if err != nil { | ||
t.Errorf("The error should be nil, not: %s", err) | ||
} | ||
|
||
result := []string{} | ||
for _, namespace := range namespaces { | ||
result = append(result, namespace.ObjectMeta.Name) | ||
} | ||
|
||
if reflect.DeepEqual(result, expected) != true { | ||
t.Errorf("Unexpected namespaces: %v != %v.", result, expected) | ||
} | ||
} | ||
|
||
func TestGetNamespacesDefault(t *testing.T) { | ||
testGetNamespaces(t, []string{}, []string{"default","kube-system",}) | ||
} | ||
|
||
func TestGetNamespacesNamespacesIsNil(t *testing.T) { | ||
testGetNamespaces(t, nil, []string{"default","kube-system",}) | ||
} | ||
|
||
func TestGetNamespacesNamespacesSet(t *testing.T) { | ||
testGetNamespaces(t, []string{"default"}, []string{"default",}) | ||
} | ||
|
||
func TestGetNamespacesNamespacesSetDoesNotExist(t *testing.T) { | ||
testGetNamespaces(t, []string{"hello"}, []string{}) | ||
} | ||
|
||
func TestGetNamespacesNamespacesMultiple(t *testing.T) { | ||
testGetNamespaces(t, []string{"default","hello","kube-system"}, []string{"default","kube-system"}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This comment was marked as abuse.
Sorry, something went wrong.