mirror of
https://github.com/k3s-io/kubernetes.git
synced 2026-01-29 21:29:24 +00:00
compute query parameter names in the client.
This commit is contained in:
15
pkg/client/cache/listwatch.go
vendored
15
pkg/client/cache/listwatch.go
vendored
@@ -17,7 +17,6 @@ limitations under the License.
|
||||
package cache
|
||||
|
||||
import (
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/client"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/fields"
|
||||
"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.
|
||||
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).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) {
|
||||
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}
|
||||
}
|
||||
|
||||
@@ -63,7 +63,7 @@ func (c *endpoints) List(selector labels.Selector) (result *api.EndpointsList, e
|
||||
err = c.r.Get().
|
||||
Namespace(c.ns).
|
||||
Resource("endpoints").
|
||||
LabelsSelectorParam(api.LabelSelectorQueryParam(c.r.APIVersion()), selector).
|
||||
LabelsSelectorParam(selector).
|
||||
Do().
|
||||
Into(result)
|
||||
return
|
||||
@@ -83,8 +83,8 @@ func (c *endpoints) Watch(label labels.Selector, field fields.Selector, resource
|
||||
Namespace(c.ns).
|
||||
Resource("endpoints").
|
||||
Param("resourceVersion", resourceVersion).
|
||||
LabelsSelectorParam(api.LabelSelectorQueryParam(c.r.APIVersion()), label).
|
||||
FieldsSelectorParam(api.FieldSelectorQueryParam(c.r.APIVersion()), field).
|
||||
LabelsSelectorParam(label).
|
||||
FieldsSelectorParam(field).
|
||||
Watch()
|
||||
}
|
||||
|
||||
|
||||
@@ -104,8 +104,8 @@ func (e *events) List(label labels.Selector, field fields.Selector) (*api.EventL
|
||||
err := e.client.Get().
|
||||
NamespaceIfScoped(e.namespace, len(e.namespace) > 0).
|
||||
Resource("events").
|
||||
LabelsSelectorParam(api.LabelSelectorQueryParam(e.client.APIVersion()), label).
|
||||
FieldsSelectorParam(api.FieldSelectorQueryParam(e.client.APIVersion()), field).
|
||||
LabelsSelectorParam(label).
|
||||
FieldsSelectorParam(field).
|
||||
Do().
|
||||
Into(result)
|
||||
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).
|
||||
Resource("events").
|
||||
Param("resourceVersion", resourceVersion).
|
||||
LabelsSelectorParam(api.LabelSelectorQueryParam(e.client.APIVersion()), label).
|
||||
FieldsSelectorParam(api.FieldSelectorQueryParam(e.client.APIVersion()), field).
|
||||
LabelsSelectorParam(label).
|
||||
FieldsSelectorParam(field).
|
||||
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.
|
||||
func (c *limitRanges) List(selector labels.Selector) (result *api.LimitRangeList, err error) {
|
||||
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
|
||||
}
|
||||
|
||||
@@ -98,7 +98,7 @@ func (c *limitRanges) Watch(label labels.Selector, field fields.Selector, resour
|
||||
Namespace(c.ns).
|
||||
Resource("limitRanges").
|
||||
Param("resourceVersion", resourceVersion).
|
||||
LabelsSelectorParam(api.LabelSelectorQueryParam(c.r.APIVersion()), label).
|
||||
FieldsSelectorParam(api.FieldSelectorQueryParam(c.r.APIVersion()), field).
|
||||
LabelsSelectorParam(label).
|
||||
FieldsSelectorParam(field).
|
||||
Watch()
|
||||
}
|
||||
|
||||
@@ -62,8 +62,8 @@ func (c *namespaces) List(label labels.Selector, field fields.Selector) (*api.Na
|
||||
result := &api.NamespaceList{}
|
||||
err := c.r.Get().
|
||||
Resource("namespaces").
|
||||
LabelsSelectorParam(api.LabelSelectorQueryParam(c.r.APIVersion()), label).
|
||||
FieldsSelectorParam(api.FieldSelectorQueryParam(c.r.APIVersion()), field).
|
||||
LabelsSelectorParam(label).
|
||||
FieldsSelectorParam(field).
|
||||
Do().Into(result)
|
||||
return result, err
|
||||
}
|
||||
@@ -119,7 +119,7 @@ func (c *namespaces) Watch(label labels.Selector, field fields.Selector, resourc
|
||||
Prefix("watch").
|
||||
Resource("namespaces").
|
||||
Param("resourceVersion", resourceVersion).
|
||||
LabelsSelectorParam(api.LabelSelectorQueryParam(c.r.APIVersion()), label).
|
||||
FieldsSelectorParam(api.FieldSelectorQueryParam(c.r.APIVersion()), field).
|
||||
LabelsSelectorParam(label).
|
||||
FieldsSelectorParam(field).
|
||||
Watch()
|
||||
}
|
||||
|
||||
@@ -101,7 +101,7 @@ func (c *nodes) Watch(label labels.Selector, field fields.Selector, resourceVers
|
||||
Namespace(api.NamespaceAll).
|
||||
Resource(c.resourceName()).
|
||||
Param("resourceVersion", resourceVersion).
|
||||
LabelsSelectorParam(api.LabelSelectorQueryParam(c.r.APIVersion()), label).
|
||||
FieldsSelectorParam(api.FieldSelectorQueryParam(c.r.APIVersion()), field).
|
||||
LabelsSelectorParam(label).
|
||||
FieldsSelectorParam(field).
|
||||
Watch()
|
||||
}
|
||||
|
||||
@@ -57,8 +57,8 @@ func (c *persistentVolumeClaims) List(label labels.Selector, field fields.Select
|
||||
err = c.client.Get().
|
||||
Namespace(c.namespace).
|
||||
Resource("persistentVolumeClaims").
|
||||
LabelsSelectorParam(api.LabelSelectorQueryParam(c.client.APIVersion()), label).
|
||||
FieldsSelectorParam(api.FieldSelectorQueryParam(c.client.APIVersion()), field).
|
||||
LabelsSelectorParam(label).
|
||||
FieldsSelectorParam(field).
|
||||
Do().
|
||||
Into(result)
|
||||
|
||||
@@ -97,7 +97,7 @@ func (c *persistentVolumeClaims) Watch(label labels.Selector, field fields.Selec
|
||||
Namespace(c.namespace).
|
||||
Resource("persistentVolumeClaims").
|
||||
Param("resourceVersion", resourceVersion).
|
||||
LabelsSelectorParam(api.LabelSelectorQueryParam(c.client.APIVersion()), label).
|
||||
FieldsSelectorParam(api.FieldSelectorQueryParam(c.client.APIVersion()), field).
|
||||
LabelsSelectorParam(label).
|
||||
FieldsSelectorParam(field).
|
||||
Watch()
|
||||
}
|
||||
|
||||
@@ -52,8 +52,8 @@ func (c *persistentVolumes) List(label labels.Selector, field fields.Selector) (
|
||||
result = &api.PersistentVolumeList{}
|
||||
err = c.client.Get().
|
||||
Resource("persistentVolumes").
|
||||
LabelsSelectorParam(api.LabelSelectorQueryParam(c.client.APIVersion()), label).
|
||||
FieldsSelectorParam(api.FieldSelectorQueryParam(c.client.APIVersion()), field).
|
||||
LabelsSelectorParam(label).
|
||||
FieldsSelectorParam(field).
|
||||
Do().
|
||||
Into(result)
|
||||
|
||||
@@ -91,7 +91,7 @@ func (c *persistentVolumes) Watch(label labels.Selector, field fields.Selector,
|
||||
Prefix("watch").
|
||||
Resource("persistentVolumes").
|
||||
Param("resourceVersion", resourceVersion).
|
||||
LabelsSelectorParam(api.LabelSelectorQueryParam(c.client.APIVersion()), label).
|
||||
FieldsSelectorParam(api.FieldSelectorQueryParam(c.client.APIVersion()), field).
|
||||
LabelsSelectorParam(label).
|
||||
FieldsSelectorParam(field).
|
||||
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.
|
||||
func (c *pods) List(selector labels.Selector) (result *api.PodList, err error) {
|
||||
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
|
||||
}
|
||||
|
||||
@@ -94,8 +94,8 @@ func (c *pods) Watch(label labels.Selector, field fields.Selector, resourceVersi
|
||||
Namespace(c.ns).
|
||||
Resource("pods").
|
||||
Param("resourceVersion", resourceVersion).
|
||||
LabelsSelectorParam(api.LabelSelectorQueryParam(c.r.APIVersion()), label).
|
||||
FieldsSelectorParam(api.LabelSelectorQueryParam(c.r.APIVersion()), field).
|
||||
LabelsSelectorParam(label).
|
||||
FieldsSelectorParam(field).
|
||||
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.
|
||||
func (c *replicationControllers) List(selector labels.Selector) (result *api.ReplicationControllerList, err error) {
|
||||
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
|
||||
}
|
||||
|
||||
@@ -89,7 +89,7 @@ func (c *replicationControllers) Watch(label labels.Selector, field fields.Selec
|
||||
Namespace(c.ns).
|
||||
Resource("replicationControllers").
|
||||
Param("resourceVersion", resourceVersion).
|
||||
LabelsSelectorParam(api.LabelSelectorQueryParam(c.r.APIVersion()), label).
|
||||
FieldsSelectorParam(api.FieldSelectorQueryParam(c.r.APIVersion()), field).
|
||||
LabelsSelectorParam(label).
|
||||
FieldsSelectorParam(field).
|
||||
Watch()
|
||||
}
|
||||
|
||||
@@ -110,10 +110,11 @@ func NewRequest(client HTTPClient, verb string, baseURL *url.URL, apiVersion str
|
||||
codec runtime.Codec, namespaceInQuery bool, preserveResourceCase bool) *Request {
|
||||
metrics.Register()
|
||||
return &Request{
|
||||
client: client,
|
||||
verb: verb,
|
||||
baseURL: baseURL,
|
||||
path: baseURL.Path,
|
||||
client: client,
|
||||
verb: verb,
|
||||
baseURL: baseURL,
|
||||
path: baseURL.Path,
|
||||
apiVersion: apiVersion,
|
||||
|
||||
codec: codec,
|
||||
namespaceInQuery: namespaceInQuery,
|
||||
@@ -247,6 +248,7 @@ func (r *Request) RequestURI(uri string) *Request {
|
||||
return r
|
||||
}
|
||||
|
||||
/*
|
||||
// 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
|
||||
// validly formatted selector.
|
||||
@@ -275,28 +277,28 @@ func (r *Request) ParseSelectorParam(paramName, item string) *Request {
|
||||
return r
|
||||
}
|
||||
return r.setParam(paramName, selector)
|
||||
}
|
||||
}*/
|
||||
|
||||
// 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 {
|
||||
return r
|
||||
}
|
||||
if s.Empty() {
|
||||
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
|
||||
func (r *Request) LabelsSelectorParam(paramName string, s labels.Selector) *Request {
|
||||
func (r *Request) LabelsSelectorParam(s labels.Selector) *Request {
|
||||
if r.err != nil {
|
||||
return r
|
||||
}
|
||||
if s.Empty() {
|
||||
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.
|
||||
|
||||
@@ -47,10 +47,13 @@ import (
|
||||
)
|
||||
|
||||
func TestRequestWithErrorWontChange(t *testing.T) {
|
||||
original := Request{err: errors.New("test")}
|
||||
original := Request{
|
||||
err: errors.New("test"),
|
||||
apiVersion: testapi.Version(),
|
||||
}
|
||||
r := original
|
||||
changed := r.Param("foo", "bar").
|
||||
LabelsSelectorParam(api.LabelSelectorQueryParam(testapi.Version()), labels.Set{"a": "b"}.AsSelector()).
|
||||
LabelsSelectorParam(labels.Set{"a": "b"}.AsSelector()).
|
||||
UintParam("uint", 1).
|
||||
AbsPath("/abs").
|
||||
Prefix("test").
|
||||
@@ -749,7 +752,7 @@ func TestDoRequestNewWayReader(t *testing.T) {
|
||||
Resource("bar").
|
||||
Name("baz").
|
||||
Prefix("foo").
|
||||
LabelsSelectorParam(api.LabelSelectorQueryParam(c.APIVersion()), labels.Set{"name": "foo"}.AsSelector()).
|
||||
LabelsSelectorParam(labels.Set{"name": "foo"}.AsSelector()).
|
||||
Timeout(time.Second).
|
||||
Body(bytes.NewBuffer(reqBodyExpected)).
|
||||
Do().Get()
|
||||
@@ -789,7 +792,7 @@ func TestDoRequestNewWayObj(t *testing.T) {
|
||||
Suffix("baz").
|
||||
Name("bar").
|
||||
Resource("foo").
|
||||
LabelsSelectorParam(api.LabelSelectorQueryParam(c.APIVersion()), labels.Set{"name": "foo"}.AsSelector()).
|
||||
LabelsSelectorParam(labels.Set{"name": "foo"}.AsSelector()).
|
||||
Timeout(time.Second).
|
||||
Body(reqObj).
|
||||
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.
|
||||
func (c *resourceQuotas) List(selector labels.Selector) (result *api.ResourceQuotaList, err error) {
|
||||
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
|
||||
}
|
||||
|
||||
@@ -100,7 +100,7 @@ func (c *resourceQuotas) Watch(label labels.Selector, field fields.Selector, res
|
||||
Namespace(c.ns).
|
||||
Resource("resourceQuotas").
|
||||
Param("resourceVersion", resourceVersion).
|
||||
LabelsSelectorParam(api.LabelSelectorQueryParam(c.r.APIVersion()), label).
|
||||
FieldsSelectorParam(api.FieldSelectorQueryParam(c.r.APIVersion()), field).
|
||||
LabelsSelectorParam(label).
|
||||
FieldsSelectorParam(field).
|
||||
Watch()
|
||||
}
|
||||
|
||||
@@ -69,8 +69,8 @@ func (s *secrets) List(label labels.Selector, field fields.Selector) (*api.Secre
|
||||
err := s.client.Get().
|
||||
Namespace(s.namespace).
|
||||
Resource("secrets").
|
||||
LabelsSelectorParam(api.LabelSelectorQueryParam(s.client.APIVersion()), label).
|
||||
FieldsSelectorParam(api.FieldSelectorQueryParam(s.client.APIVersion()), field).
|
||||
LabelsSelectorParam(label).
|
||||
FieldsSelectorParam(field).
|
||||
Do().
|
||||
Into(result)
|
||||
|
||||
@@ -97,8 +97,8 @@ func (s *secrets) Watch(label labels.Selector, field fields.Selector, resourceVe
|
||||
Namespace(s.namespace).
|
||||
Resource("secrets").
|
||||
Param("resourceVersion", resourceVersion).
|
||||
LabelsSelectorParam(api.LabelSelectorQueryParam(s.client.APIVersion()), label).
|
||||
FieldsSelectorParam(api.FieldSelectorQueryParam(s.client.APIVersion()), field).
|
||||
LabelsSelectorParam(label).
|
||||
FieldsSelectorParam(field).
|
||||
Watch()
|
||||
}
|
||||
|
||||
|
||||
@@ -61,7 +61,7 @@ func (c *services) List(selector labels.Selector) (result *api.ServiceList, err
|
||||
err = c.r.Get().
|
||||
Namespace(c.ns).
|
||||
Resource("services").
|
||||
LabelsSelectorParam(api.LabelSelectorQueryParam(c.r.APIVersion()), selector).
|
||||
LabelsSelectorParam(selector).
|
||||
Do().
|
||||
Into(result)
|
||||
return
|
||||
@@ -100,7 +100,7 @@ func (c *services) Watch(label labels.Selector, field fields.Selector, resourceV
|
||||
Namespace(c.ns).
|
||||
Resource("services").
|
||||
Param("resourceVersion", resourceVersion).
|
||||
LabelsSelectorParam(api.LabelSelectorQueryParam(c.r.APIVersion()), label).
|
||||
FieldsSelectorParam(api.FieldSelectorQueryParam(c.r.APIVersion()), field).
|
||||
LabelsSelectorParam(label).
|
||||
FieldsSelectorParam(field).
|
||||
Watch()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user