Skip to content

Commit

Permalink
feat(sync): Add pod filter using FieldSelector (#9493)
Browse files Browse the repository at this point in the history
Signed-off-by: Suleiman Dibirov <[email protected]>
  • Loading branch information
idsulik authored Nov 15, 2024
1 parent 3f2e8df commit 08001f6
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 30 deletions.
8 changes: 3 additions & 5 deletions pkg/skaffold/sync/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
25 changes: 0 additions & 25 deletions pkg/skaffold/sync/sync_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 08001f6

Please sign in to comment.