Skip to content

Commit 8abd606

Browse files
authored
Add default-scheduler tests (#2795)
1 parent d8a0375 commit 8abd606

File tree

1 file changed

+70
-0
lines changed

1 file changed

+70
-0
lines changed

test/e2e/syncer/pods/pods.go

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"github.com/loft-sh/vcluster/pkg/util/translate"
1414
"github.com/loft-sh/vcluster/test/framework"
1515
"github.com/onsi/ginkgo/v2"
16+
"github.com/onsi/gomega"
1617
corev1 "k8s.io/api/core/v1"
1718
kerrors "k8s.io/apimachinery/pkg/api/errors"
1819
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -118,6 +119,75 @@ var _ = ginkgo.Describe("Pods are running in the host cluster", func() {
118119
}
119120
})
120121

122+
ginkgo.It("Test pod without explicitly set scheduler is scheduled by the default-scheduler", func(ctx context.Context) {
123+
const (
124+
podName = "implicit-default-scheduler-test"
125+
defaultSchedulerName = "default-scheduler"
126+
)
127+
_, err := f.VClusterClient.CoreV1().Pods(ns).Create(f.Context, &corev1.Pod{
128+
ObjectMeta: metav1.ObjectMeta{Name: podName},
129+
Spec: corev1.PodSpec{
130+
Containers: []corev1.Container{
131+
{
132+
Name: testingContainerName,
133+
Image: testingContainerImage,
134+
ImagePullPolicy: corev1.PullIfNotPresent,
135+
SecurityContext: f.GetDefaultSecurityContext(),
136+
},
137+
},
138+
},
139+
}, metav1.CreateOptions{})
140+
framework.ExpectNoError(err)
141+
142+
err = f.WaitForPodRunning(podName, ns)
143+
framework.ExpectNoError(err, "A pod created in the vcluster is expected to be in the Running phase eventually.")
144+
145+
eventsListOptions := metav1.ListOptions{
146+
FieldSelector: "reason==Scheduled,involvedObject.name==" + podName,
147+
}
148+
scheduledEvents, err := f.VClusterClient.CoreV1().Events(ns).List(ctx, eventsListOptions)
149+
framework.ExpectNoError(err)
150+
gomega.Expect(scheduledEvents.Items).To(gomega.HaveLen(1))
151+
152+
// Assert that the default scheduler has scheduled the pod
153+
gomega.Expect(scheduledEvents.Items[0].ReportingController).To(gomega.Equal(defaultSchedulerName))
154+
})
155+
156+
ginkgo.It("Test pod with explicitly set default-scheduler is scheduled by the default-scheduler", func(ctx context.Context) {
157+
const (
158+
podName = "explicit-default-scheduler-test"
159+
defaultSchedulerName = "default-scheduler"
160+
)
161+
_, err := f.VClusterClient.CoreV1().Pods(ns).Create(f.Context, &corev1.Pod{
162+
ObjectMeta: metav1.ObjectMeta{Name: podName},
163+
Spec: corev1.PodSpec{
164+
Containers: []corev1.Container{
165+
{
166+
Name: testingContainerName,
167+
Image: testingContainerImage,
168+
ImagePullPolicy: corev1.PullIfNotPresent,
169+
SecurityContext: f.GetDefaultSecurityContext(),
170+
},
171+
},
172+
SchedulerName: defaultSchedulerName,
173+
},
174+
}, metav1.CreateOptions{})
175+
framework.ExpectNoError(err)
176+
177+
err = f.WaitForPodRunning(podName, ns)
178+
framework.ExpectNoError(err, "A pod created in the vcluster is expected to be in the Running phase eventually.")
179+
180+
eventsListOptions := metav1.ListOptions{
181+
FieldSelector: "reason==Scheduled,involvedObject.name==" + podName,
182+
}
183+
scheduledEvents, err := f.VClusterClient.CoreV1().Events(ns).List(ctx, eventsListOptions)
184+
framework.ExpectNoError(err)
185+
gomega.Expect(scheduledEvents.Items).To(gomega.HaveLen(1))
186+
187+
// Assert that the default scheduler has scheduled the pod
188+
gomega.Expect(scheduledEvents.Items[0].ReportingController).To(gomega.Equal(defaultSchedulerName))
189+
})
190+
121191
ginkgo.It("Test pod starts successfully and readiness conditions are synced back to vcluster pod resource", func() {
122192
podName := "test"
123193
_, err := f.VClusterClient.CoreV1().Pods(ns).Create(f.Context, &corev1.Pod{

0 commit comments

Comments
 (0)