Skip to content

Commit 3a92e19

Browse files
akhilaoommenAkhila Rachel Oommen
andauthored
Fixed flaky tests in e2e_limit_classes (#2934)
* Added two new test scripts for ingressClasses and priorityClasses limit * Added two new test scripts for ingressClasses and priorityClasses limit * Removed comments and corrected values file * Corrected values file for runtimeClasses * Created a new folder structure for limit host classes tests * Corrected test/e2e/values.yaml * Corrected test/e2e/values.yaml for runtimeClasses * Corrected test/e2e/values.yaml for priorityClasses * Removed storageClasses and priorityClasses sync.fromHost * Removed ingressClasses sync.fromHost * Added 2 P0 tests for stroageClasses and runtimeClasses, also did some changes as aked by Ulysses * Added a verification of events for the resources created with not allowed classes and modified based on Sowmya's comments * Fixed flaky test to verify the events in the resources when classes are not available * Fixed flaky tests * Fixed flaky tests * Added polling for listing classes inside the vcluster * Corrected a value * Corrected a classname * Changed the scripts as requested by Sowmya * Changed the scripts as requested by Sowmya * Removed conistent check of the classes inside the vCluster * Changed the logic to check the ingressClasses in vCluster --------- Co-authored-by: Akhila Rachel Oommen <akhilarachel@Mac.fritz.box>
1 parent 17a5c87 commit 3a92e19

File tree

4 files changed

+157
-112
lines changed

4 files changed

+157
-112
lines changed

test/e2e_limit_classes/limitClasses/ingressClasses.go

Lines changed: 43 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package limitclasses
22

33
import (
4-
"fmt"
54
"time"
65

76
"github.com/loft-sh/vcluster/test/framework"
@@ -66,19 +65,29 @@ var _ = ginkgo.Describe("Test limitclass on fromHost", ginkgo.Ordered, func() {
6665

6766
ginkgo.It("should only sync ingressClasses with allowed label to vcluster", func() {
6867
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")
7988
})
8089

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() {
8291
ginkgo.By("Creating a haproxy-ingress using haproxy-ingressclass in vcluster")
8392
haproxyIngress := &networkingv1.Ingress{
8493
ObjectMeta: metav1.ObjectMeta{
@@ -119,22 +128,22 @@ var _ = ginkgo.Describe("Test limitclass on fromHost", ginkgo.Ordered, func() {
119128

120129
ginkgo.By("There should be a warning message event in the describe of the created ingress")
121130
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{})
125132
gomega.Expect(err).NotTo(gomega.HaveOccurred())
126133
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))
130136
return true
131137
}
132138
}
133139
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)
135144
})
136145

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() {
138147
ginkgo.By("Creating a nginx-ingress using nginx-ingressclass in vcluster")
139148
nginxIngress := &networkingv1.Ingress{
140149
ObjectMeta: metav1.ObjectMeta{
@@ -169,18 +178,22 @@ var _ = ginkgo.Describe("Test limitclass on fromHost", ginkgo.Ordered, func() {
169178
_, err := f.VClusterClient.NetworkingV1().Ingresses(testNamespace).Create(f.Context, nginxIngress, metav1.CreateOptions{})
170179
framework.ExpectNoError(err)
171180

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{})
175185
if err != nil {
176-
return nil
186+
return false
177187
}
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+
}
181192
}
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")
185198
})
186199
})

test/e2e_limit_classes/limitClasses/priorityClasses.go

Lines changed: 34 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package limitclasses
22

33
import (
4-
"fmt"
54
"time"
65

76
"github.com/loft-sh/vcluster/test/framework"
@@ -66,19 +65,29 @@ var _ = ginkgo.Describe("Test limitclass on fromHost", ginkgo.Ordered, func() {
6665

6766
ginkgo.It("should only sync priorityClasses to virtual with allowed label", func() {
6867
ginkgo.By("Listing all priorityClasses in vcluster")
69-
pcs, err := f.VClusterClient.SchedulingV1().PriorityClasses().List(f.Context, metav1.ListOptions{})
70-
gomega.Expect(err).NotTo(gomega.HaveOccurred())
71-
var names []string
72-
for _, pc := range pcs.Items {
73-
names = append(names, pc.Name)
74-
}
75-
gomega.Expect(names).To(gomega.ContainElement(hpriorityClassName))
76-
ginkgo.By("Found high-priority in vcluster")
77-
gomega.Expect(names).NotTo(gomega.ContainElement(lpriorityClassName))
78-
ginkgo.By("low-priority is not available in vcluster")
68+
gomega.Eventually(func() bool {
69+
priorityClasses, err := f.VClusterClient.SchedulingV1().PriorityClasses().List(f.Context, metav1.ListOptions{})
70+
if err != nil {
71+
return false
72+
}
73+
foundhighPriorityClass := false
74+
foundlowPriorityClass := false
75+
for _, priorityClass := range priorityClasses.Items {
76+
if priorityClass.Name == hpriorityClassName {
77+
foundhighPriorityClass = true
78+
}
79+
if priorityClass.Name == lpriorityClassName {
80+
foundlowPriorityClass = true
81+
}
82+
}
83+
return foundhighPriorityClass && !foundlowPriorityClass
84+
}).
85+
WithPolling(time.Second).
86+
WithTimeout(framework.PollTimeout).
87+
Should(gomega.BeTrue(), "Timed out waiting for the priorityClasses in vCluster")
7988
})
8089

81-
ginkgo.It("should get an error for pod creation using filtered priorityClass to host", func() {
90+
ginkgo.It("should get an error for pod creation in vcluster using an unavailable priorityClass", func() {
8291
ginkgo.By("Creating a pod using low-prority priorityClass in vcluster")
8392
lpPod := &corev1.Pod{
8493
ObjectMeta: metav1.ObjectMeta{
@@ -97,11 +106,10 @@ var _ = ginkgo.Describe("Test limitclass on fromHost", ginkgo.Ordered, func() {
97106
}
98107
_, err := f.VClusterClient.CoreV1().Pods(testNamespace).Create(f.Context, lpPod, metav1.CreateOptions{})
99108
ginkgo.By("An error should be triggered")
100-
expectedSubstring := fmt.Sprintf(`pods "%s" is forbidden: no PriorityClass with name %s was found`, lpPodName, lpriorityClassName)
101-
gomega.Expect(err).To(gomega.MatchError(gomega.ContainSubstring(expectedSubstring)))
109+
gomega.Expect(err).To(gomega.MatchError(gomega.ContainSubstring(`pods "%s" is forbidden: no PriorityClass with name %s was found`, lpPodName, lpriorityClassName)))
102110
})
103111

104-
ginkgo.It("should sync vcluster pod created with allowed priorityClass to host", func() {
112+
ginkgo.It("should sync Pods created in vCluster to host using priorityClass synced from Host", func() {
105113
ginkgo.By("Creating a pod using high-prority priorityClass in vcluster")
106114
hpPod := &corev1.Pod{
107115
ObjectMeta: metav1.ObjectMeta{
@@ -121,19 +129,22 @@ var _ = ginkgo.Describe("Test limitclass on fromHost", ginkgo.Ordered, func() {
121129
_, err := f.VClusterClient.CoreV1().Pods(testNamespace).Create(f.Context, hpPod, metav1.CreateOptions{})
122130
framework.ExpectNoError(err)
123131

124-
ginkgo.By("Pod should be synced to host")
125-
gomega.Eventually(func() []string {
132+
ginkgo.By("Listing all Pods in host's vcluster namespace")
133+
gomega.Eventually(func() bool {
126134
pods, err := f.HostClient.CoreV1().Pods(hostNamespace).List(f.Context, metav1.ListOptions{})
127135
if err != nil {
128-
return nil
136+
return false
129137
}
130-
var names []string
131138
for _, pod := range pods.Items {
132-
names = append(names, pod.Name)
139+
if pod.Name == hpPodName+"-x-"+testNamespace+"-x-"+hostNamespace {
140+
return true
141+
}
133142
}
134-
return names
135-
}).WithTimeout(time.Minute).WithPolling(time.Second).
136-
Should(gomega.ContainElement(hpPodName + "-x-" + testNamespace + "-x-" + hostNamespace))
143+
return false
144+
}).
145+
WithTimeout(time.Minute).
146+
WithPolling(time.Second).
147+
Should(gomega.BeTrue(), "Timed out waiting for listing all pods in host")
137148
})
138149

139150
})

test/e2e_limit_classes/limitClasses/runtimeClasses.go

Lines changed: 37 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package limitclasses
22

33
import (
4-
"fmt"
54
"time"
65

76
"github.com/loft-sh/vcluster/test/framework"
@@ -61,20 +60,30 @@ var _ = ginkgo.Describe("Test limitclass on fromHost", ginkgo.Ordered, func() {
6160
})
6261

6362
ginkgo.It("should only sync runtimeClasses to virtual with allowed label", func() {
64-
ginkgo.By("Listing all runtimeClasses in the vCluster")
65-
rcs, err := f.VClusterClient.NodeV1().RuntimeClasses().List(f.Context, metav1.ListOptions{})
66-
gomega.Expect(err).NotTo(gomega.HaveOccurred())
67-
var names []string
68-
for _, rc := range rcs.Items {
69-
names = append(names, rc.Name)
70-
}
71-
gomega.Expect(names).To(gomega.ContainElement(runcClassName))
72-
ginkgo.By("Found runc in vcluster")
73-
gomega.Expect(names).NotTo(gomega.ContainElement(runscClassName))
74-
ginkgo.By("runsc is not available in vcluster")
63+
ginkgo.By("Listing all runtimeClasses in vCluster")
64+
gomega.Eventually(func() bool {
65+
runtimeClasses, err := f.VClusterClient.NodeV1().RuntimeClasses().List(f.Context, metav1.ListOptions{})
66+
if err != nil {
67+
return false
68+
}
69+
foundRuncClass := false
70+
foundRunscClass := false
71+
for _, runtimeClass := range runtimeClasses.Items {
72+
if runtimeClass.Name == runcClassName {
73+
foundRuncClass = true
74+
}
75+
if runtimeClass.Name == runscClassName {
76+
foundRunscClass = true
77+
}
78+
}
79+
return foundRuncClass && !foundRunscClass
80+
}).
81+
WithPolling(time.Second).
82+
WithTimeout(framework.PollTimeout).
83+
Should(gomega.BeTrue(), "Timed out waiting for the runtimeClasses in vCluster")
7584
})
7685

77-
ginkgo.It("should get an error for pod creation using filtered runtimeClass to host", func() {
86+
ginkgo.It("should get an error for pod creation in vcluster using an unavailable runtimeClass", func() {
7887
ginkgo.By("Creating a pod using runsc runtimeClass in vcluster")
7988
runscpod := &corev1.Pod{
8089
ObjectMeta: metav1.ObjectMeta{
@@ -98,11 +107,10 @@ var _ = ginkgo.Describe("Test limitclass on fromHost", ginkgo.Ordered, func() {
98107
}
99108
_, err := f.VClusterClient.CoreV1().Pods(testNamespace).Create(f.Context, runscpod, metav1.CreateOptions{})
100109
ginkgo.By("An error should be triggered")
101-
expectedSubstring := fmt.Sprintf(`pods "%s" is forbidden: pod rejected: RuntimeClass "%s" not found`, rscPodName, runscClassName)
102-
gomega.Expect(err).To(gomega.MatchError(gomega.ContainSubstring(expectedSubstring)))
110+
gomega.Expect(err).To(gomega.MatchError(gomega.ContainSubstring(`pods "%s" is forbidden: pod rejected: RuntimeClass "%s" not found`, rscPodName, runscClassName)))
103111
})
104112

105-
ginkgo.It("should sync vcluster pod created with allowed runtimeClass to host", func() {
113+
ginkgo.It("should sync Pods created in vCluster to host using runtimeClass synced from Host", func() {
106114
ginkgo.By("Creating a pod using runc runtimeClass in vcluster")
107115
runcpod := &corev1.Pod{
108116
ObjectMeta: metav1.ObjectMeta{
@@ -127,20 +135,21 @@ var _ = ginkgo.Describe("Test limitclass on fromHost", ginkgo.Ordered, func() {
127135
_, err := f.VClusterClient.CoreV1().Pods(testNamespace).Create(f.Context, runcpod, metav1.CreateOptions{})
128136
framework.ExpectNoError(err)
129137

130-
ginkgo.By("Pod should be synced to host")
131-
gomega.Eventually(func() []string {
132-
pods, err := f.HostClient.CoreV1().Pods(hostNamespace).List(f.Context, metav1.ListOptions{}) // List all pods in the vCluster
138+
ginkgo.By("Listing all Pods in host's vcluster namespace")
139+
gomega.Eventually(func() bool {
140+
pods, err := f.HostClient.CoreV1().Pods(hostNamespace).List(f.Context, metav1.ListOptions{})
133141
if err != nil {
134-
return nil
142+
return false
135143
}
136-
var names []string
137-
for _, po := range pods.Items {
138-
names = append(names, po.Name)
144+
for _, pod := range pods.Items {
145+
if pod.Name == rcPodName+"-x-"+testNamespace+"-x-"+hostNamespace {
146+
return true
147+
}
139148
}
140-
return names
141-
}).WithTimeout(time.Minute).WithPolling(time.Second).
142-
Should(gomega.ContainElement(rcPodName + "-x-" + testNamespace + "-x-" + hostNamespace))
143-
149+
return false
150+
}).
151+
WithTimeout(time.Minute).
152+
WithPolling(time.Second).
153+
Should(gomega.BeTrue(), "Timed out waiting for listing all pods in host")
144154
})
145-
146155
})

0 commit comments

Comments
 (0)