mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 03:41:45 +00:00
Merge pull request #6494 from lavalamp/fix2
compute query parameter names in the client.
This commit is contained in:
commit
0400339d01
15
pkg/client/cache/listwatch.go
vendored
15
pkg/client/cache/listwatch.go
vendored
@ -17,7 +17,6 @@ limitations under the License.
|
|||||||
package cache
|
package cache
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
|
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/client"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/client"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/fields"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/fields"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"
|
||||||
@ -41,10 +40,20 @@ type ListWatch struct {
|
|||||||
// NewListWatchFromClient creates a new ListWatch from the specified client, resource, namespace and field selector.
|
// NewListWatchFromClient creates a new ListWatch from the specified client, resource, namespace and field selector.
|
||||||
func NewListWatchFromClient(c *client.Client, resource string, namespace string, fieldSelector fields.Selector) *ListWatch {
|
func NewListWatchFromClient(c *client.Client, resource string, namespace string, fieldSelector fields.Selector) *ListWatch {
|
||||||
listFunc := func() (runtime.Object, error) {
|
listFunc := func() (runtime.Object, error) {
|
||||||
return c.Get().Namespace(namespace).Resource(resource).FieldsSelectorParam(api.FieldSelectorQueryParam(c.APIVersion()), fieldSelector).Do().Get()
|
return c.Get().
|
||||||
|
Namespace(namespace).
|
||||||
|
Resource(resource).
|
||||||
|
FieldsSelectorParam(fieldSelector).
|
||||||
|
Do().
|
||||||
|
Get()
|
||||||
}
|
}
|
||||||
watchFunc := func(resourceVersion string) (watch.Interface, error) {
|
watchFunc := func(resourceVersion string) (watch.Interface, error) {
|
||||||
return c.Get().Prefix("watch").Namespace(namespace).Resource(resource).FieldsSelectorParam(api.FieldSelectorQueryParam(c.APIVersion()), fieldSelector).Param("resourceVersion", resourceVersion).Watch()
|
return c.Get().
|
||||||
|
Prefix("watch").
|
||||||
|
Namespace(namespace).
|
||||||
|
Resource(resource).
|
||||||
|
FieldsSelectorParam(fieldSelector).
|
||||||
|
Param("resourceVersion", resourceVersion).Watch()
|
||||||
}
|
}
|
||||||
return &ListWatch{ListFunc: listFunc, WatchFunc: watchFunc}
|
return &ListWatch{ListFunc: listFunc, WatchFunc: watchFunc}
|
||||||
}
|
}
|
||||||
|
@ -63,7 +63,7 @@ func (c *endpoints) List(selector labels.Selector) (result *api.EndpointsList, e
|
|||||||
err = c.r.Get().
|
err = c.r.Get().
|
||||||
Namespace(c.ns).
|
Namespace(c.ns).
|
||||||
Resource("endpoints").
|
Resource("endpoints").
|
||||||
LabelsSelectorParam(api.LabelSelectorQueryParam(c.r.APIVersion()), selector).
|
LabelsSelectorParam(selector).
|
||||||
Do().
|
Do().
|
||||||
Into(result)
|
Into(result)
|
||||||
return
|
return
|
||||||
@ -83,8 +83,8 @@ func (c *endpoints) Watch(label labels.Selector, field fields.Selector, resource
|
|||||||
Namespace(c.ns).
|
Namespace(c.ns).
|
||||||
Resource("endpoints").
|
Resource("endpoints").
|
||||||
Param("resourceVersion", resourceVersion).
|
Param("resourceVersion", resourceVersion).
|
||||||
LabelsSelectorParam(api.LabelSelectorQueryParam(c.r.APIVersion()), label).
|
LabelsSelectorParam(label).
|
||||||
FieldsSelectorParam(api.FieldSelectorQueryParam(c.r.APIVersion()), field).
|
FieldsSelectorParam(field).
|
||||||
Watch()
|
Watch()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -104,8 +104,8 @@ func (e *events) List(label labels.Selector, field fields.Selector) (*api.EventL
|
|||||||
err := e.client.Get().
|
err := e.client.Get().
|
||||||
NamespaceIfScoped(e.namespace, len(e.namespace) > 0).
|
NamespaceIfScoped(e.namespace, len(e.namespace) > 0).
|
||||||
Resource("events").
|
Resource("events").
|
||||||
LabelsSelectorParam(api.LabelSelectorQueryParam(e.client.APIVersion()), label).
|
LabelsSelectorParam(label).
|
||||||
FieldsSelectorParam(api.FieldSelectorQueryParam(e.client.APIVersion()), field).
|
FieldsSelectorParam(field).
|
||||||
Do().
|
Do().
|
||||||
Into(result)
|
Into(result)
|
||||||
return result, err
|
return result, err
|
||||||
@ -130,8 +130,8 @@ func (e *events) Watch(label labels.Selector, field fields.Selector, resourceVer
|
|||||||
NamespaceIfScoped(e.namespace, len(e.namespace) > 0).
|
NamespaceIfScoped(e.namespace, len(e.namespace) > 0).
|
||||||
Resource("events").
|
Resource("events").
|
||||||
Param("resourceVersion", resourceVersion).
|
Param("resourceVersion", resourceVersion).
|
||||||
LabelsSelectorParam(api.LabelSelectorQueryParam(e.client.APIVersion()), label).
|
LabelsSelectorParam(label).
|
||||||
FieldsSelectorParam(api.FieldSelectorQueryParam(e.client.APIVersion()), field).
|
FieldsSelectorParam(field).
|
||||||
Watch()
|
Watch()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -57,7 +57,7 @@ func newLimitRanges(c *Client, namespace string) *limitRanges {
|
|||||||
// List takes a selector, and returns the list of limitRanges that match that selector.
|
// List takes a selector, and returns the list of limitRanges that match that selector.
|
||||||
func (c *limitRanges) List(selector labels.Selector) (result *api.LimitRangeList, err error) {
|
func (c *limitRanges) List(selector labels.Selector) (result *api.LimitRangeList, err error) {
|
||||||
result = &api.LimitRangeList{}
|
result = &api.LimitRangeList{}
|
||||||
err = c.r.Get().Namespace(c.ns).Resource("limitRanges").LabelsSelectorParam(api.LabelSelectorQueryParam(c.r.APIVersion()), selector).Do().Into(result)
|
err = c.r.Get().Namespace(c.ns).Resource("limitRanges").LabelsSelectorParam(selector).Do().Into(result)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -98,7 +98,7 @@ func (c *limitRanges) Watch(label labels.Selector, field fields.Selector, resour
|
|||||||
Namespace(c.ns).
|
Namespace(c.ns).
|
||||||
Resource("limitRanges").
|
Resource("limitRanges").
|
||||||
Param("resourceVersion", resourceVersion).
|
Param("resourceVersion", resourceVersion).
|
||||||
LabelsSelectorParam(api.LabelSelectorQueryParam(c.r.APIVersion()), label).
|
LabelsSelectorParam(label).
|
||||||
FieldsSelectorParam(api.FieldSelectorQueryParam(c.r.APIVersion()), field).
|
FieldsSelectorParam(field).
|
||||||
Watch()
|
Watch()
|
||||||
}
|
}
|
||||||
|
@ -62,8 +62,8 @@ func (c *namespaces) List(label labels.Selector, field fields.Selector) (*api.Na
|
|||||||
result := &api.NamespaceList{}
|
result := &api.NamespaceList{}
|
||||||
err := c.r.Get().
|
err := c.r.Get().
|
||||||
Resource("namespaces").
|
Resource("namespaces").
|
||||||
LabelsSelectorParam(api.LabelSelectorQueryParam(c.r.APIVersion()), label).
|
LabelsSelectorParam(label).
|
||||||
FieldsSelectorParam(api.FieldSelectorQueryParam(c.r.APIVersion()), field).
|
FieldsSelectorParam(field).
|
||||||
Do().Into(result)
|
Do().Into(result)
|
||||||
return result, err
|
return result, err
|
||||||
}
|
}
|
||||||
@ -119,7 +119,7 @@ func (c *namespaces) Watch(label labels.Selector, field fields.Selector, resourc
|
|||||||
Prefix("watch").
|
Prefix("watch").
|
||||||
Resource("namespaces").
|
Resource("namespaces").
|
||||||
Param("resourceVersion", resourceVersion).
|
Param("resourceVersion", resourceVersion).
|
||||||
LabelsSelectorParam(api.LabelSelectorQueryParam(c.r.APIVersion()), label).
|
LabelsSelectorParam(label).
|
||||||
FieldsSelectorParam(api.FieldSelectorQueryParam(c.r.APIVersion()), field).
|
FieldsSelectorParam(field).
|
||||||
Watch()
|
Watch()
|
||||||
}
|
}
|
||||||
|
@ -101,7 +101,7 @@ func (c *nodes) Watch(label labels.Selector, field fields.Selector, resourceVers
|
|||||||
Namespace(api.NamespaceAll).
|
Namespace(api.NamespaceAll).
|
||||||
Resource(c.resourceName()).
|
Resource(c.resourceName()).
|
||||||
Param("resourceVersion", resourceVersion).
|
Param("resourceVersion", resourceVersion).
|
||||||
LabelsSelectorParam(api.LabelSelectorQueryParam(c.r.APIVersion()), label).
|
LabelsSelectorParam(label).
|
||||||
FieldsSelectorParam(api.FieldSelectorQueryParam(c.r.APIVersion()), field).
|
FieldsSelectorParam(field).
|
||||||
Watch()
|
Watch()
|
||||||
}
|
}
|
||||||
|
@ -57,8 +57,8 @@ func (c *persistentVolumeClaims) List(label labels.Selector, field fields.Select
|
|||||||
err = c.client.Get().
|
err = c.client.Get().
|
||||||
Namespace(c.namespace).
|
Namespace(c.namespace).
|
||||||
Resource("persistentVolumeClaims").
|
Resource("persistentVolumeClaims").
|
||||||
LabelsSelectorParam(api.LabelSelectorQueryParam(c.client.APIVersion()), label).
|
LabelsSelectorParam(label).
|
||||||
FieldsSelectorParam(api.FieldSelectorQueryParam(c.client.APIVersion()), field).
|
FieldsSelectorParam(field).
|
||||||
Do().
|
Do().
|
||||||
Into(result)
|
Into(result)
|
||||||
|
|
||||||
@ -97,7 +97,7 @@ func (c *persistentVolumeClaims) Watch(label labels.Selector, field fields.Selec
|
|||||||
Namespace(c.namespace).
|
Namespace(c.namespace).
|
||||||
Resource("persistentVolumeClaims").
|
Resource("persistentVolumeClaims").
|
||||||
Param("resourceVersion", resourceVersion).
|
Param("resourceVersion", resourceVersion).
|
||||||
LabelsSelectorParam(api.LabelSelectorQueryParam(c.client.APIVersion()), label).
|
LabelsSelectorParam(label).
|
||||||
FieldsSelectorParam(api.FieldSelectorQueryParam(c.client.APIVersion()), field).
|
FieldsSelectorParam(field).
|
||||||
Watch()
|
Watch()
|
||||||
}
|
}
|
||||||
|
@ -52,8 +52,8 @@ func (c *persistentVolumes) List(label labels.Selector, field fields.Selector) (
|
|||||||
result = &api.PersistentVolumeList{}
|
result = &api.PersistentVolumeList{}
|
||||||
err = c.client.Get().
|
err = c.client.Get().
|
||||||
Resource("persistentVolumes").
|
Resource("persistentVolumes").
|
||||||
LabelsSelectorParam(api.LabelSelectorQueryParam(c.client.APIVersion()), label).
|
LabelsSelectorParam(label).
|
||||||
FieldsSelectorParam(api.FieldSelectorQueryParam(c.client.APIVersion()), field).
|
FieldsSelectorParam(field).
|
||||||
Do().
|
Do().
|
||||||
Into(result)
|
Into(result)
|
||||||
|
|
||||||
@ -91,7 +91,7 @@ func (c *persistentVolumes) Watch(label labels.Selector, field fields.Selector,
|
|||||||
Prefix("watch").
|
Prefix("watch").
|
||||||
Resource("persistentVolumes").
|
Resource("persistentVolumes").
|
||||||
Param("resourceVersion", resourceVersion).
|
Param("resourceVersion", resourceVersion).
|
||||||
LabelsSelectorParam(api.LabelSelectorQueryParam(c.client.APIVersion()), label).
|
LabelsSelectorParam(label).
|
||||||
FieldsSelectorParam(api.FieldSelectorQueryParam(c.client.APIVersion()), field).
|
FieldsSelectorParam(field).
|
||||||
Watch()
|
Watch()
|
||||||
}
|
}
|
||||||
|
@ -57,7 +57,7 @@ func newPods(c *Client, namespace string) *pods {
|
|||||||
// List takes a selector, and returns the list of pods that match that selector.
|
// List takes a selector, and returns the list of pods that match that selector.
|
||||||
func (c *pods) List(selector labels.Selector) (result *api.PodList, err error) {
|
func (c *pods) List(selector labels.Selector) (result *api.PodList, err error) {
|
||||||
result = &api.PodList{}
|
result = &api.PodList{}
|
||||||
err = c.r.Get().Namespace(c.ns).Resource("pods").LabelsSelectorParam(api.LabelSelectorQueryParam(c.r.APIVersion()), selector).Do().Into(result)
|
err = c.r.Get().Namespace(c.ns).Resource("pods").LabelsSelectorParam(selector).Do().Into(result)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -94,8 +94,8 @@ func (c *pods) Watch(label labels.Selector, field fields.Selector, resourceVersi
|
|||||||
Namespace(c.ns).
|
Namespace(c.ns).
|
||||||
Resource("pods").
|
Resource("pods").
|
||||||
Param("resourceVersion", resourceVersion).
|
Param("resourceVersion", resourceVersion).
|
||||||
LabelsSelectorParam(api.LabelSelectorQueryParam(c.r.APIVersion()), label).
|
LabelsSelectorParam(label).
|
||||||
FieldsSelectorParam(api.LabelSelectorQueryParam(c.r.APIVersion()), field).
|
FieldsSelectorParam(field).
|
||||||
Watch()
|
Watch()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -52,7 +52,7 @@ func newReplicationControllers(c *Client, namespace string) *replicationControll
|
|||||||
// List takes a selector, and returns the list of replication controllers that match that selector.
|
// List takes a selector, and returns the list of replication controllers that match that selector.
|
||||||
func (c *replicationControllers) List(selector labels.Selector) (result *api.ReplicationControllerList, err error) {
|
func (c *replicationControllers) List(selector labels.Selector) (result *api.ReplicationControllerList, err error) {
|
||||||
result = &api.ReplicationControllerList{}
|
result = &api.ReplicationControllerList{}
|
||||||
err = c.r.Get().Namespace(c.ns).Resource("replicationControllers").LabelsSelectorParam(api.LabelSelectorQueryParam(c.r.APIVersion()), selector).Do().Into(result)
|
err = c.r.Get().Namespace(c.ns).Resource("replicationControllers").LabelsSelectorParam(selector).Do().Into(result)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -89,7 +89,7 @@ func (c *replicationControllers) Watch(label labels.Selector, field fields.Selec
|
|||||||
Namespace(c.ns).
|
Namespace(c.ns).
|
||||||
Resource("replicationControllers").
|
Resource("replicationControllers").
|
||||||
Param("resourceVersion", resourceVersion).
|
Param("resourceVersion", resourceVersion).
|
||||||
LabelsSelectorParam(api.LabelSelectorQueryParam(c.r.APIVersion()), label).
|
LabelsSelectorParam(label).
|
||||||
FieldsSelectorParam(api.FieldSelectorQueryParam(c.r.APIVersion()), field).
|
FieldsSelectorParam(field).
|
||||||
Watch()
|
Watch()
|
||||||
}
|
}
|
||||||
|
@ -110,10 +110,11 @@ func NewRequest(client HTTPClient, verb string, baseURL *url.URL, apiVersion str
|
|||||||
codec runtime.Codec, namespaceInQuery bool, preserveResourceCase bool) *Request {
|
codec runtime.Codec, namespaceInQuery bool, preserveResourceCase bool) *Request {
|
||||||
metrics.Register()
|
metrics.Register()
|
||||||
return &Request{
|
return &Request{
|
||||||
client: client,
|
client: client,
|
||||||
verb: verb,
|
verb: verb,
|
||||||
baseURL: baseURL,
|
baseURL: baseURL,
|
||||||
path: baseURL.Path,
|
path: baseURL.Path,
|
||||||
|
apiVersion: apiVersion,
|
||||||
|
|
||||||
codec: codec,
|
codec: codec,
|
||||||
namespaceInQuery: namespaceInQuery,
|
namespaceInQuery: namespaceInQuery,
|
||||||
@ -247,6 +248,7 @@ func (r *Request) RequestURI(uri string) *Request {
|
|||||||
return r
|
return r
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
// ParseSelectorParam parses the given string as a resource selector.
|
// ParseSelectorParam parses the given string as a resource selector.
|
||||||
// This is a convenience function so you don't have to first check that it's a
|
// This is a convenience function so you don't have to first check that it's a
|
||||||
// validly formatted selector.
|
// validly formatted selector.
|
||||||
@ -275,28 +277,28 @@ func (r *Request) ParseSelectorParam(paramName, item string) *Request {
|
|||||||
return r
|
return r
|
||||||
}
|
}
|
||||||
return r.setParam(paramName, selector)
|
return r.setParam(paramName, selector)
|
||||||
}
|
}*/
|
||||||
|
|
||||||
// FieldsSelectorParam adds the given selector as a query parameter with the name paramName.
|
// FieldsSelectorParam adds the given selector as a query parameter with the name paramName.
|
||||||
func (r *Request) FieldsSelectorParam(paramName string, s fields.Selector) *Request {
|
func (r *Request) FieldsSelectorParam(s fields.Selector) *Request {
|
||||||
if r.err != nil {
|
if r.err != nil {
|
||||||
return r
|
return r
|
||||||
}
|
}
|
||||||
if s.Empty() {
|
if s.Empty() {
|
||||||
return r
|
return r
|
||||||
}
|
}
|
||||||
return r.setParam(paramName, s.String())
|
return r.setParam(api.FieldSelectorQueryParam(r.apiVersion), s.String())
|
||||||
}
|
}
|
||||||
|
|
||||||
// LabelsSelectorParam adds the given selector as a query parameter
|
// LabelsSelectorParam adds the given selector as a query parameter
|
||||||
func (r *Request) LabelsSelectorParam(paramName string, s labels.Selector) *Request {
|
func (r *Request) LabelsSelectorParam(s labels.Selector) *Request {
|
||||||
if r.err != nil {
|
if r.err != nil {
|
||||||
return r
|
return r
|
||||||
}
|
}
|
||||||
if s.Empty() {
|
if s.Empty() {
|
||||||
return r
|
return r
|
||||||
}
|
}
|
||||||
return r.setParam(paramName, s.String())
|
return r.setParam(api.LabelSelectorQueryParam(r.apiVersion), s.String())
|
||||||
}
|
}
|
||||||
|
|
||||||
// UintParam creates a query parameter with the given value.
|
// UintParam creates a query parameter with the given value.
|
||||||
|
@ -47,10 +47,13 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func TestRequestWithErrorWontChange(t *testing.T) {
|
func TestRequestWithErrorWontChange(t *testing.T) {
|
||||||
original := Request{err: errors.New("test")}
|
original := Request{
|
||||||
|
err: errors.New("test"),
|
||||||
|
apiVersion: testapi.Version(),
|
||||||
|
}
|
||||||
r := original
|
r := original
|
||||||
changed := r.Param("foo", "bar").
|
changed := r.Param("foo", "bar").
|
||||||
LabelsSelectorParam(api.LabelSelectorQueryParam(testapi.Version()), labels.Set{"a": "b"}.AsSelector()).
|
LabelsSelectorParam(labels.Set{"a": "b"}.AsSelector()).
|
||||||
UintParam("uint", 1).
|
UintParam("uint", 1).
|
||||||
AbsPath("/abs").
|
AbsPath("/abs").
|
||||||
Prefix("test").
|
Prefix("test").
|
||||||
@ -749,7 +752,7 @@ func TestDoRequestNewWayReader(t *testing.T) {
|
|||||||
Resource("bar").
|
Resource("bar").
|
||||||
Name("baz").
|
Name("baz").
|
||||||
Prefix("foo").
|
Prefix("foo").
|
||||||
LabelsSelectorParam(api.LabelSelectorQueryParam(c.APIVersion()), labels.Set{"name": "foo"}.AsSelector()).
|
LabelsSelectorParam(labels.Set{"name": "foo"}.AsSelector()).
|
||||||
Timeout(time.Second).
|
Timeout(time.Second).
|
||||||
Body(bytes.NewBuffer(reqBodyExpected)).
|
Body(bytes.NewBuffer(reqBodyExpected)).
|
||||||
Do().Get()
|
Do().Get()
|
||||||
@ -789,7 +792,7 @@ func TestDoRequestNewWayObj(t *testing.T) {
|
|||||||
Suffix("baz").
|
Suffix("baz").
|
||||||
Name("bar").
|
Name("bar").
|
||||||
Resource("foo").
|
Resource("foo").
|
||||||
LabelsSelectorParam(api.LabelSelectorQueryParam(c.APIVersion()), labels.Set{"name": "foo"}.AsSelector()).
|
LabelsSelectorParam(labels.Set{"name": "foo"}.AsSelector()).
|
||||||
Timeout(time.Second).
|
Timeout(time.Second).
|
||||||
Body(reqObj).
|
Body(reqObj).
|
||||||
Do().Get()
|
Do().Get()
|
||||||
|
@ -56,7 +56,7 @@ func newResourceQuotas(c *Client, namespace string) *resourceQuotas {
|
|||||||
// List takes a selector, and returns the list of resourceQuotas that match that selector.
|
// List takes a selector, and returns the list of resourceQuotas that match that selector.
|
||||||
func (c *resourceQuotas) List(selector labels.Selector) (result *api.ResourceQuotaList, err error) {
|
func (c *resourceQuotas) List(selector labels.Selector) (result *api.ResourceQuotaList, err error) {
|
||||||
result = &api.ResourceQuotaList{}
|
result = &api.ResourceQuotaList{}
|
||||||
err = c.r.Get().Namespace(c.ns).Resource("resourceQuotas").LabelsSelectorParam(api.LabelSelectorQueryParam(c.r.APIVersion()), selector).Do().Into(result)
|
err = c.r.Get().Namespace(c.ns).Resource("resourceQuotas").LabelsSelectorParam(selector).Do().Into(result)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -100,7 +100,7 @@ func (c *resourceQuotas) Watch(label labels.Selector, field fields.Selector, res
|
|||||||
Namespace(c.ns).
|
Namespace(c.ns).
|
||||||
Resource("resourceQuotas").
|
Resource("resourceQuotas").
|
||||||
Param("resourceVersion", resourceVersion).
|
Param("resourceVersion", resourceVersion).
|
||||||
LabelsSelectorParam(api.LabelSelectorQueryParam(c.r.APIVersion()), label).
|
LabelsSelectorParam(label).
|
||||||
FieldsSelectorParam(api.FieldSelectorQueryParam(c.r.APIVersion()), field).
|
FieldsSelectorParam(field).
|
||||||
Watch()
|
Watch()
|
||||||
}
|
}
|
||||||
|
@ -69,8 +69,8 @@ func (s *secrets) List(label labels.Selector, field fields.Selector) (*api.Secre
|
|||||||
err := s.client.Get().
|
err := s.client.Get().
|
||||||
Namespace(s.namespace).
|
Namespace(s.namespace).
|
||||||
Resource("secrets").
|
Resource("secrets").
|
||||||
LabelsSelectorParam(api.LabelSelectorQueryParam(s.client.APIVersion()), label).
|
LabelsSelectorParam(label).
|
||||||
FieldsSelectorParam(api.FieldSelectorQueryParam(s.client.APIVersion()), field).
|
FieldsSelectorParam(field).
|
||||||
Do().
|
Do().
|
||||||
Into(result)
|
Into(result)
|
||||||
|
|
||||||
@ -97,8 +97,8 @@ func (s *secrets) Watch(label labels.Selector, field fields.Selector, resourceVe
|
|||||||
Namespace(s.namespace).
|
Namespace(s.namespace).
|
||||||
Resource("secrets").
|
Resource("secrets").
|
||||||
Param("resourceVersion", resourceVersion).
|
Param("resourceVersion", resourceVersion).
|
||||||
LabelsSelectorParam(api.LabelSelectorQueryParam(s.client.APIVersion()), label).
|
LabelsSelectorParam(label).
|
||||||
FieldsSelectorParam(api.FieldSelectorQueryParam(s.client.APIVersion()), field).
|
FieldsSelectorParam(field).
|
||||||
Watch()
|
Watch()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -61,7 +61,7 @@ func (c *services) List(selector labels.Selector) (result *api.ServiceList, err
|
|||||||
err = c.r.Get().
|
err = c.r.Get().
|
||||||
Namespace(c.ns).
|
Namespace(c.ns).
|
||||||
Resource("services").
|
Resource("services").
|
||||||
LabelsSelectorParam(api.LabelSelectorQueryParam(c.r.APIVersion()), selector).
|
LabelsSelectorParam(selector).
|
||||||
Do().
|
Do().
|
||||||
Into(result)
|
Into(result)
|
||||||
return
|
return
|
||||||
@ -100,7 +100,7 @@ func (c *services) Watch(label labels.Selector, field fields.Selector, resourceV
|
|||||||
Namespace(c.ns).
|
Namespace(c.ns).
|
||||||
Resource("services").
|
Resource("services").
|
||||||
Param("resourceVersion", resourceVersion).
|
Param("resourceVersion", resourceVersion).
|
||||||
LabelsSelectorParam(api.LabelSelectorQueryParam(c.r.APIVersion()), label).
|
LabelsSelectorParam(label).
|
||||||
FieldsSelectorParam(api.FieldSelectorQueryParam(c.r.APIVersion()), field).
|
FieldsSelectorParam(field).
|
||||||
Watch()
|
Watch()
|
||||||
}
|
}
|
||||||
|
@ -22,6 +22,8 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
|
||||||
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/testapi"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/client"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/client"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -187,12 +189,12 @@ func TestDeleteMultipleSelector(t *testing.T) {
|
|||||||
Client: client.HTTPClientFunc(func(req *http.Request) (*http.Response, error) {
|
Client: client.HTTPClientFunc(func(req *http.Request) (*http.Response, error) {
|
||||||
switch p, m := req.URL.Path, req.Method; {
|
switch p, m := req.URL.Path, req.Method; {
|
||||||
case p == "/namespaces/test/pods" && m == "GET":
|
case p == "/namespaces/test/pods" && m == "GET":
|
||||||
if req.URL.Query().Get("labels") != "a=b" {
|
if req.URL.Query().Get(api.LabelSelectorQueryParam(testapi.Version())) != "a=b" {
|
||||||
t.Fatalf("unexpected request: %#v\n%#v", req.URL, req)
|
t.Fatalf("unexpected request: %#v\n%#v", req.URL, req)
|
||||||
}
|
}
|
||||||
return &http.Response{StatusCode: 200, Body: objBody(codec, pods)}, nil
|
return &http.Response{StatusCode: 200, Body: objBody(codec, pods)}, nil
|
||||||
case p == "/namespaces/test/services" && m == "GET":
|
case p == "/namespaces/test/services" && m == "GET":
|
||||||
if req.URL.Query().Get("labels") != "a=b" {
|
if req.URL.Query().Get(api.LabelSelectorQueryParam(testapi.Version())) != "a=b" {
|
||||||
t.Fatalf("unexpected request: %#v\n%#v", req.URL, req)
|
t.Fatalf("unexpected request: %#v\n%#v", req.URL, req)
|
||||||
}
|
}
|
||||||
return &http.Response{StatusCode: 200, Body: objBody(codec, svc)}, nil
|
return &http.Response{StatusCode: 200, Body: objBody(codec, svc)}, nil
|
||||||
|
@ -28,6 +28,7 @@ import (
|
|||||||
|
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/latest"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/latest"
|
||||||
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/testapi"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/client"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/client"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
|
||||||
@ -280,7 +281,7 @@ func TestGetMultipleTypeObjectsWithSelector(t *testing.T) {
|
|||||||
tf.Client = &client.FakeRESTClient{
|
tf.Client = &client.FakeRESTClient{
|
||||||
Codec: codec,
|
Codec: codec,
|
||||||
Client: client.HTTPClientFunc(func(req *http.Request) (*http.Response, error) {
|
Client: client.HTTPClientFunc(func(req *http.Request) (*http.Response, error) {
|
||||||
if req.URL.Query().Get("labels") != "a=b" {
|
if req.URL.Query().Get(api.LabelSelectorQueryParam(testapi.Version())) != "a=b" {
|
||||||
t.Fatalf("unexpected request: %#v\n%#v", req.URL, req)
|
t.Fatalf("unexpected request: %#v\n%#v", req.URL, req)
|
||||||
}
|
}
|
||||||
switch req.URL.Path {
|
switch req.URL.Path {
|
||||||
@ -412,7 +413,7 @@ func TestWatchSelector(t *testing.T) {
|
|||||||
tf.Client = &client.FakeRESTClient{
|
tf.Client = &client.FakeRESTClient{
|
||||||
Codec: codec,
|
Codec: codec,
|
||||||
Client: client.HTTPClientFunc(func(req *http.Request) (*http.Response, error) {
|
Client: client.HTTPClientFunc(func(req *http.Request) (*http.Response, error) {
|
||||||
if req.URL.Query().Get("labels") != "a=b" {
|
if req.URL.Query().Get(api.LabelSelectorQueryParam(testapi.Version())) != "a=b" {
|
||||||
t.Fatalf("unexpected request: %#v\n%#v", req.URL, req)
|
t.Fatalf("unexpected request: %#v\n%#v", req.URL, req)
|
||||||
}
|
}
|
||||||
switch req.URL.Path {
|
switch req.URL.Path {
|
||||||
|
@ -31,6 +31,7 @@ import (
|
|||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/latest"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/latest"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/meta"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/meta"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/resource"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/resource"
|
||||||
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/testapi"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/client"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/client"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/util/errors"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/util/errors"
|
||||||
@ -364,9 +365,10 @@ func TestResourceByNameAndEmptySelector(t *testing.T) {
|
|||||||
|
|
||||||
func TestSelector(t *testing.T) {
|
func TestSelector(t *testing.T) {
|
||||||
pods, svc := testData()
|
pods, svc := testData()
|
||||||
|
labelKey := api.LabelSelectorQueryParam(testapi.Version())
|
||||||
b := NewBuilder(latest.RESTMapper, api.Scheme, fakeClientWith(t, map[string]string{
|
b := NewBuilder(latest.RESTMapper, api.Scheme, fakeClientWith(t, map[string]string{
|
||||||
"/namespaces/test/pods?labels=a%3Db": runtime.EncodeOrDie(latest.Codec, pods),
|
"/namespaces/test/pods?" + labelKey + "=a%3Db": runtime.EncodeOrDie(latest.Codec, pods),
|
||||||
"/namespaces/test/services?labels=a%3Db": runtime.EncodeOrDie(latest.Codec, svc),
|
"/namespaces/test/services?" + labelKey + "=a%3Db": runtime.EncodeOrDie(latest.Codec, svc),
|
||||||
})).
|
})).
|
||||||
SelectorParam("a=b").
|
SelectorParam("a=b").
|
||||||
NamespaceParam("test").
|
NamespaceParam("test").
|
||||||
@ -576,8 +578,9 @@ func TestSingularObject(t *testing.T) {
|
|||||||
|
|
||||||
func TestListObject(t *testing.T) {
|
func TestListObject(t *testing.T) {
|
||||||
pods, _ := testData()
|
pods, _ := testData()
|
||||||
|
labelKey := api.LabelSelectorQueryParam(testapi.Version())
|
||||||
b := NewBuilder(latest.RESTMapper, api.Scheme, fakeClientWith(t, map[string]string{
|
b := NewBuilder(latest.RESTMapper, api.Scheme, fakeClientWith(t, map[string]string{
|
||||||
"/namespaces/test/pods?labels=a%3Db": runtime.EncodeOrDie(latest.Codec, pods),
|
"/namespaces/test/pods?" + labelKey + "=a%3Db": runtime.EncodeOrDie(latest.Codec, pods),
|
||||||
})).
|
})).
|
||||||
SelectorParam("a=b").
|
SelectorParam("a=b").
|
||||||
NamespaceParam("test").
|
NamespaceParam("test").
|
||||||
@ -608,9 +611,10 @@ func TestListObject(t *testing.T) {
|
|||||||
|
|
||||||
func TestListObjectWithDifferentVersions(t *testing.T) {
|
func TestListObjectWithDifferentVersions(t *testing.T) {
|
||||||
pods, svc := testData()
|
pods, svc := testData()
|
||||||
|
labelKey := api.LabelSelectorQueryParam(testapi.Version())
|
||||||
obj, err := NewBuilder(latest.RESTMapper, api.Scheme, fakeClientWith(t, map[string]string{
|
obj, err := NewBuilder(latest.RESTMapper, api.Scheme, fakeClientWith(t, map[string]string{
|
||||||
"/namespaces/test/pods?labels=a%3Db": runtime.EncodeOrDie(latest.Codec, pods),
|
"/namespaces/test/pods?" + labelKey + "=a%3Db": runtime.EncodeOrDie(latest.Codec, pods),
|
||||||
"/namespaces/test/services?labels=a%3Db": runtime.EncodeOrDie(latest.Codec, svc),
|
"/namespaces/test/services?" + labelKey + "=a%3Db": runtime.EncodeOrDie(latest.Codec, svc),
|
||||||
})).
|
})).
|
||||||
SelectorParam("a=b").
|
SelectorParam("a=b").
|
||||||
NamespaceParam("test").
|
NamespaceParam("test").
|
||||||
|
@ -17,7 +17,6 @@ limitations under the License.
|
|||||||
package resource
|
package resource
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
|
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/meta"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/meta"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/fields"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/fields"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels"
|
||||||
@ -30,7 +29,7 @@ import (
|
|||||||
type Helper struct {
|
type Helper struct {
|
||||||
// The name of this resource as the server would recognize it
|
// The name of this resource as the server would recognize it
|
||||||
Resource string
|
Resource string
|
||||||
// A RESTClient capable of mutating this resource
|
// A RESTClient capable of mutating this resource.
|
||||||
RESTClient RESTClient
|
RESTClient RESTClient
|
||||||
// A codec for decoding and encoding objects of this resource type.
|
// A codec for decoding and encoding objects of this resource type.
|
||||||
Codec runtime.Codec
|
Codec runtime.Codec
|
||||||
@ -62,11 +61,12 @@ func (m *Helper) Get(namespace, name string) (runtime.Object, error) {
|
|||||||
Get()
|
Get()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: add field selector
|
||||||
func (m *Helper) List(namespace, apiVersion string, selector labels.Selector) (runtime.Object, error) {
|
func (m *Helper) List(namespace, apiVersion string, selector labels.Selector) (runtime.Object, error) {
|
||||||
return m.RESTClient.Get().
|
return m.RESTClient.Get().
|
||||||
NamespaceIfScoped(namespace, m.NamespaceScoped).
|
NamespaceIfScoped(namespace, m.NamespaceScoped).
|
||||||
Resource(m.Resource).
|
Resource(m.Resource).
|
||||||
LabelsSelectorParam(api.LabelSelectorQueryParam(apiVersion), selector).
|
LabelsSelectorParam(selector).
|
||||||
Do().
|
Do().
|
||||||
Get()
|
Get()
|
||||||
}
|
}
|
||||||
@ -77,8 +77,8 @@ func (m *Helper) Watch(namespace, resourceVersion, apiVersion string, labelSelec
|
|||||||
NamespaceIfScoped(namespace, m.NamespaceScoped).
|
NamespaceIfScoped(namespace, m.NamespaceScoped).
|
||||||
Resource(m.Resource).
|
Resource(m.Resource).
|
||||||
Param("resourceVersion", resourceVersion).
|
Param("resourceVersion", resourceVersion).
|
||||||
LabelsSelectorParam(api.LabelSelectorQueryParam(apiVersion), labelSelector).
|
LabelsSelectorParam(labelSelector).
|
||||||
FieldsSelectorParam(api.FieldSelectorQueryParam(apiVersion), fieldSelector).
|
FieldsSelectorParam(fieldSelector).
|
||||||
Watch()
|
Watch()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user