Skip to content

Add default-scheduler tests #2795

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 20, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 70 additions & 0 deletions test/e2e/syncer/pods/pods.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/loft-sh/vcluster/pkg/util/translate"
"github.com/loft-sh/vcluster/test/framework"
"github.com/onsi/ginkgo/v2"
"github.com/onsi/gomega"
corev1 "k8s.io/api/core/v1"
kerrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down Expand Up @@ -118,6 +119,75 @@ var _ = ginkgo.Describe("Pods are running in the host cluster", func() {
}
})

ginkgo.It("Test pod without explicitly set scheduler is scheduled by the default-scheduler", func(ctx context.Context) {
const (
podName = "implicit-default-scheduler-test"
defaultSchedulerName = "default-scheduler"
)
_, err := f.VClusterClient.CoreV1().Pods(ns).Create(f.Context, &corev1.Pod{
ObjectMeta: metav1.ObjectMeta{Name: podName},
Spec: corev1.PodSpec{
Containers: []corev1.Container{
{
Name: testingContainerName,
Image: testingContainerImage,
ImagePullPolicy: corev1.PullIfNotPresent,
SecurityContext: f.GetDefaultSecurityContext(),
},
},
},
}, metav1.CreateOptions{})
framework.ExpectNoError(err)

err = f.WaitForPodRunning(podName, ns)
framework.ExpectNoError(err, "A pod created in the vcluster is expected to be in the Running phase eventually.")

eventsListOptions := metav1.ListOptions{
FieldSelector: "reason==Scheduled,involvedObject.name==" + podName,
}
scheduledEvents, err := f.VClusterClient.CoreV1().Events(ns).List(ctx, eventsListOptions)
framework.ExpectNoError(err)
gomega.Expect(scheduledEvents.Items).To(gomega.HaveLen(1))

// Assert that the default scheduler has scheduled the pod
gomega.Expect(scheduledEvents.Items[0].ReportingController).To(gomega.Equal(defaultSchedulerName))
})

ginkgo.It("Test pod with explicitly set default-scheduler is scheduled by the default-scheduler", func(ctx context.Context) {
const (
podName = "explicit-default-scheduler-test"
defaultSchedulerName = "default-scheduler"
)
_, err := f.VClusterClient.CoreV1().Pods(ns).Create(f.Context, &corev1.Pod{
ObjectMeta: metav1.ObjectMeta{Name: podName},
Spec: corev1.PodSpec{
Containers: []corev1.Container{
{
Name: testingContainerName,
Image: testingContainerImage,
ImagePullPolicy: corev1.PullIfNotPresent,
SecurityContext: f.GetDefaultSecurityContext(),
},
},
SchedulerName: defaultSchedulerName,
},
}, metav1.CreateOptions{})
framework.ExpectNoError(err)

err = f.WaitForPodRunning(podName, ns)
framework.ExpectNoError(err, "A pod created in the vcluster is expected to be in the Running phase eventually.")

eventsListOptions := metav1.ListOptions{
FieldSelector: "reason==Scheduled,involvedObject.name==" + podName,
}
scheduledEvents, err := f.VClusterClient.CoreV1().Events(ns).List(ctx, eventsListOptions)
framework.ExpectNoError(err)
gomega.Expect(scheduledEvents.Items).To(gomega.HaveLen(1))

// Assert that the default scheduler has scheduled the pod
gomega.Expect(scheduledEvents.Items[0].ReportingController).To(gomega.Equal(defaultSchedulerName))
})

ginkgo.It("Test pod starts successfully and readiness conditions are synced back to vcluster pod resource", func() {
podName := "test"
_, err := f.VClusterClient.CoreV1().Pods(ns).Create(f.Context, &corev1.Pod{
Expand Down
Loading