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

Fake client doesn't limit results #793

Closed
sagikazarmark opened this issue Apr 27, 2020 · 4 comments
Closed

Fake client doesn't limit results #793

sagikazarmark opened this issue Apr 27, 2020 · 4 comments

Comments

@sagikazarmark
Copy link

sagikazarmark commented Apr 27, 2020

As the title says, the fake client ignores the Limit parameter in a list operation:

package fake_test

import (
	"context"
	"testing"

	"k8s.io/api/core/v1"
	metaV1 "k8s.io/apimachinery/pkg/apis/meta/v1"
	"k8s.io/client-go/kubernetes/fake"
)

func TestPodLimit(t *testing.T) {
	client := fake.NewSimpleClientset(
		&v1.Pod{
			TypeMeta: metaV1.TypeMeta{Kind: "Pod", APIVersion: "v1"},
			ObjectMeta: metaV1.ObjectMeta{
				Name:      "my-pod-1",
				Namespace: "default",
			},
		},
		&v1.Pod{
			TypeMeta: metaV1.TypeMeta{Kind: "Pod", APIVersion: "v1"},
			ObjectMeta: metaV1.ObjectMeta{
				Name:      "my-pod-2",
				Namespace: "default",
			},
		},
	)

	podList, _ := client.CoreV1().Pods("default").List(context.Background(), metaV1.ListOptions{Limit: 1})
	if len(podList.Items) > 1 {
		t.Errorf("expected one items in podList, got %d", len(podList.Items))
	}
}

Feels like it would be a trivial thing to implement, since slices are ordered in Go it would probably even be consistent enough so that tests could safely rely on the behavior.

@liggitt
Copy link
Member

liggitt commented Apr 27, 2020

I'd tend to put this on this list of server-side behaviors that are not replicated by the client fake

@sagikazarmark
Copy link
Author

Why? sounds like a trivial thing to me.

@liggitt
Copy link
Member

liggitt commented Apr 28, 2020

generating continue tokens and serving coherent sublists for a given resourceVersion is a fundamental part of returning paged lists. Simply returning a partial list without doing those other things (which the resource tracker doesn't have the info to do) is worse than returning a full list (which is permitted by the API definition and which clients must be prepared to handle)

@sagikazarmark
Copy link
Author

Thanks for the explanation, makes sense.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants