Skip to content
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

feat(sync): Add pod filter using FieldSelector #9493

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
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