|
1 | 1 | package limitclasses
|
2 | 2 |
|
3 | 3 | import (
|
4 |
| - "fmt" |
5 | 4 | "time"
|
6 | 5 |
|
7 | 6 | "github.com/loft-sh/vcluster/test/framework"
|
@@ -66,19 +65,29 @@ var _ = ginkgo.Describe("Test limitclass on fromHost", ginkgo.Ordered, func() {
|
66 | 65 |
|
67 | 66 | ginkgo.It("should only sync ingressClasses with allowed label to vcluster", func() {
|
68 | 67 | ginkgo.By("Listing all ingresssesClasses available in vcluster")
|
69 |
| - ics, err := f.VClusterClient.NetworkingV1().IngressClasses().List(f.Context, metav1.ListOptions{}) |
70 |
| - gomega.Expect(err).NotTo(gomega.HaveOccurred()) |
71 |
| - var names []string |
72 |
| - for _, ic := range ics.Items { |
73 |
| - names = append(names, ic.Name) |
74 |
| - } |
75 |
| - gomega.Expect(names).To(gomega.ContainElement(nginxClassName)) |
76 |
| - ginkgo.By("Found nginx-ingressclass in vcluster") |
77 |
| - gomega.Expect(names).NotTo(gomega.ContainElement(haproxyClassName)) |
78 |
| - ginkgo.By("haproxy-ingressclass is not available in vcluster") |
| 68 | + gomega.Eventually(func() bool { |
| 69 | + ingressClasses, err := f.VClusterClient.NetworkingV1().IngressClasses().List(f.Context, metav1.ListOptions{}) |
| 70 | + if err != nil { |
| 71 | + return false |
| 72 | + } |
| 73 | + foundNginxIngressClass := false |
| 74 | + foundHaproxyIngressClass := false |
| 75 | + for _, ingressClass := range ingressClasses.Items { |
| 76 | + if ingressClass.Name == nginxClassName { |
| 77 | + foundNginxIngressClass = true |
| 78 | + } |
| 79 | + if ingressClass.Name == haproxyClassName { |
| 80 | + foundHaproxyIngressClass = true |
| 81 | + } |
| 82 | + } |
| 83 | + return foundNginxIngressClass && !foundHaproxyIngressClass |
| 84 | + }). |
| 85 | + WithPolling(time.Second). |
| 86 | + WithTimeout(framework.PollTimeout). |
| 87 | + Should(gomega.BeTrue(), "Timed out waiting for the ingressClasses in vCluster") |
79 | 88 | })
|
80 | 89 |
|
81 |
| - ginkgo.It("should not sync vcluster ingresses using a filtered ingressClass to host", func() { |
| 90 | + ginkgo.It("should not sync vcluster ingresses created using an ingressClass not available in vCluster", func() { |
82 | 91 | ginkgo.By("Creating a haproxy-ingress using haproxy-ingressclass in vcluster")
|
83 | 92 | haproxyIngress := &networkingv1.Ingress{
|
84 | 93 | ObjectMeta: metav1.ObjectMeta{
|
@@ -119,22 +128,22 @@ var _ = ginkgo.Describe("Test limitclass on fromHost", ginkgo.Ordered, func() {
|
119 | 128 |
|
120 | 129 | ginkgo.By("There should be a warning message event in the describe of the created ingress")
|
121 | 130 | gomega.Eventually(func() bool {
|
122 |
| - eventList, err := f.VClusterClient.CoreV1().Events(testNamespace).List(f.Context, metav1.ListOptions{ |
123 |
| - FieldSelector: fmt.Sprintf("involvedObject.kind=Ingress,involvedObject.name=%s", haproxyIngressName), |
124 |
| - }) |
| 131 | + eventList, err := f.VClusterClient.CoreV1().Events(testNamespace).List(f.Context, metav1.ListOptions{}) |
125 | 132 | gomega.Expect(err).NotTo(gomega.HaveOccurred())
|
126 | 133 | for _, event := range eventList.Items {
|
127 |
| - if event.Type == corev1.EventTypeWarning && event.Reason == "SyncWarning" { |
128 |
| - expectedSubstring := fmt.Sprintf(`did not sync ingress "%s" to host because the ingress class "%s" in the host does not match the selector under 'sync.fromHost.ingressClasses.selector'`, haproxyIngressName, haproxyClassName) |
129 |
| - gomega.Expect(event.Message).To(gomega.ContainSubstring(expectedSubstring)) |
| 134 | + if event.InvolvedObject.Kind == "Ingress" && event.InvolvedObject.Name == haproxyIngressName && event.Type == corev1.EventTypeWarning && event.Reason == "SyncWarning" { |
| 135 | + gomega.Expect(event.Message).To(gomega.ContainSubstring(`did not sync ingress "%s" to host because the ingress class "%s" in the host does not match the selector under 'sync.fromHost.ingressClasses.selector'`, haproxyIngressName, haproxyClassName)) |
130 | 136 | return true
|
131 | 137 | }
|
132 | 138 | }
|
133 | 139 | return false
|
134 |
| - }).WithTimeout(time.Minute).WithPolling(time.Second).Should(gomega.BeTrue(), "Timed out waiting for SyncWarning event for ingress %s", haproxyIngressName) |
| 140 | + }). |
| 141 | + WithTimeout(time.Minute). |
| 142 | + WithPolling(time.Second). |
| 143 | + Should(gomega.BeTrue(), "Timed out waiting for SyncWarning event for ingress %s", haproxyIngressName) |
135 | 144 | })
|
136 | 145 |
|
137 |
| - ginkgo.It("should sync vcluster ingresses using allowed ingressClass to host", func() { |
| 146 | + ginkgo.It("should sync ingresses created in vcluster to host", func() { |
138 | 147 | ginkgo.By("Creating a nginx-ingress using nginx-ingressclass in vcluster")
|
139 | 148 | nginxIngress := &networkingv1.Ingress{
|
140 | 149 | ObjectMeta: metav1.ObjectMeta{
|
@@ -169,18 +178,22 @@ var _ = ginkgo.Describe("Test limitclass on fromHost", ginkgo.Ordered, func() {
|
169 | 178 | _, err := f.VClusterClient.NetworkingV1().Ingresses(testNamespace).Create(f.Context, nginxIngress, metav1.CreateOptions{})
|
170 | 179 | framework.ExpectNoError(err)
|
171 | 180 |
|
172 |
| - ginkgo.By("Ingress should be synced to host") |
173 |
| - gomega.Eventually(func() []string { |
174 |
| - igs, err := f.HostClient.NetworkingV1().Ingresses(hostNamespace).List(f.Context, metav1.ListOptions{}) |
| 181 | + ginkgo.By("should sync ingress created in vCluster to host using ingressClass synced from Host") |
| 182 | + ginkgo.By("Listing all Ingresses in host's vcluster namespace") |
| 183 | + gomega.Eventually(func() bool { |
| 184 | + ingresses, err := f.HostClient.NetworkingV1().Ingresses(hostNamespace).List(f.Context, metav1.ListOptions{}) |
175 | 185 | if err != nil {
|
176 |
| - return nil |
| 186 | + return false |
177 | 187 | }
|
178 |
| - var names []string |
179 |
| - for _, igc := range igs.Items { |
180 |
| - names = append(names, igc.Name) |
| 188 | + for _, ingress := range ingresses.Items { |
| 189 | + if ingress.Name == nginxIngressName+"-x-"+testNamespace+"-x-"+hostNamespace { |
| 190 | + return true |
| 191 | + } |
181 | 192 | }
|
182 |
| - return names |
183 |
| - }).WithTimeout(time.Minute).WithPolling(time.Second). |
184 |
| - Should(gomega.ContainElement(nginxIngressName + "-x-" + testNamespace + "-x-" + hostNamespace)) |
| 193 | + return false |
| 194 | + }). |
| 195 | + WithTimeout(time.Minute). |
| 196 | + WithPolling(time.Second). |
| 197 | + Should(gomega.BeTrue(), "Timed out waiting for listing all ingresses in host") |
185 | 198 | })
|
186 | 199 | })
|
0 commit comments