mirror of https://github.com/k3s-io/k3s
Make label and field selector query strings versionable.
parent
0aee25e065
commit
266234f3b9
|
@ -30,3 +30,22 @@ type APIVersions struct {
|
||||||
type RootPaths struct {
|
type RootPaths struct {
|
||||||
Paths []string `json:"paths"`
|
Paths []string `json:"paths"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// preV1Beta3 returns true if the provided API version is an API introduced before v1beta3.
|
||||||
|
func PreV1Beta3(version string) bool {
|
||||||
|
return version == "v1beta1" || version == "v1beta2"
|
||||||
|
}
|
||||||
|
|
||||||
|
func LabelSelectorQueryParam(version string) string {
|
||||||
|
if PreV1Beta3(version) {
|
||||||
|
return "labels"
|
||||||
|
}
|
||||||
|
return "label-selector"
|
||||||
|
}
|
||||||
|
|
||||||
|
func FieldSelectorQueryParam(version string) string {
|
||||||
|
if PreV1Beta3(version) {
|
||||||
|
return "fields"
|
||||||
|
}
|
||||||
|
return "field-selector"
|
||||||
|
}
|
||||||
|
|
|
@ -84,7 +84,7 @@ func GetResource(r RESTGetter, ctxFn ContextFunc, namer ScopeNamer, codec runtim
|
||||||
}
|
}
|
||||||
|
|
||||||
func parseSelectorQueryParams(query url.Values, version, apiResource string) (label labels.Selector, field fields.Selector, err error) {
|
func parseSelectorQueryParams(query url.Values, version, apiResource string) (label labels.Selector, field fields.Selector, err error) {
|
||||||
labelString := query.Get("labels")
|
labelString := query.Get(api.LabelSelectorQueryParam(version))
|
||||||
label, err = labels.Parse(labelString)
|
label, err = labels.Parse(labelString)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, errors.NewBadRequest(fmt.Sprintf("The 'labels' selector parameter (%s) could not be parsed: %v", labelString, err))
|
return nil, nil, errors.NewBadRequest(fmt.Sprintf("The 'labels' selector parameter (%s) could not be parsed: %v", labelString, err))
|
||||||
|
@ -93,7 +93,7 @@ func parseSelectorQueryParams(query url.Values, version, apiResource string) (la
|
||||||
convertToInternalVersionFunc := func(label, value string) (newLabel, newValue string, err error) {
|
convertToInternalVersionFunc := func(label, value string) (newLabel, newValue string, err error) {
|
||||||
return api.Scheme.ConvertFieldLabel(version, apiResource, label, value)
|
return api.Scheme.ConvertFieldLabel(version, apiResource, label, value)
|
||||||
}
|
}
|
||||||
fieldString := query.Get("fields")
|
fieldString := query.Get(api.FieldSelectorQueryParam(version))
|
||||||
field, err = fields.ParseAndTransformSelector(fieldString, convertToInternalVersionFunc)
|
field, err = fields.ParseAndTransformSelector(fieldString, convertToInternalVersionFunc)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, errors.NewBadRequest(fmt.Sprintf("The 'fields' selector parameter (%s) could not be parsed: %v", fieldString, err))
|
return nil, nil, errors.NewBadRequest(fmt.Sprintf("The 'fields' selector parameter (%s) could not be parsed: %v", fieldString, err))
|
||||||
|
|
|
@ -188,13 +188,13 @@ func TestWatchParamParsing(t *testing.T) {
|
||||||
fieldSelector: "",
|
fieldSelector: "",
|
||||||
namespace: api.NamespaceAll,
|
namespace: api.NamespaceAll,
|
||||||
}, {
|
}, {
|
||||||
rawQuery: "namespace=default&resourceVersion=314159&fields=Host%3D&labels=name%3Dfoo",
|
rawQuery: "namespace=default&resourceVersion=314159&" + api.FieldSelectorQueryParam(testVersion) + "=Host%3D&" + api.LabelSelectorQueryParam(testVersion) + "=name%3Dfoo",
|
||||||
resourceVersion: "314159",
|
resourceVersion: "314159",
|
||||||
labelSelector: "name=foo",
|
labelSelector: "name=foo",
|
||||||
fieldSelector: "Host=",
|
fieldSelector: "Host=",
|
||||||
namespace: api.NamespaceDefault,
|
namespace: api.NamespaceDefault,
|
||||||
}, {
|
}, {
|
||||||
rawQuery: "namespace=watchother&fields=id%3dfoo&resourceVersion=1492",
|
rawQuery: "namespace=watchother&" + api.FieldSelectorQueryParam(testVersion) + "=id%3dfoo&resourceVersion=1492",
|
||||||
resourceVersion: "1492",
|
resourceVersion: "1492",
|
||||||
labelSelector: "",
|
labelSelector: "",
|
||||||
fieldSelector: "id=foo",
|
fieldSelector: "id=foo",
|
||||||
|
|
|
@ -17,6 +17,7 @@ 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/labels"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"
|
||||||
|
@ -38,12 +39,12 @@ 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(client *client.Client, resource string, namespace string, fieldSelector labels.Selector) *ListWatch {
|
func NewListWatchFromClient(c *client.Client, resource string, namespace string, fieldSelector labels.Selector) *ListWatch {
|
||||||
listFunc := func() (runtime.Object, error) {
|
listFunc := func() (runtime.Object, error) {
|
||||||
return client.Get().Namespace(namespace).Resource(resource).SelectorParam("fields", fieldSelector).Do().Get()
|
return c.Get().Namespace(namespace).Resource(resource).SelectorParam(api.FieldSelectorQueryParam(c.APIVersion()), fieldSelector).Do().Get()
|
||||||
}
|
}
|
||||||
watchFunc := func(resourceVersion string) (watch.Interface, error) {
|
watchFunc := func(resourceVersion string) (watch.Interface, error) {
|
||||||
return client.Get().Prefix("watch").Namespace(namespace).Resource(resource).SelectorParam("fields", fieldSelector).Param("resourceVersion", resourceVersion).Watch()
|
return c.Get().Prefix("watch").Namespace(namespace).Resource(resource).SelectorParam(api.FieldSelectorQueryParam(c.APIVersion()), fieldSelector).Param("resourceVersion", resourceVersion).Watch()
|
||||||
}
|
}
|
||||||
return &ListWatch{ListFunc: listFunc, WatchFunc: watchFunc}
|
return &ListWatch{ListFunc: listFunc, WatchFunc: watchFunc}
|
||||||
}
|
}
|
||||||
|
|
|
@ -154,8 +154,3 @@ func IsTimeout(err error) bool {
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
// preV1Beta3 returns true if the provided API version is an API introduced before v1beta3.
|
|
||||||
func preV1Beta3(version string) bool {
|
|
||||||
return version == "v1beta1" || version == "v1beta2"
|
|
||||||
}
|
|
||||||
|
|
|
@ -60,7 +60,12 @@ func (c *endpoints) Create(endpoints *api.Endpoints) (*api.Endpoints, error) {
|
||||||
// List takes a selector, and returns the list of endpoints that match that selector
|
// List takes a selector, and returns the list of endpoints that match that selector
|
||||||
func (c *endpoints) List(selector labels.Selector) (result *api.EndpointsList, err error) {
|
func (c *endpoints) List(selector labels.Selector) (result *api.EndpointsList, err error) {
|
||||||
result = &api.EndpointsList{}
|
result = &api.EndpointsList{}
|
||||||
err = c.r.Get().Namespace(c.ns).Resource("endpoints").SelectorParam("labels", selector).Do().Into(result)
|
err = c.r.Get().
|
||||||
|
Namespace(c.ns).
|
||||||
|
Resource("endpoints").
|
||||||
|
SelectorParam(api.LabelSelectorQueryParam(c.r.APIVersion()), selector).
|
||||||
|
Do().
|
||||||
|
Into(result)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -82,8 +87,8 @@ func (c *endpoints) Watch(label, field labels.Selector, resourceVersion string)
|
||||||
Namespace(c.ns).
|
Namespace(c.ns).
|
||||||
Resource("endpoints").
|
Resource("endpoints").
|
||||||
Param("resourceVersion", resourceVersion).
|
Param("resourceVersion", resourceVersion).
|
||||||
SelectorParam("labels", label).
|
SelectorParam(api.LabelSelectorQueryParam(c.r.APIVersion()), label).
|
||||||
SelectorParam("fields", field).
|
SelectorParam(api.FieldSelectorQueryParam(c.r.APIVersion()), field).
|
||||||
Watch()
|
Watch()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -100,8 +100,8 @@ func (e *events) List(label, field labels.Selector) (*api.EventList, error) {
|
||||||
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").
|
||||||
SelectorParam("labels", label).
|
SelectorParam(api.LabelSelectorQueryParam(e.client.APIVersion()), label).
|
||||||
SelectorParam("fields", field).
|
SelectorParam(api.FieldSelectorQueryParam(e.client.APIVersion()), field).
|
||||||
Do().
|
Do().
|
||||||
Into(result)
|
Into(result)
|
||||||
return result, err
|
return result, err
|
||||||
|
@ -130,8 +130,8 @@ func (e *events) Watch(label, field labels.Selector, resourceVersion string) (wa
|
||||||
NamespaceIfScoped(e.namespace, len(e.namespace) > 0).
|
NamespaceIfScoped(e.namespace, len(e.namespace) > 0).
|
||||||
Resource("events").
|
Resource("events").
|
||||||
Param("resourceVersion", resourceVersion).
|
Param("resourceVersion", resourceVersion).
|
||||||
SelectorParam("labels", label).
|
SelectorParam(api.LabelSelectorQueryParam(e.client.APIVersion()), label).
|
||||||
SelectorParam("fields", field).
|
SelectorParam(api.FieldSelectorQueryParam(e.client.APIVersion()), field).
|
||||||
Watch()
|
Watch()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -21,6 +21,7 @@ import (
|
||||||
"net/url"
|
"net/url"
|
||||||
|
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
|
||||||
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/testapi"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/version"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/version"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/watch"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/watch"
|
||||||
|
@ -124,19 +125,19 @@ type FakeRESTClient struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *FakeRESTClient) Get() *Request {
|
func (c *FakeRESTClient) Get() *Request {
|
||||||
return NewRequest(c, "GET", &url.URL{Host: "localhost"}, c.Codec, c.Legacy, c.Legacy)
|
return NewRequest(c, "GET", &url.URL{Host: "localhost"}, testapi.Version(), c.Codec, c.Legacy, c.Legacy)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *FakeRESTClient) Put() *Request {
|
func (c *FakeRESTClient) Put() *Request {
|
||||||
return NewRequest(c, "PUT", &url.URL{Host: "localhost"}, c.Codec, c.Legacy, c.Legacy)
|
return NewRequest(c, "PUT", &url.URL{Host: "localhost"}, testapi.Version(), c.Codec, c.Legacy, c.Legacy)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *FakeRESTClient) Post() *Request {
|
func (c *FakeRESTClient) Post() *Request {
|
||||||
return NewRequest(c, "POST", &url.URL{Host: "localhost"}, c.Codec, c.Legacy, c.Legacy)
|
return NewRequest(c, "POST", &url.URL{Host: "localhost"}, testapi.Version(), c.Codec, c.Legacy, c.Legacy)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *FakeRESTClient) Delete() *Request {
|
func (c *FakeRESTClient) Delete() *Request {
|
||||||
return NewRequest(c, "DELETE", &url.URL{Host: "localhost"}, c.Codec, c.Legacy, c.Legacy)
|
return NewRequest(c, "DELETE", &url.URL{Host: "localhost"}, testapi.Version(), c.Codec, c.Legacy, c.Legacy)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *FakeRESTClient) Do(req *http.Request) (*http.Response, error) {
|
func (c *FakeRESTClient) Do(req *http.Request) (*http.Response, error) {
|
||||||
|
|
|
@ -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").SelectorParam("labels", selector).Do().Into(result)
|
err = c.r.Get().Namespace(c.ns).Resource("limitRanges").SelectorParam(api.LabelSelectorQueryParam(c.r.APIVersion()), selector).Do().Into(result)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -102,7 +102,7 @@ func (c *limitRanges) Watch(label, field labels.Selector, resourceVersion string
|
||||||
Namespace(c.ns).
|
Namespace(c.ns).
|
||||||
Resource("limitRanges").
|
Resource("limitRanges").
|
||||||
Param("resourceVersion", resourceVersion).
|
Param("resourceVersion", resourceVersion).
|
||||||
SelectorParam("labels", label).
|
SelectorParam(api.LabelSelectorQueryParam(c.r.APIVersion()), label).
|
||||||
SelectorParam("fields", field).
|
SelectorParam(api.FieldSelectorQueryParam(c.r.APIVersion()), field).
|
||||||
Watch()
|
Watch()
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,7 +48,7 @@ func newNodes(c *Client) *nodes {
|
||||||
|
|
||||||
// resourceName returns node's URL resource name based on resource version.
|
// resourceName returns node's URL resource name based on resource version.
|
||||||
func (c *nodes) resourceName() string {
|
func (c *nodes) resourceName() string {
|
||||||
if preV1Beta3(c.r.APIVersion()) {
|
if api.PreV1Beta3(c.r.APIVersion()) {
|
||||||
return "minions"
|
return "minions"
|
||||||
}
|
}
|
||||||
return "nodes"
|
return "nodes"
|
||||||
|
|
|
@ -58,7 +58,7 @@ func (c *namespaces) Create(namespace *api.Namespace) (*api.Namespace, error) {
|
||||||
// List lists all the namespaces in the cluster.
|
// List lists all the namespaces in the cluster.
|
||||||
func (c *namespaces) List(selector labels.Selector) (*api.NamespaceList, error) {
|
func (c *namespaces) List(selector labels.Selector) (*api.NamespaceList, error) {
|
||||||
result := &api.NamespaceList{}
|
result := &api.NamespaceList{}
|
||||||
err := c.r.Get().Resource("namespaces").SelectorParam("labels", selector).Do().Into(result)
|
err := c.r.Get().Resource("namespaces").SelectorParam(api.LabelSelectorQueryParam(c.r.APIVersion()), selector).Do().Into(result)
|
||||||
return result, err
|
return result, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -95,7 +95,7 @@ func (c *namespaces) Watch(label, field labels.Selector, resourceVersion string)
|
||||||
Prefix("watch").
|
Prefix("watch").
|
||||||
Resource("namespaces").
|
Resource("namespaces").
|
||||||
Param("resourceVersion", resourceVersion).
|
Param("resourceVersion", resourceVersion).
|
||||||
SelectorParam("labels", label).
|
SelectorParam(api.LabelSelectorQueryParam(c.r.APIVersion()), label).
|
||||||
SelectorParam("fields", field).
|
SelectorParam(api.FieldSelectorQueryParam(c.r.APIVersion()), field).
|
||||||
Watch()
|
Watch()
|
||||||
}
|
}
|
||||||
|
|
|
@ -58,7 +58,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").SelectorParam("labels", selector).Do().Into(result)
|
err = c.r.Get().Namespace(c.ns).Resource("pods").SelectorParam(api.LabelSelectorQueryParam(c.r.APIVersion()), selector).Do().Into(result)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -54,7 +54,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").SelectorParam("labels", selector).Do().Into(result)
|
err = c.r.Get().Namespace(c.ns).Resource("replicationControllers").SelectorParam(api.LabelSelectorQueryParam(c.r.APIVersion()), selector).Do().Into(result)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -99,7 +99,7 @@ func (c *replicationControllers) Watch(label, field labels.Selector, resourceVer
|
||||||
Namespace(c.ns).
|
Namespace(c.ns).
|
||||||
Resource("replicationControllers").
|
Resource("replicationControllers").
|
||||||
Param("resourceVersion", resourceVersion).
|
Param("resourceVersion", resourceVersion).
|
||||||
SelectorParam("labels", label).
|
SelectorParam(api.LabelSelectorQueryParam(c.r.APIVersion()), label).
|
||||||
SelectorParam("fields", field).
|
SelectorParam(api.FieldSelectorQueryParam(c.r.APIVersion()), field).
|
||||||
Watch()
|
Watch()
|
||||||
}
|
}
|
||||||
|
|
|
@ -110,6 +110,8 @@ type Request struct {
|
||||||
selector labels.Selector
|
selector labels.Selector
|
||||||
timeout time.Duration
|
timeout time.Duration
|
||||||
|
|
||||||
|
apiVersion string
|
||||||
|
|
||||||
// output
|
// output
|
||||||
err error
|
err error
|
||||||
body io.Reader
|
body io.Reader
|
||||||
|
@ -120,7 +122,7 @@ type Request struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewRequest creates a new request helper object for accessing runtime.Objects on a server.
|
// NewRequest creates a new request helper object for accessing runtime.Objects on a server.
|
||||||
func NewRequest(client HTTPClient, verb string, baseURL *url.URL,
|
func NewRequest(client HTTPClient, verb string, baseURL *url.URL, apiVersion string,
|
||||||
codec runtime.Codec, namespaceInQuery bool, preserveResourceCase bool) *Request {
|
codec runtime.Codec, namespaceInQuery bool, preserveResourceCase bool) *Request {
|
||||||
return &Request{
|
return &Request{
|
||||||
client: client,
|
client: client,
|
||||||
|
|
|
@ -50,12 +50,11 @@ func TestRequestWithErrorWontChange(t *testing.T) {
|
||||||
original := Request{err: errors.New("test")}
|
original := Request{err: errors.New("test")}
|
||||||
r := original
|
r := original
|
||||||
changed := r.Param("foo", "bar").
|
changed := r.Param("foo", "bar").
|
||||||
SelectorParam("labels", labels.Set{"a": "b"}.AsSelector()).
|
SelectorParam(api.LabelSelectorQueryParam(testapi.Version()), labels.Set{"a": "b"}.AsSelector()).
|
||||||
UintParam("uint", 1).
|
UintParam("uint", 1).
|
||||||
AbsPath("/abs").
|
AbsPath("/abs").
|
||||||
Prefix("test").
|
Prefix("test").
|
||||||
Suffix("testing").
|
Suffix("testing").
|
||||||
ParseSelectorParam("foo", "a=b").
|
|
||||||
Namespace("new").
|
Namespace("new").
|
||||||
Resource("foos").
|
Resource("foos").
|
||||||
Name("bars").
|
Name("bars").
|
||||||
|
@ -154,13 +153,6 @@ func TestRequestSetTwiceError(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestRequestParseSelectorParam(t *testing.T) {
|
|
||||||
r := (&Request{}).ParseSelectorParam("foo", "a=")
|
|
||||||
if r.err == nil || r.params != nil {
|
|
||||||
t.Errorf("should have set err and left params nil: %#v", r)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestRequestParam(t *testing.T) {
|
func TestRequestParam(t *testing.T) {
|
||||||
r := (&Request{}).Param("foo", "a")
|
r := (&Request{}).Param("foo", "a")
|
||||||
if !api.Semantic.DeepDerivative(r.params, url.Values{"foo": []string{"a"}}) {
|
if !api.Semantic.DeepDerivative(r.params, url.Values{"foo": []string{"a"}}) {
|
||||||
|
@ -242,7 +234,7 @@ func TestTransformResponse(t *testing.T) {
|
||||||
{Response: &http.Response{StatusCode: 200, Body: ioutil.NopCloser(bytes.NewReader(invalid))}, Data: invalid},
|
{Response: &http.Response{StatusCode: 200, Body: ioutil.NopCloser(bytes.NewReader(invalid))}, Data: invalid},
|
||||||
}
|
}
|
||||||
for i, test := range testCases {
|
for i, test := range testCases {
|
||||||
r := NewRequest(nil, "", uri, testapi.Codec(), true, true)
|
r := NewRequest(nil, "", uri, testapi.Version(), testapi.Codec(), true, true)
|
||||||
if test.Response.Body == nil {
|
if test.Response.Body == nil {
|
||||||
test.Response.Body = ioutil.NopCloser(bytes.NewReader([]byte{}))
|
test.Response.Body = ioutil.NopCloser(bytes.NewReader([]byte{}))
|
||||||
}
|
}
|
||||||
|
@ -540,7 +532,7 @@ func TestRequestUpgrade(t *testing.T) {
|
||||||
Err: true,
|
Err: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Request: NewRequest(nil, "", uri, testapi.Codec(), true, true),
|
Request: NewRequest(nil, "", uri, testapi.Version(), testapi.Codec(), true, true),
|
||||||
Config: &Config{
|
Config: &Config{
|
||||||
Username: "u",
|
Username: "u",
|
||||||
Password: "p",
|
Password: "p",
|
||||||
|
@ -549,7 +541,7 @@ func TestRequestUpgrade(t *testing.T) {
|
||||||
Err: false,
|
Err: false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Request: NewRequest(nil, "", uri, testapi.Codec(), true, true),
|
Request: NewRequest(nil, "", uri, testapi.Version(), testapi.Codec(), true, true),
|
||||||
Config: &Config{
|
Config: &Config{
|
||||||
BearerToken: "b",
|
BearerToken: "b",
|
||||||
},
|
},
|
||||||
|
@ -638,7 +630,6 @@ func TestDoRequestNewWay(t *testing.T) {
|
||||||
obj, err := c.Verb("POST").
|
obj, err := c.Verb("POST").
|
||||||
Prefix("foo", "bar").
|
Prefix("foo", "bar").
|
||||||
Suffix("baz").
|
Suffix("baz").
|
||||||
ParseSelectorParam("labels", "name=foo").
|
|
||||||
Timeout(time.Second).
|
Timeout(time.Second).
|
||||||
Body([]byte(reqBody)).
|
Body([]byte(reqBody)).
|
||||||
Do().Get()
|
Do().Get()
|
||||||
|
@ -651,7 +642,7 @@ func TestDoRequestNewWay(t *testing.T) {
|
||||||
} else if !api.Semantic.DeepDerivative(expectedObj, obj) {
|
} else if !api.Semantic.DeepDerivative(expectedObj, obj) {
|
||||||
t.Errorf("Expected: %#v, got %#v", expectedObj, obj)
|
t.Errorf("Expected: %#v, got %#v", expectedObj, obj)
|
||||||
}
|
}
|
||||||
fakeHandler.ValidateRequest(t, "/api/v1beta2/foo/bar/baz?labels=name%3Dfoo&timeout=1s", "POST", &reqBody)
|
fakeHandler.ValidateRequest(t, "/api/v1beta2/foo/bar/baz?timeout=1s", "POST", &reqBody)
|
||||||
if fakeHandler.RequestReceived.Header["Authorization"] == nil {
|
if fakeHandler.RequestReceived.Header["Authorization"] == nil {
|
||||||
t.Errorf("Request is missing authorization header: %#v", *fakeHandler.RequestReceived)
|
t.Errorf("Request is missing authorization header: %#v", *fakeHandler.RequestReceived)
|
||||||
}
|
}
|
||||||
|
@ -673,7 +664,7 @@ func TestDoRequestNewWayReader(t *testing.T) {
|
||||||
Resource("bar").
|
Resource("bar").
|
||||||
Name("baz").
|
Name("baz").
|
||||||
Prefix("foo").
|
Prefix("foo").
|
||||||
SelectorParam("labels", labels.Set{"name": "foo"}.AsSelector()).
|
SelectorParam(api.LabelSelectorQueryParam(c.APIVersion()), labels.Set{"name": "foo"}.AsSelector()).
|
||||||
Timeout(time.Second).
|
Timeout(time.Second).
|
||||||
Body(bytes.NewBuffer(reqBodyExpected)).
|
Body(bytes.NewBuffer(reqBodyExpected)).
|
||||||
Do().Get()
|
Do().Get()
|
||||||
|
@ -709,7 +700,7 @@ func TestDoRequestNewWayObj(t *testing.T) {
|
||||||
Suffix("baz").
|
Suffix("baz").
|
||||||
Name("bar").
|
Name("bar").
|
||||||
Resource("foo").
|
Resource("foo").
|
||||||
SelectorParam("labels", labels.Set{"name": "foo"}.AsSelector()).
|
SelectorParam(api.LabelSelectorQueryParam(c.APIVersion()), labels.Set{"name": "foo"}.AsSelector()).
|
||||||
Timeout(time.Second).
|
Timeout(time.Second).
|
||||||
Body(reqObj).
|
Body(reqObj).
|
||||||
Do().Get()
|
Do().Get()
|
||||||
|
@ -758,7 +749,6 @@ func TestDoRequestNewWayFile(t *testing.T) {
|
||||||
wasCreated := true
|
wasCreated := true
|
||||||
obj, err := c.Verb("POST").
|
obj, err := c.Verb("POST").
|
||||||
Prefix("foo/bar", "baz").
|
Prefix("foo/bar", "baz").
|
||||||
ParseSelectorParam("labels", "name=foo").
|
|
||||||
Timeout(time.Second).
|
Timeout(time.Second).
|
||||||
Body(file.Name()).
|
Body(file.Name()).
|
||||||
Do().WasCreated(&wasCreated).Get()
|
Do().WasCreated(&wasCreated).Get()
|
||||||
|
@ -775,7 +765,7 @@ func TestDoRequestNewWayFile(t *testing.T) {
|
||||||
t.Errorf("expected object was not created")
|
t.Errorf("expected object was not created")
|
||||||
}
|
}
|
||||||
tmpStr := string(reqBodyExpected)
|
tmpStr := string(reqBodyExpected)
|
||||||
fakeHandler.ValidateRequest(t, "/api/v1beta1/foo/bar/baz?labels=name%3Dfoo&timeout=1s", "POST", &tmpStr)
|
fakeHandler.ValidateRequest(t, "/api/v1beta1/foo/bar/baz?timeout=1s", "POST", &tmpStr)
|
||||||
if fakeHandler.RequestReceived.Header["Authorization"] == nil {
|
if fakeHandler.RequestReceived.Header["Authorization"] == nil {
|
||||||
t.Errorf("Request is missing authorization header: %#v", *fakeHandler.RequestReceived)
|
t.Errorf("Request is missing authorization header: %#v", *fakeHandler.RequestReceived)
|
||||||
}
|
}
|
||||||
|
@ -800,7 +790,6 @@ func TestWasCreated(t *testing.T) {
|
||||||
wasCreated := false
|
wasCreated := false
|
||||||
obj, err := c.Verb("PUT").
|
obj, err := c.Verb("PUT").
|
||||||
Prefix("foo/bar", "baz").
|
Prefix("foo/bar", "baz").
|
||||||
ParseSelectorParam("labels", "name=foo").
|
|
||||||
Timeout(time.Second).
|
Timeout(time.Second).
|
||||||
Body(reqBodyExpected).
|
Body(reqBodyExpected).
|
||||||
Do().WasCreated(&wasCreated).Get()
|
Do().WasCreated(&wasCreated).Get()
|
||||||
|
@ -818,7 +807,7 @@ func TestWasCreated(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
tmpStr := string(reqBodyExpected)
|
tmpStr := string(reqBodyExpected)
|
||||||
fakeHandler.ValidateRequest(t, "/api/v1beta1/foo/bar/baz?labels=name%3Dfoo&timeout=1s", "PUT", &tmpStr)
|
fakeHandler.ValidateRequest(t, "/api/v1beta1/foo/bar/baz?timeout=1s", "PUT", &tmpStr)
|
||||||
if fakeHandler.RequestReceived.Header["Authorization"] == nil {
|
if fakeHandler.RequestReceived.Header["Authorization"] == nil {
|
||||||
t.Errorf("Request is missing authorization header: %#v", *fakeHandler.RequestReceived)
|
t.Errorf("Request is missing authorization header: %#v", *fakeHandler.RequestReceived)
|
||||||
}
|
}
|
||||||
|
|
|
@ -57,7 +57,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").SelectorParam("labels", selector).Do().Into(result)
|
err = c.r.Get().Namespace(c.ns).Resource("resourceQuotas").SelectorParam(api.LabelSelectorQueryParam(c.r.APIVersion()), selector).Do().Into(result)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -102,7 +102,7 @@ func (c *resourceQuotas) Watch(label, field labels.Selector, resourceVersion str
|
||||||
Namespace(c.ns).
|
Namespace(c.ns).
|
||||||
Resource("resourceQuotas").
|
Resource("resourceQuotas").
|
||||||
Param("resourceVersion", resourceVersion).
|
Param("resourceVersion", resourceVersion).
|
||||||
SelectorParam("labels", label).
|
SelectorParam(api.LabelSelectorQueryParam(c.r.APIVersion()), label).
|
||||||
SelectorParam("fields", field).
|
SelectorParam(api.FieldSelectorQueryParam(c.r.APIVersion()), field).
|
||||||
Watch()
|
Watch()
|
||||||
}
|
}
|
||||||
|
|
|
@ -92,7 +92,7 @@ func (c *RESTClient) Verb(verb string) *Request {
|
||||||
// if c.Client != nil {
|
// if c.Client != nil {
|
||||||
// timeout = c.Client.Timeout
|
// timeout = c.Client.Timeout
|
||||||
// }
|
// }
|
||||||
return NewRequest(c.Client, verb, c.baseURL, c.Codec, c.LegacyBehavior, c.LegacyBehavior).Timeout(c.Timeout)
|
return NewRequest(c.Client, verb, c.baseURL, c.apiVersion, c.Codec, c.LegacyBehavior, c.LegacyBehavior).Timeout(c.Timeout)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Post begins a POST request. Short for c.Verb("POST").
|
// Post begins a POST request. Short for c.Verb("POST").
|
||||||
|
|
|
@ -75,8 +75,8 @@ func (s *secrets) List(label, field labels.Selector) (*api.SecretList, error) {
|
||||||
err := s.client.Get().
|
err := s.client.Get().
|
||||||
Namespace(s.namespace).
|
Namespace(s.namespace).
|
||||||
Resource("secrets").
|
Resource("secrets").
|
||||||
SelectorParam("labels", label).
|
SelectorParam(api.LabelSelectorQueryParam(s.client.APIVersion()), label).
|
||||||
SelectorParam("fields", field).
|
SelectorParam(api.FieldSelectorQueryParam(s.client.APIVersion()), field).
|
||||||
Do().
|
Do().
|
||||||
Into(result)
|
Into(result)
|
||||||
|
|
||||||
|
@ -107,8 +107,8 @@ func (s *secrets) Watch(label, field labels.Selector, resourceVersion string) (w
|
||||||
Namespace(s.namespace).
|
Namespace(s.namespace).
|
||||||
Resource("secrets").
|
Resource("secrets").
|
||||||
Param("resourceVersion", resourceVersion).
|
Param("resourceVersion", resourceVersion).
|
||||||
SelectorParam("labels", label).
|
SelectorParam(api.LabelSelectorQueryParam(s.client.APIVersion()), label).
|
||||||
SelectorParam("fields", field).
|
SelectorParam(api.FieldSelectorQueryParam(s.client.APIVersion()), field).
|
||||||
Watch()
|
Watch()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -54,7 +54,12 @@ func newServices(c *Client, namespace string) *services {
|
||||||
// List takes a selector, and returns the list of services that match that selector
|
// List takes a selector, and returns the list of services that match that selector
|
||||||
func (c *services) List(selector labels.Selector) (result *api.ServiceList, err error) {
|
func (c *services) List(selector labels.Selector) (result *api.ServiceList, err error) {
|
||||||
result = &api.ServiceList{}
|
result = &api.ServiceList{}
|
||||||
err = c.r.Get().Namespace(c.ns).Resource("services").SelectorParam("labels", selector).Do().Into(result)
|
err = c.r.Get().
|
||||||
|
Namespace(c.ns).
|
||||||
|
Resource("services").
|
||||||
|
SelectorParam(api.LabelSelectorQueryParam(c.r.APIVersion()), selector).
|
||||||
|
Do().
|
||||||
|
Into(result)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -99,7 +104,7 @@ func (c *services) Watch(label, field labels.Selector, resourceVersion string) (
|
||||||
Namespace(c.ns).
|
Namespace(c.ns).
|
||||||
Resource("services").
|
Resource("services").
|
||||||
Param("resourceVersion", resourceVersion).
|
Param("resourceVersion", resourceVersion).
|
||||||
SelectorParam("labels", label).
|
SelectorParam(api.LabelSelectorQueryParam(c.r.APIVersion()), label).
|
||||||
SelectorParam("fields", field).
|
SelectorParam(api.FieldSelectorQueryParam(c.r.APIVersion()), field).
|
||||||
Watch()
|
Watch()
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,6 +17,7 @@ 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/labels"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"
|
||||||
|
@ -60,23 +61,23 @@ func (m *Helper) Get(namespace, name string) (runtime.Object, error) {
|
||||||
Get()
|
Get()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *Helper) List(namespace 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).
|
||||||
SelectorParam("labels", selector).
|
SelectorParam(api.LabelSelectorQueryParam(apiVersion), selector).
|
||||||
Do().
|
Do().
|
||||||
Get()
|
Get()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *Helper) Watch(namespace, resourceVersion string, labelSelector, fieldSelector labels.Selector) (watch.Interface, error) {
|
func (m *Helper) Watch(namespace, resourceVersion, apiVersion string, labelSelector, fieldSelector labels.Selector) (watch.Interface, error) {
|
||||||
return m.RESTClient.Get().
|
return m.RESTClient.Get().
|
||||||
Prefix("watch").
|
Prefix("watch").
|
||||||
NamespaceIfScoped(namespace, m.NamespaceScoped).
|
NamespaceIfScoped(namespace, m.NamespaceScoped).
|
||||||
Resource(m.Resource).
|
Resource(m.Resource).
|
||||||
Param("resourceVersion", resourceVersion).
|
Param("resourceVersion", resourceVersion).
|
||||||
SelectorParam("labels", labelSelector).
|
SelectorParam(api.LabelSelectorQueryParam(apiVersion), labelSelector).
|
||||||
SelectorParam("fields", fieldSelector).
|
SelectorParam(api.FieldSelectorQueryParam(apiVersion), fieldSelector).
|
||||||
Watch()
|
Watch()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -347,7 +347,7 @@ func TestHelperList(t *testing.T) {
|
||||||
RESTClient: client,
|
RESTClient: client,
|
||||||
NamespaceScoped: true,
|
NamespaceScoped: true,
|
||||||
}
|
}
|
||||||
obj, err := modifier.List("bar", labels.SelectorFromSet(labels.Set{"foo": "baz"}))
|
obj, err := modifier.List("bar", testapi.Version(), labels.SelectorFromSet(labels.Set{"foo": "baz"}))
|
||||||
if (err != nil) != test.Err {
|
if (err != nil) != test.Err {
|
||||||
t.Errorf("unexpected error: %t %v", test.Err, err)
|
t.Errorf("unexpected error: %t %v", test.Err, err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,7 +45,7 @@ func NewSelector(client RESTClient, mapping *meta.RESTMapping, namespace string,
|
||||||
|
|
||||||
// Visit implements Visitor
|
// Visit implements Visitor
|
||||||
func (r *Selector) Visit(fn VisitorFunc) error {
|
func (r *Selector) Visit(fn VisitorFunc) error {
|
||||||
list, err := NewHelper(r.Client, r.Mapping).List(r.Namespace, r.Selector)
|
list, err := NewHelper(r.Client, r.Mapping).List(r.Namespace, r.ResourceMapping().APIVersion, r.Selector)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if errors.IsBadRequest(err) || errors.IsNotFound(err) {
|
if errors.IsBadRequest(err) || errors.IsNotFound(err) {
|
||||||
if r.Selector.Empty() {
|
if r.Selector.Empty() {
|
||||||
|
@ -71,7 +71,7 @@ func (r *Selector) Visit(fn VisitorFunc) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Selector) Watch(resourceVersion string) (watch.Interface, error) {
|
func (r *Selector) Watch(resourceVersion string) (watch.Interface, error) {
|
||||||
return NewHelper(r.Client, r.Mapping).Watch(r.Namespace, resourceVersion, r.Selector, labels.Everything())
|
return NewHelper(r.Client, r.Mapping).Watch(r.Namespace, resourceVersion, r.ResourceMapping().APIVersion, r.Selector, labels.Everything())
|
||||||
}
|
}
|
||||||
|
|
||||||
// ResourceMapping returns the mapping for this resource and implements ResourceMapping
|
// ResourceMapping returns the mapping for this resource and implements ResourceMapping
|
||||||
|
|
Loading…
Reference in New Issue