diff --git a/internal/runtime/kubernetes/resources_test.go b/internal/runtime/kubernetes/resources_test.go index daf8587..a383383 100644 --- a/internal/runtime/kubernetes/resources_test.go +++ b/internal/runtime/kubernetes/resources_test.go @@ -145,6 +145,23 @@ func TestPinPodToRuntimeNodeUsesRunningPVCConsumer(t *testing.T) { } } +func TestPinPodToRuntimeNodeUsesScheduledPendingPVCConsumer(t *testing.T) { + root := ref("druid", "druid-static-web-data") + runtimePod := runningProcedurePod("druid", root, "start", "coldstart", 1, "runtime-pod", "start-job") + runtimePod.Status.Phase = corev1.PodPending + runtimePod.Spec.Volumes = []corev1.Volume{pvcVolume("data", "druid-static-web-data")} + client := fake.NewSimpleClientset(runtimePod) + backend := NewWithClient(Config{Namespace: "druid"}, client) + + podSpec := corev1.PodSpec{} + if err := backend.pinPodToRuntimeNode(context.Background(), "druid", "druid-static-web-data", &podSpec); err != nil { + t.Fatal(err) + } + if got := podSpec.NodeSelector[corev1.LabelHostname]; got != "node-a" { + t.Fatalf("node selector = %q, want node-a", got) + } +} + func TestPinPodToRuntimeNodeIgnoresInactiveOrUnrelatedPods(t *testing.T) { root := ref("druid", "druid-static-web-data") inactive := runningProcedurePod("druid", root, "start", "start", 1, "inactive", "start-job") diff --git a/internal/runtime/kubernetes/scheduling.go b/internal/runtime/kubernetes/scheduling.go index 0a29224..abebcfc 100644 --- a/internal/runtime/kubernetes/scheduling.go +++ b/internal/runtime/kubernetes/scheduling.go @@ -33,7 +33,10 @@ func (b *Backend) runtimePVCNode(ctx context.Context, namespace string, pvc stri } for idx := range pods.Items { pod := &pods.Items[idx] - if pod.Status.Phase != corev1.PodRunning || pod.Spec.NodeName == "" || !podUsesPVC(pod, pvc) { + if pod.Status.Phase != corev1.PodPending && pod.Status.Phase != corev1.PodRunning { + continue + } + if pod.Spec.NodeName == "" || !podUsesPVC(pod, pvc) { continue } return pod.Spec.NodeName, nil