Skip to content

Commit

Permalink
Merge pull request kubernetes#18655 from wojtek-t/versioned_list_opti…
Browse files Browse the repository at this point in the history
…ons_in_server

Switch to versioned ListOptions in server.
  • Loading branch information
wojtek-t committed Dec 22, 2015
2 parents 6ac2774 + 5833682 commit e108a32
Show file tree
Hide file tree
Showing 34 changed files with 218 additions and 232 deletions.
8 changes: 0 additions & 8 deletions pkg/api/conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
32 changes: 32 additions & 0 deletions pkg/api/deep_copy_generated.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down
1 change: 0 additions & 1 deletion pkg/api/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{})
Expand Down
6 changes: 3 additions & 3 deletions pkg/api/rest/rest.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions pkg/api/rest/resttest/resttest.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand Down
7 changes: 0 additions & 7 deletions pkg/api/testing/fuzzer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion pkg/api/unversioned/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
21 changes: 0 additions & 21 deletions pkg/api/unversioned/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down
13 changes: 0 additions & 13 deletions pkg/api/unversioned/types_swagger_doc_generated.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
}
Expand Down
66 changes: 33 additions & 33 deletions pkg/api/v1/conversion_generated.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
}
Expand All @@ -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 {
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
33 changes: 0 additions & 33 deletions pkg/api/v1/conversion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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)
}
}
}
2 changes: 1 addition & 1 deletion pkg/apiserver/apiserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ type APIGroupVersion struct {
RequestInfoResolver *RequestInfoResolver

// OptionsExternalVersion controls the Kubernetes APIVersion used for common objects in the apiserver
// schema like api.Status, api.DeleteOptions, and unversioned.ListOptions. Other implementors may
// schema like api.Status, api.DeleteOptions, and api.ListOptions. Other implementors may
// define a version "v1beta1" but want to use the Kubernetes "v1" internal objects. If
// empty, defaults to GroupVersion.
OptionsExternalVersion *unversioned.GroupVersion
Expand Down
Loading

0 comments on commit e108a32

Please sign in to comment.