mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-09-06 19:52:42 +00:00
Finalize fields.Selector
This commit is contained in:
8
pkg/client/cache/listwatch.go
vendored
8
pkg/client/cache/listwatch.go
vendored
@@ -19,7 +19,7 @@ package cache
|
||||
import (
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/client"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/fields"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/watch"
|
||||
)
|
||||
@@ -39,12 +39,12 @@ type ListWatch struct {
|
||||
}
|
||||
|
||||
// NewListWatchFromClient creates a new ListWatch from the specified client, resource, namespace and field selector.
|
||||
func NewListWatchFromClient(c *client.Client, resource string, namespace string, fieldSelector labels.Selector) *ListWatch {
|
||||
func NewListWatchFromClient(c *client.Client, resource string, namespace string, fieldSelector fields.Selector) *ListWatch {
|
||||
listFunc := func() (runtime.Object, error) {
|
||||
return c.Get().Namespace(namespace).Resource(resource).SelectorParam(api.FieldSelectorQueryParam(c.APIVersion()), fieldSelector).Do().Get()
|
||||
return c.Get().Namespace(namespace).Resource(resource).FieldsSelectorParam(api.FieldSelectorQueryParam(c.APIVersion()), fieldSelector).Do().Get()
|
||||
}
|
||||
watchFunc := func(resourceVersion string) (watch.Interface, error) {
|
||||
return c.Get().Prefix("watch").Namespace(namespace).Resource(resource).SelectorParam(api.FieldSelectorQueryParam(c.APIVersion()), fieldSelector).Param("resourceVersion", resourceVersion).Watch()
|
||||
return c.Get().Prefix("watch").Namespace(namespace).Resource(resource).FieldsSelectorParam(api.FieldSelectorQueryParam(c.APIVersion()), fieldSelector).Param("resourceVersion", resourceVersion).Watch()
|
||||
}
|
||||
return &ListWatch{ListFunc: listFunc, WatchFunc: watchFunc}
|
||||
}
|
||||
|
18
pkg/client/cache/listwatch_test.go
vendored
18
pkg/client/cache/listwatch_test.go
vendored
@@ -25,12 +25,12 @@ import (
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/testapi"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/client"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/fields"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
|
||||
)
|
||||
|
||||
func parseSelectorOrDie(s string) labels.Selector {
|
||||
selector, err := labels.Parse(s)
|
||||
func parseSelectorOrDie(s string) fields.Selector {
|
||||
selector, err := fields.ParseSelector(s)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
@@ -82,7 +82,7 @@ func TestListWatchesCanList(t *testing.T) {
|
||||
location string
|
||||
resource string
|
||||
namespace string
|
||||
fieldSelector labels.Selector
|
||||
fieldSelector fields.Selector
|
||||
}{
|
||||
// Minion
|
||||
{
|
||||
@@ -96,14 +96,14 @@ func TestListWatchesCanList(t *testing.T) {
|
||||
location: buildLocation(buildResourcePath("", api.NamespaceAll, "pods"), buildQueryValues(api.NamespaceAll, url.Values{"fields": []string{getHostFieldLabel() + "="}})),
|
||||
resource: "pods",
|
||||
namespace: api.NamespaceAll,
|
||||
fieldSelector: labels.Set{getHostFieldLabel(): ""}.AsSelector(),
|
||||
fieldSelector: fields.Set{getHostFieldLabel(): ""}.AsSelector(),
|
||||
},
|
||||
// pod in namespace "foo"
|
||||
{
|
||||
location: buildLocation(buildResourcePath("", "foo", "pods"), buildQueryValues("foo", url.Values{"fields": []string{getHostFieldLabel() + "="}})),
|
||||
resource: "pods",
|
||||
namespace: "foo",
|
||||
fieldSelector: labels.Set{getHostFieldLabel(): ""}.AsSelector(),
|
||||
fieldSelector: fields.Set{getHostFieldLabel(): ""}.AsSelector(),
|
||||
},
|
||||
}
|
||||
for _, item := range table {
|
||||
@@ -128,7 +128,7 @@ func TestListWatchesCanWatch(t *testing.T) {
|
||||
location string
|
||||
resource string
|
||||
namespace string
|
||||
fieldSelector labels.Selector
|
||||
fieldSelector fields.Selector
|
||||
}{
|
||||
// Minion
|
||||
{
|
||||
@@ -151,7 +151,7 @@ func TestListWatchesCanWatch(t *testing.T) {
|
||||
rv: "0",
|
||||
resource: "pods",
|
||||
namespace: api.NamespaceAll,
|
||||
fieldSelector: labels.Set{getHostFieldLabel(): ""}.AsSelector(),
|
||||
fieldSelector: fields.Set{getHostFieldLabel(): ""}.AsSelector(),
|
||||
},
|
||||
// pod with namespace foo and assigned field selector
|
||||
{
|
||||
@@ -159,7 +159,7 @@ func TestListWatchesCanWatch(t *testing.T) {
|
||||
rv: "0",
|
||||
resource: "pods",
|
||||
namespace: "foo",
|
||||
fieldSelector: labels.Set{getHostFieldLabel(): ""}.AsSelector(),
|
||||
fieldSelector: fields.Set{getHostFieldLabel(): ""}.AsSelector(),
|
||||
},
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user