@@ -13,6 +13,7 @@ import (
13
13
"github.com/loft-sh/vcluster/pkg/util/translate"
14
14
"github.com/loft-sh/vcluster/test/framework"
15
15
"github.com/onsi/ginkgo/v2"
16
+ "github.com/onsi/gomega"
16
17
corev1 "k8s.io/api/core/v1"
17
18
kerrors "k8s.io/apimachinery/pkg/api/errors"
18
19
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -118,6 +119,75 @@ var _ = ginkgo.Describe("Pods are running in the host cluster", func() {
118
119
}
119
120
})
120
121
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
+
121
191
ginkgo .It ("Test pod starts successfully and readiness conditions are synced back to vcluster pod resource" , func () {
122
192
podName := "test"
123
193
_ , err := f .VClusterClient .CoreV1 ().Pods (ns ).Create (f .Context , & corev1.Pod {
0 commit comments