|
| 1 | +package e2e |
| 2 | + |
| 3 | +import ( |
| 4 | + "time" |
| 5 | + |
| 6 | + . "github.com/onsi/ginkgo/v2" |
| 7 | + |
| 8 | + . "sigs.k8s.io/hierarchical-namespaces/pkg/testutils" |
| 9 | +) |
| 10 | + |
| 11 | +var _ = Describe("List Resources", func() { |
| 12 | + const ( |
| 13 | + parent1 = namspacePrefix + "parent1" |
| 14 | + parent2 = namspacePrefix + "parent2" |
| 15 | + child1a = namspacePrefix + "child1a" |
| 16 | + child1b = namspacePrefix + "child1b" |
| 17 | + child2a = namspacePrefix + "child2a" |
| 18 | + grandchild1ai = namspacePrefix + "grandchild1ai" |
| 19 | + ) |
| 20 | + |
| 21 | + BeforeEach(func() { |
| 22 | + CleanupTestNamespaces() |
| 23 | + CreateNamespace(parent1) |
| 24 | + CreateNamespace(parent2) |
| 25 | + CreateSubnamespace(child1a, parent1) |
| 26 | + CreateSubnamespace(child1b, parent1) |
| 27 | + CreateSubnamespace(child2a, parent2) |
| 28 | + CreateSubnamespace(grandchild1ai, child1a) |
| 29 | + // wait for all the descendents to be in the tree |
| 30 | + RunShouldContain(grandchild1ai, 5, "kubectl hns tree", parent1) |
| 31 | + }) |
| 32 | + |
| 33 | + AfterEach(func() { |
| 34 | + CleanupTestNamespaces() |
| 35 | + }) |
| 36 | + |
| 37 | + It("should list resources", func() { |
| 38 | + createEmptySecret(parent1, "s-parent1") |
| 39 | + createEmptySecret(child1a, "s-child1a") |
| 40 | + createEmptySecret(child1b, "s-child1b") |
| 41 | + createEmptySecret(grandchild1ai, "s-grandchild1ai") |
| 42 | + createEmptySecret(child2a, "s-child2a") |
| 43 | + |
| 44 | + // verify |
| 45 | + // list resources under one tree |
| 46 | + RunShouldContainMultiple([]string{"s-parent1", "s-child1a", "s-child1b", "s-grandchild1ai"}, 5, "kubectl hns --namespace", parent1, "get secret") |
| 47 | + RunShouldNotContain("s-child2a", 5, "kubectl hns --namespace", parent1, "get secret") |
| 48 | + |
| 49 | + // list resources under another tree |
| 50 | + RunShouldContain("s-child2a", 5, "kubectl hns --namespace", parent2, "get secret") |
| 51 | + RunShouldNotContainMultiple([]string{"s-parent1", "s-child1a", "s-child1b", "s-grandchild1ai"}, 5, "kubectl hns --namespace", parent2, "get secret") |
| 52 | + |
| 53 | + // list all resources |
| 54 | + RunShouldContainMultiple([]string{"s-parent1", "s-child1a", "s-child1b", "s-grandchild1ai", "s-child2a"}, 5, "kubectl hns get secret --all-namespaces") |
| 55 | + }) |
| 56 | + |
| 57 | + It("should watch resources", func() { |
| 58 | + go func() { |
| 59 | + defer GinkgoRecover() |
| 60 | + interval := 1 * time.Second |
| 61 | + time.Sleep(interval) |
| 62 | + createEmptySecret(parent1, "s-parent1") |
| 63 | + time.Sleep(interval) |
| 64 | + createEmptySecret(child1a, "s-child1a") |
| 65 | + time.Sleep(interval) |
| 66 | + createEmptySecret(child1b, "s-child1b") |
| 67 | + time.Sleep(interval) |
| 68 | + createEmptySecret(grandchild1ai, "s-grandchild1ai") |
| 69 | + time.Sleep(interval) |
| 70 | + createEmptySecret(child2a, "s-child2a") |
| 71 | + }() |
| 72 | + |
| 73 | + // verify |
| 74 | + cmd := []string{"kubectl hns --namespace", parent1, "get secret --watch"} |
| 75 | + wantStrings := []string{"s-parent1", "s-child1a", "s-child1b", "s-grandchild1ai"} |
| 76 | + RunShouldContainMultipleWithTimeout(wantStrings, 15, 15, cmd...) |
| 77 | + }) |
| 78 | +}) |
| 79 | + |
| 80 | +func createEmptySecret(namespace, name string) { |
| 81 | + MustRun("kubectl --namespace", namespace, "create secret generic", name) |
| 82 | +} |
0 commit comments