mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-30 06:54:01 +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() {
|
||||
Scheme.AddDefaultingFuncs(
|
||||
func(obj *unversioned.ListOptions) {
|
||||
obj.LabelSelector = unversioned.LabelSelector{labels.Everything()}
|
||||
obj.FieldSelector = unversioned.FieldSelector{fields.Everything()}
|
||||
if obj.LabelSelector.Selector == nil {
|
||||
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
|
||||
func(obj *PodExecOptions) {
|
||||
@ -135,6 +139,28 @@ func init() {
|
||||
*out = in.Selector.String()
|
||||
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 {
|
||||
// Cannot deep copy these, because inf.Dec has unexported fields.
|
||||
*out = *in.Copy()
|
||||
|
@ -57,6 +57,10 @@ func addKnownTypes() {
|
||||
&Ingress{},
|
||||
&IngressList{},
|
||||
)
|
||||
|
||||
// Register Unversioned types
|
||||
// TODO this should not be done here
|
||||
api.Scheme.AddKnownTypes(SchemeGroupVersion, &unversioned.ListOptions{})
|
||||
}
|
||||
|
||||
func (*ClusterAutoscaler) IsAnAPIObject() {}
|
||||
|
@ -55,6 +55,10 @@ func addKnownTypes() {
|
||||
&Ingress{},
|
||||
&IngressList{},
|
||||
)
|
||||
|
||||
// Register Unversioned types
|
||||
// TODO this should not be done here
|
||||
api.Scheme.AddKnownTypes(SchemeGroupVersion, &unversioned.ListOptions{})
|
||||
}
|
||||
|
||||
func (*ClusterAutoscaler) IsAnAPIObject() {}
|
||||
|
5
pkg/client/cache/listwatch.go
vendored
5
pkg/client/cache/listwatch.go
vendored
@ -19,6 +19,7 @@ package cache
|
||||
import (
|
||||
"time"
|
||||
|
||||
"k8s.io/kubernetes/pkg/api"
|
||||
"k8s.io/kubernetes/pkg/api/unversioned"
|
||||
client "k8s.io/kubernetes/pkg/client/unversioned"
|
||||
"k8s.io/kubernetes/pkg/fields"
|
||||
@ -60,9 +61,7 @@ func NewListWatchFromClient(c Getter, resource string, namespace string, fieldSe
|
||||
Prefix("watch").
|
||||
Namespace(namespace).
|
||||
Resource(resource).
|
||||
// TODO: Use VersionedParams once this is supported for non v1 API.
|
||||
Param("resourceVersion", options.ResourceVersion).
|
||||
TimeoutSeconds(timeoutFromListOptions(options)).
|
||||
VersionedParams(&options, api.Scheme).
|
||||
FieldsSelectorParam(fieldSelector).
|
||||
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(
|
||||
testapi.Default.ResourcePathWithPrefix("watch", "nodes", api.NamespaceAll, ""),
|
||||
buildQueryValues(url.Values{"resourceVersion": []string{""}})),
|
||||
buildQueryValues(url.Values{})),
|
||||
rv: "",
|
||||
resource: "nodes",
|
||||
namespace: api.NamespaceAll,
|
||||
|
@ -17,6 +17,7 @@ limitations under the License.
|
||||
package unversioned
|
||||
|
||||
import (
|
||||
"k8s.io/kubernetes/pkg/api"
|
||||
"k8s.io/kubernetes/pkg/api/unversioned"
|
||||
"k8s.io/kubernetes/pkg/apis/extensions"
|
||||
"k8s.io/kubernetes/pkg/fields"
|
||||
@ -97,8 +98,7 @@ func (c *daemonSets) Watch(label labels.Selector, field fields.Selector, opts un
|
||||
Prefix("watch").
|
||||
Namespace(c.ns).
|
||||
Resource("daemonsets").
|
||||
Param("resourceVersion", opts.ResourceVersion).
|
||||
TimeoutSeconds(TimeoutFromListOptions(opts)).
|
||||
VersionedParams(&opts, api.Scheme).
|
||||
LabelsSelectorParam(label).
|
||||
FieldsSelectorParam(field).
|
||||
Watch()
|
||||
|
@ -107,8 +107,7 @@ func (c *deployments) Watch(label labels.Selector, field fields.Selector, opts u
|
||||
Prefix("watch").
|
||||
Namespace(c.ns).
|
||||
Resource("deployments").
|
||||
Param("resourceVersion", opts.ResourceVersion).
|
||||
TimeoutSeconds(TimeoutFromListOptions(opts)).
|
||||
VersionedParams(&opts, api.Scheme).
|
||||
LabelsSelectorParam(label).
|
||||
FieldsSelectorParam(field).
|
||||
Watch()
|
||||
|
@ -568,12 +568,3 @@ func DefaultKubernetesUserAgent() string {
|
||||
version = seg[0]
|
||||
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").
|
||||
Namespace(c.ns).
|
||||
Resource("horizontalPodAutoscalers").
|
||||
Param("resourceVersion", opts.ResourceVersion).
|
||||
TimeoutSeconds(TimeoutFromListOptions(opts)).
|
||||
VersionedParams(&opts, api.Scheme).
|
||||
LabelsSelectorParam(label).
|
||||
FieldsSelectorParam(field).
|
||||
Watch()
|
||||
|
@ -99,8 +99,7 @@ func (c *ingress) Watch(label labels.Selector, field fields.Selector, opts unver
|
||||
Prefix("watch").
|
||||
Namespace(c.ns).
|
||||
Resource("ingresses").
|
||||
Param("resourceVersion", opts.ResourceVersion).
|
||||
TimeoutSeconds(TimeoutFromListOptions(opts)).
|
||||
VersionedParams(&opts, api.Scheme).
|
||||
LabelsSelectorParam(label).
|
||||
FieldsSelectorParam(field).
|
||||
Watch()
|
||||
|
@ -103,8 +103,7 @@ func (c *jobs) Watch(label labels.Selector, field fields.Selector, opts unversio
|
||||
Prefix("watch").
|
||||
Namespace(c.ns).
|
||||
Resource("jobs").
|
||||
Param("resourceVersion", opts.ResourceVersion).
|
||||
TimeoutSeconds(TimeoutFromListOptions(opts)).
|
||||
VersionedParams(&opts, api.Scheme).
|
||||
LabelsSelectorParam(label).
|
||||
FieldsSelectorParam(field).
|
||||
Watch()
|
||||
|
@ -498,19 +498,6 @@ func (r *Request) Timeout(d time.Duration) *Request {
|
||||
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.
|
||||
// If obj is a string, try to read a file of that name.
|
||||
// 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) {
|
||||
r := (&Request{apiVersion: "v1"}).Param("foo", "a")
|
||||
if !reflect.DeepEqual(r.params, url.Values{"foo": []string{"a"}}) {
|
||||
|
Loading…
Reference in New Issue
Block a user