Merge pull request #18655 from wojtek-t/versioned_list_options_in_server

Switch to versioned ListOptions in server.
This commit is contained in:
Wojciech Tyczynski
2015-12-22 10:57:09 +01:00
34 changed files with 218 additions and 232 deletions

View File

@@ -39,14 +39,6 @@ func init() {
obj.FieldSelector = fields.Everything()
}
},
func(obj *unversioned.ListOptions) {
if obj.LabelSelector.Selector == nil {
obj.LabelSelector = unversioned.LabelSelector{labels.Everything()}
}
if obj.FieldSelector.Selector == nil {
obj.FieldSelector = unversioned.FieldSelector{fields.Everything()}
}
},
)
Scheme.AddConversionFuncs(
func(in *unversioned.Time, out *unversioned.Time, s conversion.Scope) error {

View File

@@ -24,6 +24,8 @@ import (
resource "k8s.io/kubernetes/pkg/api/resource"
unversioned "k8s.io/kubernetes/pkg/api/unversioned"
conversion "k8s.io/kubernetes/pkg/conversion"
fields "k8s.io/kubernetes/pkg/fields"
labels "k8s.io/kubernetes/pkg/labels"
runtime "k8s.io/kubernetes/pkg/runtime"
intstr "k8s.io/kubernetes/pkg/util/intstr"
inf "speter.net/go/exp/math/dec/inf"
@@ -807,6 +809,35 @@ func deepCopy_api_List(in List, out *List, c *conversion.Cloner) error {
return nil
}
func deepCopy_api_ListOptions(in ListOptions, out *ListOptions, c *conversion.Cloner) error {
if err := deepCopy_unversioned_TypeMeta(in.TypeMeta, &out.TypeMeta, c); err != nil {
return err
}
if newVal, err := c.DeepCopy(in.LabelSelector); err != nil {
return err
} else if newVal == nil {
out.LabelSelector = nil
} else {
out.LabelSelector = newVal.(labels.Selector)
}
if newVal, err := c.DeepCopy(in.FieldSelector); err != nil {
return err
} else if newVal == nil {
out.FieldSelector = nil
} else {
out.FieldSelector = newVal.(fields.Selector)
}
out.Watch = in.Watch
out.ResourceVersion = in.ResourceVersion
if in.TimeoutSeconds != nil {
out.TimeoutSeconds = new(int64)
*out.TimeoutSeconds = *in.TimeoutSeconds
} else {
out.TimeoutSeconds = nil
}
return nil
}
func deepCopy_api_LoadBalancerIngress(in LoadBalancerIngress, out *LoadBalancerIngress, c *conversion.Cloner) error {
out.IP = in.IP
out.Hostname = in.Hostname
@@ -2386,6 +2417,7 @@ func init() {
deepCopy_api_LimitRangeList,
deepCopy_api_LimitRangeSpec,
deepCopy_api_List,
deepCopy_api_ListOptions,
deepCopy_api_LoadBalancerIngress,
deepCopy_api_LoadBalancerStatus,
deepCopy_api_LocalObjectReference,

View File

@@ -89,7 +89,6 @@ func init() {
// Register Unversioned types
// TODO this should not be done here
Scheme.AddKnownTypes(SchemeGroupVersion, &unversioned.ExportOptions{})
Scheme.AddKnownTypes(SchemeGroupVersion, &unversioned.ListOptions{})
Scheme.AddKnownTypes(SchemeGroupVersion, &unversioned.Status{})
Scheme.AddKnownTypes(SchemeGroupVersion, &unversioned.APIVersions{})
Scheme.AddKnownTypes(SchemeGroupVersion, &unversioned.APIGroupList{})

View File

@@ -61,7 +61,7 @@ type Lister interface {
// This object must be a pointer type for use with Codec.DecodeInto([]byte, runtime.Object)
NewList() runtime.Object
// List selects resources in the storage which match to the selector. 'options' can be nil.
List(ctx api.Context, options *unversioned.ListOptions) (runtime.Object, error)
List(ctx api.Context, options *api.ListOptions) (runtime.Object, error)
}
// Exporter is an object that knows how to strip a RESTful resource for export
@@ -141,7 +141,7 @@ type CollectionDeleter interface {
// them or return an invalid request error.
// DeleteCollection may not be atomic - i.e. it may delete some objects and still
// return an error after it. On success, returns a list of deleted objects.
DeleteCollection(ctx api.Context, options *api.DeleteOptions, listOptions *unversioned.ListOptions) (runtime.Object, error)
DeleteCollection(ctx api.Context, options *api.DeleteOptions, listOptions *api.ListOptions) (runtime.Object, error)
}
// Creater is an object that can create an instance of a RESTful object.
@@ -201,7 +201,7 @@ type Watcher interface {
// are supported; an error should be returned if 'field' tries to select on a field that
// isn't supported. 'resourceVersion' allows for continuing/starting a watch at a
// particular version.
Watch(ctx api.Context, options *unversioned.ListOptions) (watch.Interface, error)
Watch(ctx api.Context, options *api.ListOptions) (watch.Interface, error)
}
// StandardStorage is an interface covering the common verbs. Provided for testing whether a

View File

@@ -864,7 +864,7 @@ func (t *Tester) testListMatchLabels(obj runtime.Object, assignFn AssignFunc) {
filtered := []runtime.Object{objs[1]}
selector := labels.SelectorFromSet(labels.Set(testLabels))
options := &unversioned.ListOptions{LabelSelector: unversioned.LabelSelector{selector}}
options := &api.ListOptions{LabelSelector: selector}
listObj, err := t.storage.(rest.Lister).List(ctx, options)
if err != nil {
t.Errorf("unexpected error: %v", err)
@@ -906,7 +906,7 @@ func (t *Tester) testWatchFields(obj runtime.Object, emitFn EmitFunc, fieldsPass
for _, field := range fieldsPass {
for _, action := range actions {
options := &unversioned.ListOptions{FieldSelector: unversioned.FieldSelector{field.AsSelector()}, ResourceVersion: "1"}
options := &api.ListOptions{FieldSelector: field.AsSelector(), ResourceVersion: "1"}
watcher, err := t.storage.(rest.Watcher).Watch(ctx, options)
if err != nil {
t.Errorf("unexpected error: %v, %v", err, action)
@@ -930,7 +930,7 @@ func (t *Tester) testWatchFields(obj runtime.Object, emitFn EmitFunc, fieldsPass
for _, field := range fieldsFail {
for _, action := range actions {
options := &unversioned.ListOptions{FieldSelector: unversioned.FieldSelector{field.AsSelector()}, ResourceVersion: "1"}
options := &api.ListOptions{FieldSelector: field.AsSelector(), ResourceVersion: "1"}
watcher, err := t.storage.(rest.Watcher).Watch(ctx, options)
if err != nil {
t.Errorf("unexpected error: %v", err)
@@ -955,7 +955,7 @@ func (t *Tester) testWatchLabels(obj runtime.Object, emitFn EmitFunc, labelsPass
for _, label := range labelsPass {
for _, action := range actions {
options := &unversioned.ListOptions{LabelSelector: unversioned.LabelSelector{label.AsSelector()}, ResourceVersion: "1"}
options := &api.ListOptions{LabelSelector: label.AsSelector(), ResourceVersion: "1"}
watcher, err := t.storage.(rest.Watcher).Watch(ctx, options)
if err != nil {
t.Errorf("unexpected error: %v", err)
@@ -978,7 +978,7 @@ func (t *Tester) testWatchLabels(obj runtime.Object, emitFn EmitFunc, labelsPass
for _, label := range labelsFail {
for _, action := range actions {
options := &unversioned.ListOptions{LabelSelector: unversioned.LabelSelector{label.AsSelector()}, ResourceVersion: "1"}
options := &api.ListOptions{LabelSelector: label.AsSelector(), ResourceVersion: "1"}
watcher, err := t.storage.(rest.Watcher).Watch(ctx, options)
if err != nil {
t.Errorf("unexpected error: %v", err)

View File

@@ -103,13 +103,6 @@ func FuzzerFor(t *testing.T, version string, src rand.Source) *fuzz.Fuzzer {
field, _ := fields.ParseSelector("a=b")
j.FieldSelector = field
},
func(j *unversioned.ListOptions, c fuzz.Continue) {
// TODO: add some parsing
label, _ := labels.Parse("a=b")
j.LabelSelector = unversioned.LabelSelector{label}
field, _ := fields.ParseSelector("a=b")
j.FieldSelector = unversioned.FieldSelector{field}
},
func(j *api.PodExecOptions, c fuzz.Continue) {
j.Stdout = true
j.Stderr = true

View File

@@ -34,7 +34,6 @@ func (obj *TypeMeta) GroupVersionKind() *GroupVersionKind {
return FromAPIVersionAndKind(obj.APIVersion, obj.Kind)
}
func (obj *ListOptions) GetObjectKind() ObjectKind { return &obj.TypeMeta }
func (obj *Status) GetObjectKind() ObjectKind { return &obj.TypeMeta }
func (obj *APIVersions) GetObjectKind() ObjectKind { return &obj.TypeMeta }
func (obj *APIGroupList) GetObjectKind() ObjectKind { return &obj.TypeMeta }

View File

@@ -63,27 +63,6 @@ type ExportOptions struct {
Exact bool `json:"exact"`
}
// ListOptions is the query options to a standard REST list/watch calls.
type ListOptions struct {
TypeMeta `json:",inline"`
// A selector to restrict the list of returned objects by their labels.
// Defaults to everything.
LabelSelector LabelSelector `json:"labelSelector,omitempty"`
// A selector to restrict the list of returned objects by their fields.
// Defaults to everything.
FieldSelector FieldSelector `json:"fieldSelector,omitempty"`
// Watch for changes to the described resources and return them as a stream of
// add, update, and remove notifications. Specify resourceVersion.
Watch bool `json:"watch,omitempty"`
// When specified with a watch call, shows changes that occur after that particular version of a resource.
// Defaults to changes from the beginning of history.
ResourceVersion string `json:"resourceVersion,omitempty"`
// Timeout for the list/watch call.
TimeoutSeconds *int64 `json:"timeoutSeconds,omitempty"`
}
// Status is a return value for calls that don't return other objects.
type Status struct {
TypeMeta `json:",inline"`

View File

@@ -106,19 +106,6 @@ func (ListMeta) SwaggerDoc() map[string]string {
return map_ListMeta
}
var map_ListOptions = map[string]string{
"": "ListOptions is the query options to a standard REST list/watch calls.",
"labelSelector": "A selector to restrict the list of returned objects by their labels. Defaults to everything.",
"fieldSelector": "A selector to restrict the list of returned objects by their fields. Defaults to everything.",
"watch": "Watch for changes to the described resources and return them as a stream of add, update, and remove notifications. Specify resourceVersion.",
"resourceVersion": "When specified with a watch call, shows changes that occur after that particular version of a resource. Defaults to changes from the beginning of history.",
"timeoutSeconds": "Timeout for the list/watch call.",
}
func (ListOptions) SwaggerDoc() map[string]string {
return map_ListOptions
}
var map_Patch = map[string]string{
"": "Patch is provided to give a concrete name and type to the Kubernetes PATCH request body.",
}

View File

@@ -1116,6 +1116,34 @@ func convert_api_List_To_v1_List(in *api.List, out *List, s conversion.Scope) er
return autoconvert_api_List_To_v1_List(in, out, s)
}
func autoconvert_api_ListOptions_To_v1_ListOptions(in *api.ListOptions, out *ListOptions, s conversion.Scope) error {
if defaulting, found := s.DefaultingInterface(reflect.TypeOf(*in)); found {
defaulting.(func(*api.ListOptions))(in)
}
if err := s.Convert(&in.TypeMeta, &out.TypeMeta, 0); err != nil {
return err
}
if err := s.Convert(&in.LabelSelector, &out.LabelSelector, 0); err != nil {
return err
}
if err := s.Convert(&in.FieldSelector, &out.FieldSelector, 0); err != nil {
return err
}
out.Watch = in.Watch
out.ResourceVersion = in.ResourceVersion
if in.TimeoutSeconds != nil {
out.TimeoutSeconds = new(int64)
*out.TimeoutSeconds = *in.TimeoutSeconds
} else {
out.TimeoutSeconds = nil
}
return nil
}
func convert_api_ListOptions_To_v1_ListOptions(in *api.ListOptions, out *ListOptions, s conversion.Scope) error {
return autoconvert_api_ListOptions_To_v1_ListOptions(in, out, s)
}
func autoconvert_api_LoadBalancerIngress_To_v1_LoadBalancerIngress(in *api.LoadBalancerIngress, out *LoadBalancerIngress, s conversion.Scope) error {
if defaulting, found := s.DefaultingInterface(reflect.TypeOf(*in)); found {
defaulting.(func(*api.LoadBalancerIngress))(in)
@@ -3054,34 +3082,6 @@ func convert_unversioned_ExportOptions_To_v1_ExportOptions(in *unversioned.Expor
return autoconvert_unversioned_ExportOptions_To_v1_ExportOptions(in, out, s)
}
func autoconvert_unversioned_ListOptions_To_v1_ListOptions(in *unversioned.ListOptions, out *ListOptions, s conversion.Scope) error {
if defaulting, found := s.DefaultingInterface(reflect.TypeOf(*in)); found {
defaulting.(func(*unversioned.ListOptions))(in)
}
if err := s.Convert(&in.TypeMeta, &out.TypeMeta, 0); err != nil {
return err
}
if err := s.Convert(&in.LabelSelector, &out.LabelSelector, 0); err != nil {
return err
}
if err := s.Convert(&in.FieldSelector, &out.FieldSelector, 0); err != nil {
return err
}
out.Watch = in.Watch
out.ResourceVersion = in.ResourceVersion
if in.TimeoutSeconds != nil {
out.TimeoutSeconds = new(int64)
*out.TimeoutSeconds = *in.TimeoutSeconds
} else {
out.TimeoutSeconds = nil
}
return nil
}
func convert_unversioned_ListOptions_To_v1_ListOptions(in *unversioned.ListOptions, out *ListOptions, s conversion.Scope) error {
return autoconvert_unversioned_ListOptions_To_v1_ListOptions(in, out, s)
}
func autoconvert_v1_AWSElasticBlockStoreVolumeSource_To_api_AWSElasticBlockStoreVolumeSource(in *AWSElasticBlockStoreVolumeSource, out *api.AWSElasticBlockStoreVolumeSource, s conversion.Scope) error {
if defaulting, found := s.DefaultingInterface(reflect.TypeOf(*in)); found {
defaulting.(func(*AWSElasticBlockStoreVolumeSource))(in)
@@ -4187,7 +4187,7 @@ func convert_v1_List_To_api_List(in *List, out *api.List, s conversion.Scope) er
return autoconvert_v1_List_To_api_List(in, out, s)
}
func autoconvert_v1_ListOptions_To_unversioned_ListOptions(in *ListOptions, out *unversioned.ListOptions, s conversion.Scope) error {
func autoconvert_v1_ListOptions_To_api_ListOptions(in *ListOptions, out *api.ListOptions, s conversion.Scope) error {
if defaulting, found := s.DefaultingInterface(reflect.TypeOf(*in)); found {
defaulting.(func(*ListOptions))(in)
}
@@ -4211,8 +4211,8 @@ func autoconvert_v1_ListOptions_To_unversioned_ListOptions(in *ListOptions, out
return nil
}
func convert_v1_ListOptions_To_unversioned_ListOptions(in *ListOptions, out *unversioned.ListOptions, s conversion.Scope) error {
return autoconvert_v1_ListOptions_To_unversioned_ListOptions(in, out, s)
func convert_v1_ListOptions_To_api_ListOptions(in *ListOptions, out *api.ListOptions, s conversion.Scope) error {
return autoconvert_v1_ListOptions_To_api_ListOptions(in, out, s)
}
func autoconvert_v1_LoadBalancerIngress_To_api_LoadBalancerIngress(in *LoadBalancerIngress, out *api.LoadBalancerIngress, s conversion.Scope) error {
@@ -6187,6 +6187,7 @@ func init() {
autoconvert_api_LimitRangeList_To_v1_LimitRangeList,
autoconvert_api_LimitRangeSpec_To_v1_LimitRangeSpec,
autoconvert_api_LimitRange_To_v1_LimitRange,
autoconvert_api_ListOptions_To_v1_ListOptions,
autoconvert_api_List_To_v1_List,
autoconvert_api_LoadBalancerIngress_To_v1_LoadBalancerIngress,
autoconvert_api_LoadBalancerStatus_To_v1_LoadBalancerStatus,
@@ -6260,7 +6261,6 @@ func init() {
autoconvert_api_VolumeSource_To_v1_VolumeSource,
autoconvert_api_Volume_To_v1_Volume,
autoconvert_unversioned_ExportOptions_To_v1_ExportOptions,
autoconvert_unversioned_ListOptions_To_v1_ListOptions,
autoconvert_v1_AWSElasticBlockStoreVolumeSource_To_api_AWSElasticBlockStoreVolumeSource,
autoconvert_v1_Binding_To_api_Binding,
autoconvert_v1_Capabilities_To_api_Capabilities,
@@ -6307,7 +6307,7 @@ func init() {
autoconvert_v1_LimitRangeList_To_api_LimitRangeList,
autoconvert_v1_LimitRangeSpec_To_api_LimitRangeSpec,
autoconvert_v1_LimitRange_To_api_LimitRange,
autoconvert_v1_ListOptions_To_unversioned_ListOptions,
autoconvert_v1_ListOptions_To_api_ListOptions,
autoconvert_v1_List_To_api_List,
autoconvert_v1_LoadBalancerIngress_To_api_LoadBalancerIngress,
autoconvert_v1_LoadBalancerStatus_To_api_LoadBalancerStatus,

View File

@@ -17,12 +17,9 @@ limitations under the License.
package v1_test
import (
"encoding/json"
"reflect"
"testing"
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api/unversioned"
versioned "k8s.io/kubernetes/pkg/api/v1"
)
@@ -71,33 +68,3 @@ func TestPodSpecConversion(t *testing.T) {
}
}
}
func TestListOptionsConversion(t *testing.T) {
testCases := []versioned.ListOptions{
{},
{ResourceVersion: "1"},
{LabelSelector: "a=b,c=d", FieldSelector: "a=b,c!=d", ResourceVersion: "5"},
}
for _, test := range testCases {
marshalled, err := json.Marshal(test)
if err != nil {
t.Errorf("unexpected error: %#v", err)
}
newRep := unversioned.ListOptions{}
if err := json.Unmarshal(marshalled, &newRep); err != nil {
t.Errorf("unexpected error: %#v", err)
}
unversionedMarshalled, err := json.Marshal(newRep)
if err != nil {
t.Errorf("unexpected error: %#", err)
}
base := versioned.ListOptions{}
if err := json.Unmarshal(unversionedMarshalled, &base); err != nil {
t.Errorf("unexpected error: %#v", err)
}
if !reflect.DeepEqual(test, base) {
t.Errorf("expected: %#v, got: %#v", test, base)
}
}
}