mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-05 10:19:50 +00:00
Merge pull request #17823 from wojtek-t/use_versioned_params
Auto commit by PR queue bot
This commit is contained in:
commit
940c7fbbd5
@ -32,8 +32,12 @@ var Codec = runtime.CodecFor(Scheme, "")
|
|||||||
func init() {
|
func init() {
|
||||||
Scheme.AddDefaultingFuncs(
|
Scheme.AddDefaultingFuncs(
|
||||||
func(obj *unversioned.ListOptions) {
|
func(obj *unversioned.ListOptions) {
|
||||||
obj.LabelSelector = unversioned.LabelSelector{labels.Everything()}
|
if obj.LabelSelector.Selector == nil {
|
||||||
obj.FieldSelector = unversioned.FieldSelector{fields.Everything()}
|
obj.LabelSelector = unversioned.LabelSelector{labels.Everything()}
|
||||||
|
}
|
||||||
|
if obj.FieldSelector.Selector == nil {
|
||||||
|
obj.FieldSelector = unversioned.FieldSelector{fields.Everything()}
|
||||||
|
}
|
||||||
},
|
},
|
||||||
// TODO: see about moving this into v1/defaults.go
|
// TODO: see about moving this into v1/defaults.go
|
||||||
func(obj *PodExecOptions) {
|
func(obj *PodExecOptions) {
|
||||||
@ -135,6 +139,28 @@ func init() {
|
|||||||
*out = in.Selector.String()
|
*out = in.Selector.String()
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
|
func(in *unversioned.LabelSelector, out *unversioned.LabelSelector, s conversion.Scope) error {
|
||||||
|
if in.Selector == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
selector, err := labels.Parse(in.Selector.String())
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
out.Selector = selector
|
||||||
|
return nil
|
||||||
|
},
|
||||||
|
func(in *unversioned.FieldSelector, out *unversioned.FieldSelector, s conversion.Scope) error {
|
||||||
|
if in.Selector == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
selector, err := fields.ParseSelector(in.Selector.String())
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
out.Selector = selector
|
||||||
|
return nil
|
||||||
|
},
|
||||||
func(in *resource.Quantity, out *resource.Quantity, s conversion.Scope) error {
|
func(in *resource.Quantity, out *resource.Quantity, s conversion.Scope) error {
|
||||||
// Cannot deep copy these, because inf.Dec has unexported fields.
|
// Cannot deep copy these, because inf.Dec has unexported fields.
|
||||||
*out = *in.Copy()
|
*out = *in.Copy()
|
||||||
|
@ -57,6 +57,10 @@ func addKnownTypes() {
|
|||||||
&Ingress{},
|
&Ingress{},
|
||||||
&IngressList{},
|
&IngressList{},
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Register Unversioned types
|
||||||
|
// TODO this should not be done here
|
||||||
|
api.Scheme.AddKnownTypes(SchemeGroupVersion, &unversioned.ListOptions{})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (*ClusterAutoscaler) IsAnAPIObject() {}
|
func (*ClusterAutoscaler) IsAnAPIObject() {}
|
||||||
|
@ -55,6 +55,10 @@ func addKnownTypes() {
|
|||||||
&Ingress{},
|
&Ingress{},
|
||||||
&IngressList{},
|
&IngressList{},
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Register Unversioned types
|
||||||
|
// TODO this should not be done here
|
||||||
|
api.Scheme.AddKnownTypes(SchemeGroupVersion, &unversioned.ListOptions{})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (*ClusterAutoscaler) IsAnAPIObject() {}
|
func (*ClusterAutoscaler) IsAnAPIObject() {}
|
||||||
|
5
pkg/client/cache/listwatch.go
vendored
5
pkg/client/cache/listwatch.go
vendored
@ -19,6 +19,7 @@ package cache
|
|||||||
import (
|
import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"k8s.io/kubernetes/pkg/api"
|
||||||
"k8s.io/kubernetes/pkg/api/unversioned"
|
"k8s.io/kubernetes/pkg/api/unversioned"
|
||||||
client "k8s.io/kubernetes/pkg/client/unversioned"
|
client "k8s.io/kubernetes/pkg/client/unversioned"
|
||||||
"k8s.io/kubernetes/pkg/fields"
|
"k8s.io/kubernetes/pkg/fields"
|
||||||
@ -60,9 +61,7 @@ func NewListWatchFromClient(c Getter, resource string, namespace string, fieldSe
|
|||||||
Prefix("watch").
|
Prefix("watch").
|
||||||
Namespace(namespace).
|
Namespace(namespace).
|
||||||
Resource(resource).
|
Resource(resource).
|
||||||
// TODO: Use VersionedParams once this is supported for non v1 API.
|
VersionedParams(&options, api.Scheme).
|
||||||
Param("resourceVersion", options.ResourceVersion).
|
|
||||||
TimeoutSeconds(timeoutFromListOptions(options)).
|
|
||||||
FieldsSelectorParam(fieldSelector).
|
FieldsSelectorParam(fieldSelector).
|
||||||
Watch()
|
Watch()
|
||||||
}
|
}
|
||||||
|
2
pkg/client/cache/listwatch_test.go
vendored
2
pkg/client/cache/listwatch_test.go
vendored
@ -117,7 +117,7 @@ func TestListWatchesCanWatch(t *testing.T) {
|
|||||||
{
|
{
|
||||||
location: buildLocation(
|
location: buildLocation(
|
||||||
testapi.Default.ResourcePathWithPrefix("watch", "nodes", api.NamespaceAll, ""),
|
testapi.Default.ResourcePathWithPrefix("watch", "nodes", api.NamespaceAll, ""),
|
||||||
buildQueryValues(url.Values{"resourceVersion": []string{""}})),
|
buildQueryValues(url.Values{})),
|
||||||
rv: "",
|
rv: "",
|
||||||
resource: "nodes",
|
resource: "nodes",
|
||||||
namespace: api.NamespaceAll,
|
namespace: api.NamespaceAll,
|
||||||
|
@ -17,6 +17,7 @@ limitations under the License.
|
|||||||
package unversioned
|
package unversioned
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"k8s.io/kubernetes/pkg/api"
|
||||||
"k8s.io/kubernetes/pkg/api/unversioned"
|
"k8s.io/kubernetes/pkg/api/unversioned"
|
||||||
"k8s.io/kubernetes/pkg/apis/extensions"
|
"k8s.io/kubernetes/pkg/apis/extensions"
|
||||||
"k8s.io/kubernetes/pkg/fields"
|
"k8s.io/kubernetes/pkg/fields"
|
||||||
@ -97,8 +98,7 @@ func (c *daemonSets) Watch(label labels.Selector, field fields.Selector, opts un
|
|||||||
Prefix("watch").
|
Prefix("watch").
|
||||||
Namespace(c.ns).
|
Namespace(c.ns).
|
||||||
Resource("daemonsets").
|
Resource("daemonsets").
|
||||||
Param("resourceVersion", opts.ResourceVersion).
|
VersionedParams(&opts, api.Scheme).
|
||||||
TimeoutSeconds(TimeoutFromListOptions(opts)).
|
|
||||||
LabelsSelectorParam(label).
|
LabelsSelectorParam(label).
|
||||||
FieldsSelectorParam(field).
|
FieldsSelectorParam(field).
|
||||||
Watch()
|
Watch()
|
||||||
|
@ -107,8 +107,7 @@ func (c *deployments) Watch(label labels.Selector, field fields.Selector, opts u
|
|||||||
Prefix("watch").
|
Prefix("watch").
|
||||||
Namespace(c.ns).
|
Namespace(c.ns).
|
||||||
Resource("deployments").
|
Resource("deployments").
|
||||||
Param("resourceVersion", opts.ResourceVersion).
|
VersionedParams(&opts, api.Scheme).
|
||||||
TimeoutSeconds(TimeoutFromListOptions(opts)).
|
|
||||||
LabelsSelectorParam(label).
|
LabelsSelectorParam(label).
|
||||||
FieldsSelectorParam(field).
|
FieldsSelectorParam(field).
|
||||||
Watch()
|
Watch()
|
||||||
|
@ -568,12 +568,3 @@ func DefaultKubernetesUserAgent() string {
|
|||||||
version = seg[0]
|
version = seg[0]
|
||||||
return fmt.Sprintf("%s/%s (%s/%s) kubernetes/%s", path.Base(os.Args[0]), version, gruntime.GOOS, gruntime.GOARCH, commit)
|
return fmt.Sprintf("%s/%s (%s/%s) kubernetes/%s", path.Base(os.Args[0]), version, gruntime.GOOS, gruntime.GOARCH, commit)
|
||||||
}
|
}
|
||||||
|
|
||||||
// TimeoutFromListOptions returns timeout to be set via TimeoutSeconds() method
|
|
||||||
// based on given options.
|
|
||||||
func TimeoutFromListOptions(options unversioned.ListOptions) time.Duration {
|
|
||||||
if options.TimeoutSeconds != nil {
|
|
||||||
return time.Duration(*options.TimeoutSeconds) * time.Second
|
|
||||||
}
|
|
||||||
return 0
|
|
||||||
}
|
|
||||||
|
@ -109,8 +109,7 @@ func (c *horizontalPodAutoscalers) Watch(label labels.Selector, field fields.Sel
|
|||||||
Prefix("watch").
|
Prefix("watch").
|
||||||
Namespace(c.ns).
|
Namespace(c.ns).
|
||||||
Resource("horizontalPodAutoscalers").
|
Resource("horizontalPodAutoscalers").
|
||||||
Param("resourceVersion", opts.ResourceVersion).
|
VersionedParams(&opts, api.Scheme).
|
||||||
TimeoutSeconds(TimeoutFromListOptions(opts)).
|
|
||||||
LabelsSelectorParam(label).
|
LabelsSelectorParam(label).
|
||||||
FieldsSelectorParam(field).
|
FieldsSelectorParam(field).
|
||||||
Watch()
|
Watch()
|
||||||
|
@ -99,8 +99,7 @@ func (c *ingress) Watch(label labels.Selector, field fields.Selector, opts unver
|
|||||||
Prefix("watch").
|
Prefix("watch").
|
||||||
Namespace(c.ns).
|
Namespace(c.ns).
|
||||||
Resource("ingresses").
|
Resource("ingresses").
|
||||||
Param("resourceVersion", opts.ResourceVersion).
|
VersionedParams(&opts, api.Scheme).
|
||||||
TimeoutSeconds(TimeoutFromListOptions(opts)).
|
|
||||||
LabelsSelectorParam(label).
|
LabelsSelectorParam(label).
|
||||||
FieldsSelectorParam(field).
|
FieldsSelectorParam(field).
|
||||||
Watch()
|
Watch()
|
||||||
|
@ -103,8 +103,7 @@ func (c *jobs) Watch(label labels.Selector, field fields.Selector, opts unversio
|
|||||||
Prefix("watch").
|
Prefix("watch").
|
||||||
Namespace(c.ns).
|
Namespace(c.ns).
|
||||||
Resource("jobs").
|
Resource("jobs").
|
||||||
Param("resourceVersion", opts.ResourceVersion).
|
VersionedParams(&opts, api.Scheme).
|
||||||
TimeoutSeconds(TimeoutFromListOptions(opts)).
|
|
||||||
LabelsSelectorParam(label).
|
LabelsSelectorParam(label).
|
||||||
FieldsSelectorParam(field).
|
FieldsSelectorParam(field).
|
||||||
Watch()
|
Watch()
|
||||||
|
@ -498,19 +498,6 @@ func (r *Request) Timeout(d time.Duration) *Request {
|
|||||||
return r
|
return r
|
||||||
}
|
}
|
||||||
|
|
||||||
// Timeout makes the request use the given duration as a timeout. Sets the "timeoutSeconds"
|
|
||||||
// parameter.
|
|
||||||
func (r *Request) TimeoutSeconds(d time.Duration) *Request {
|
|
||||||
if r.err != nil {
|
|
||||||
return r
|
|
||||||
}
|
|
||||||
if d != 0 {
|
|
||||||
timeout := int64(d.Seconds())
|
|
||||||
r.Param("timeoutSeconds", strconv.FormatInt(timeout, 10))
|
|
||||||
}
|
|
||||||
return r
|
|
||||||
}
|
|
||||||
|
|
||||||
// Body makes the request use obj as the body. Optional.
|
// Body makes the request use obj as the body. Optional.
|
||||||
// If obj is a string, try to read a file of that name.
|
// If obj is a string, try to read a file of that name.
|
||||||
// If obj is a []byte, send it directly.
|
// If obj is a []byte, send it directly.
|
||||||
|
@ -176,16 +176,6 @@ func TestRequestParam(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestTimeoutSeconds(t *testing.T) {
|
|
||||||
r := &Request{}
|
|
||||||
r.TimeoutSeconds(time.Duration(5 * time.Second))
|
|
||||||
if !reflect.DeepEqual(r.params, url.Values{
|
|
||||||
"timeoutSeconds": []string{"5"},
|
|
||||||
}) {
|
|
||||||
t.Errorf("invalid timeoutSeconds parameter: %#v", r)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestRequestVersionedParams(t *testing.T) {
|
func TestRequestVersionedParams(t *testing.T) {
|
||||||
r := (&Request{apiVersion: "v1"}).Param("foo", "a")
|
r := (&Request{apiVersion: "v1"}).Param("foo", "a")
|
||||||
if !reflect.DeepEqual(r.params, url.Values{"foo": []string{"a"}}) {
|
if !reflect.DeepEqual(r.params, url.Values{"foo": []string{"a"}}) {
|
||||||
|
Loading…
Reference in New Issue
Block a user