diff --git a/pkg/skaffold/sync/sync.go b/pkg/skaffold/sync/sync.go index c89196e53c5..528133589ea 100644 --- a/pkg/skaffold/sync/sync.go +++ b/pkg/skaffold/sync/sync.go @@ -337,16 +337,14 @@ func Perform(ctx context.Context, image string, files syncMap, cmdFn func(contex numSynced := 0 for _, ns := range namespaces { - pods, err := client.CoreV1().Pods(ns).List(ctx, metav1.ListOptions{}) + pods, err := client.CoreV1().Pods(ns).List(ctx, metav1.ListOptions{ + FieldSelector: fmt.Sprintf("status.phase=%s", v1.PodRunning), + }) if err != nil { return fmt.Errorf("getting pods for namespace %q: %w", ns, err) } for _, p := range pods.Items { - if p.Status.Phase != v1.PodRunning { - continue - } - for _, c := range p.Spec.Containers { if c.Image != image { continue diff --git a/pkg/skaffold/sync/sync_test.go b/pkg/skaffold/sync/sync_test.go index 43078cc1346..6ed0baf1bb8 100644 --- a/pkg/skaffold/sync/sync_test.go +++ b/pkg/skaffold/sync/sync_test.go @@ -920,23 +920,6 @@ var pod = &v1.Pod{ }, } -var nonRunningPod = &v1.Pod{ - ObjectMeta: metav1.ObjectMeta{ - Name: "podname", - }, - Status: v1.PodStatus{ - Phase: v1.PodPending, - }, - Spec: v1.PodSpec{ - Containers: []v1.Container{ - { - Name: "container_name", - Image: "gcr.io/k8s-skaffold:123", - }, - }, - }, -} - func TestPerform(t *testing.T) { tests := []struct { description string @@ -983,14 +966,6 @@ func TestPerform(t *testing.T) { cmdFn: fakeCmd, shouldErr: true, }, - { - description: "Skip sync when pod is not running", - image: "gcr.io/k8s-skaffold:123", - files: syncMap{"test.go": {"/test.go"}}, - pod: nonRunningPod, - cmdFn: fakeCmd, - shouldErr: true, - }, } for _, test := range tests { testutil.Run(t, test.description, func(t *testutil.T) {