mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-07 11:13:48 +00:00
Create unversioned.ListOptions object.
This commit is contained in:
parent
147b6911f5
commit
77fd936b5f
@ -30,6 +30,9 @@ type FieldSelector struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (sh FieldSelector) MarshalJSON() ([]byte, error) {
|
func (sh FieldSelector) MarshalJSON() ([]byte, error) {
|
||||||
|
if sh.Selector == nil {
|
||||||
|
return json.Marshal("")
|
||||||
|
}
|
||||||
return json.Marshal(sh.Selector.String())
|
return json.Marshal(sh.Selector.String())
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -53,6 +56,9 @@ type LabelSelector struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (sh LabelSelector) MarshalJSON() ([]byte, error) {
|
func (sh LabelSelector) MarshalJSON() ([]byte, error) {
|
||||||
|
if sh.Selector == nil {
|
||||||
|
return json.Marshal("")
|
||||||
|
}
|
||||||
return json.Marshal(sh.Selector.String())
|
return json.Marshal(sh.Selector.String())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -17,7 +17,9 @@ limitations under the License.
|
|||||||
// Package unversioned contains API types that are common to all versions.
|
// Package unversioned contains API types that are common to all versions.
|
||||||
package unversioned
|
package unversioned
|
||||||
|
|
||||||
import "strings"
|
import (
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
// TypeMeta describes an individual object in an API response or request
|
// TypeMeta describes an individual object in an API response or request
|
||||||
// with strings representing the type of the object and its API schema version.
|
// with strings representing the type of the object and its API schema version.
|
||||||
@ -54,6 +56,27 @@ type ListMeta struct {
|
|||||||
ResourceVersion string `json:"resourceVersion,omitempty"`
|
ResourceVersion string `json:"resourceVersion,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 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.
|
// Status is a return value for calls that don't return other objects.
|
||||||
type Status struct {
|
type Status struct {
|
||||||
TypeMeta `json:",inline"`
|
TypeMeta `json:",inline"`
|
||||||
@ -276,6 +299,7 @@ const (
|
|||||||
CauseTypeUnexpectedServerResponse CauseType = "UnexpectedServerResponse"
|
CauseTypeUnexpectedServerResponse CauseType = "UnexpectedServerResponse"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func (*ListOptions) IsAnAPIObject() {}
|
||||||
func (*Status) IsAnAPIObject() {}
|
func (*Status) IsAnAPIObject() {}
|
||||||
func (*APIVersions) IsAnAPIObject() {}
|
func (*APIVersions) IsAnAPIObject() {}
|
||||||
func (*APIGroupList) IsAnAPIObject() {}
|
func (*APIGroupList) IsAnAPIObject() {}
|
||||||
|
@ -96,6 +96,19 @@ func (ListMeta) SwaggerDoc() map[string]string {
|
|||||||
return map_ListMeta
|
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{
|
var map_Patch = map[string]string{
|
||||||
"": "Patch is provided to give a concrete name and type to the Kubernetes PATCH request body.",
|
"": "Patch is provided to give a concrete name and type to the Kubernetes PATCH request body.",
|
||||||
}
|
}
|
||||||
|
@ -17,9 +17,12 @@ limitations under the License.
|
|||||||
package v1_test
|
package v1_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"reflect"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"k8s.io/kubernetes/pkg/api"
|
"k8s.io/kubernetes/pkg/api"
|
||||||
|
"k8s.io/kubernetes/pkg/api/unversioned"
|
||||||
versioned "k8s.io/kubernetes/pkg/api/v1"
|
versioned "k8s.io/kubernetes/pkg/api/v1"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -68,3 +71,33 @@ 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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user