Remove use of (Label|Field)SelectorParam

This commit is contained in:
Clayton Coleman 2017-07-16 00:22:11 -04:00
parent b516a521b1
commit b6d9815b95
No known key found for this signature in database
GPG Key ID: 3D16906B4F1C5CB3
5 changed files with 30 additions and 14 deletions

View File

@ -58,6 +58,7 @@ func (m *Helper) Get(namespace, name string, export bool) (runtime.Object, error
Resource(m.Resource).
Name(name)
if export {
// TODO: I should be part of GetOptions
req.Param("export", strconv.FormatBool(export))
}
return req.Do().Get()
@ -68,8 +69,11 @@ func (m *Helper) List(namespace, apiVersion string, selector labels.Selector, ex
req := m.RESTClient.Get().
NamespaceIfScoped(namespace, m.NamespaceScoped).
Resource(m.Resource).
LabelsSelectorParam(selector)
VersionedParams(&metav1.ListOptions{
LabelSelector: selector.String(),
}, metav1.ParameterCodec)
if export {
// TODO: I should be part of ListOptions
req.Param("export", strconv.FormatBool(export))
}
return req.Do().Get()
@ -79,9 +83,11 @@ func (m *Helper) Watch(namespace, resourceVersion, apiVersion string, labelSelec
return m.RESTClient.Get().
NamespaceIfScoped(namespace, m.NamespaceScoped).
Resource(m.Resource).
Param("resourceVersion", resourceVersion).
Param("watch", "true").
LabelsSelectorParam(labelSelector).
VersionedParams(&metav1.ListOptions{
ResourceVersion: resourceVersion,
Watch: true,
LabelSelector: labelSelector.String(),
}, metav1.ParameterCodec).
Watch()
}
@ -89,9 +95,11 @@ func (m *Helper) WatchSingle(namespace, name, resourceVersion string) (watch.Int
return m.RESTClient.Get().
NamespaceIfScoped(namespace, m.NamespaceScoped).
Resource(m.Resource).
Param("resourceVersion", resourceVersion).
Param("watch", "true").
FieldsSelectorParam(fields.OneTermEqualSelector("metadata.name", name)).
VersionedParams(&metav1.ListOptions{
ResourceVersion: resourceVersion,
Watch: true,
FieldSelector: fields.OneTermEqualSelector("metadata.name", name).String(),
}, metav1.ParameterCodec).
Watch()
}

View File

@ -58,21 +58,21 @@ type Getter interface {
// NewListWatchFromClient creates a new ListWatch from the specified client, resource, namespace and field selector.
func NewListWatchFromClient(c Getter, resource string, namespace string, fieldSelector fields.Selector) *ListWatch {
listFunc := func(options metav1.ListOptions) (runtime.Object, error) {
options.FieldSelector = fieldSelector.String()
return c.Get().
Namespace(namespace).
Resource(resource).
VersionedParams(&options, metav1.ParameterCodec).
FieldsSelectorParam(fieldSelector).
Do().
Get()
}
watchFunc := func(options metav1.ListOptions) (watch.Interface, error) {
options.Watch = true
options.FieldSelector = fieldSelector.String()
return c.Get().
Namespace(namespace).
Resource(resource).
VersionedParams(&options, metav1.ParameterCodec).
FieldsSelectorParam(fieldSelector).
Watch()
}
return &ListWatch{ListFunc: listFunc, WatchFunc: watchFunc}

View File

@ -16,6 +16,7 @@ go_library(
tags = ["automanaged"],
deps = [
"//vendor/k8s.io/apimachinery/pkg/api/meta:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/labels:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/runtime/schema:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/runtime/serializer:go_default_library",

View File

@ -20,6 +20,7 @@ import (
"fmt"
"k8s.io/apimachinery/pkg/api/meta"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/apimachinery/pkg/runtime/schema"
serializer "k8s.io/apimachinery/pkg/runtime/serializer"
@ -180,7 +181,9 @@ func (m *rootScopedMetrics) GetForObjects(groupKind schema.GroupKind, selector l
Resource(resourceName).
Name(v1alpha1.AllObjects).
SubResource(metricName).
LabelsSelectorParam(selector).
VersionedParams(&metav1.ListOptions{
LabelSelector: selector.String(),
}, metav1.ParameterCodec).
Do().
Into(res)
@ -234,7 +237,9 @@ func (m *namespacedMetrics) GetForObjects(groupKind schema.GroupKind, selector l
Namespace(m.namespace).
Name(v1alpha1.AllObjects).
SubResource(metricName).
LabelsSelectorParam(selector).
VersionedParams(&metav1.ListOptions{
LabelSelector: selector.String(),
}, metav1.ParameterCodec).
Do().
Into(res)

View File

@ -523,9 +523,11 @@ func TestSingleWatch(t *testing.T) {
w, err := client.Core().RESTClient().Get().
Namespace(ns.Name).
Resource("events").
Param("resourceVersion", rv1).
Param("watch", "true").
FieldsSelectorParam(fields.OneTermEqualSelector("metadata.name", "event-9")).
VersionedParams(&metav1.ListOptions{
ResourceVersion: rv1,
Watch: true,
FieldSelector: fields.OneTermEqualSelector("metadata.name", "event-9").String(),
}, metav1.ParameterCodec).
Watch()
if err != nil {