manually sync with k8s.io/kubernetest at 17375fc59fff39135af63bd1750bb07c36ef873b, k8s.io/apimachinery at d90aa2c8531f13b0ca734845934c10dcb6a56ca7

This commit is contained in:
Chao Xu
2017-02-23 12:23:54 -08:00
parent 5fbce75e01
commit 088dc4a30d
304 changed files with 37541 additions and 6673 deletions

View File

@@ -112,7 +112,7 @@ type ResourceClient struct {
}
// List returns a list of objects for this resource.
func (rc *ResourceClient) List(opts runtime.Object) (runtime.Object, error) {
func (rc *ResourceClient) List(opts metav1.ListOptions) (runtime.Object, error) {
parameterEncoder := rc.parameterCodec
if parameterEncoder == nil {
parameterEncoder = defaultParameterEncoder
@@ -120,7 +120,7 @@ func (rc *ResourceClient) List(opts runtime.Object) (runtime.Object, error) {
return rc.cl.Get().
NamespaceIfScoped(rc.ns, rc.resource.Namespaced).
Resource(rc.resource.Name).
VersionedParams(opts, parameterEncoder).
VersionedParams(&opts, parameterEncoder).
Do().
Get()
}
@@ -149,7 +149,7 @@ func (rc *ResourceClient) Delete(name string, opts *metav1.DeleteOptions) error
}
// DeleteCollection deletes a collection of objects.
func (rc *ResourceClient) DeleteCollection(deleteOptions *metav1.DeleteOptions, listOptions runtime.Object) error {
func (rc *ResourceClient) DeleteCollection(deleteOptions *metav1.DeleteOptions, listOptions metav1.ListOptions) error {
parameterEncoder := rc.parameterCodec
if parameterEncoder == nil {
parameterEncoder = defaultParameterEncoder
@@ -157,7 +157,7 @@ func (rc *ResourceClient) DeleteCollection(deleteOptions *metav1.DeleteOptions,
return rc.cl.Delete().
NamespaceIfScoped(rc.ns, rc.resource.Namespaced).
Resource(rc.resource.Name).
VersionedParams(listOptions, parameterEncoder).
VersionedParams(&listOptions, parameterEncoder).
Body(deleteOptions).
Do().
Error()
@@ -192,16 +192,16 @@ func (rc *ResourceClient) Update(obj *unstructured.Unstructured) (*unstructured.
}
// Watch returns a watch.Interface that watches the resource.
func (rc *ResourceClient) Watch(opts runtime.Object) (watch.Interface, error) {
func (rc *ResourceClient) Watch(opts metav1.ListOptions) (watch.Interface, error) {
parameterEncoder := rc.parameterCodec
if parameterEncoder == nil {
parameterEncoder = defaultParameterEncoder
}
opts.Watch = true
return rc.cl.Get().
Prefix("watch").
NamespaceIfScoped(rc.ns, rc.resource.Namespaced).
Resource(rc.resource.Name).
VersionedParams(opts, parameterEncoder).
VersionedParams(&opts, parameterEncoder).
Watch()
}

View File

@@ -21,6 +21,7 @@ import (
"k8s.io/apimachinery/pkg/api/meta"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/client-go/pkg/api"
restclient "k8s.io/client-go/rest"
)
@@ -70,6 +71,13 @@ func NewClientPool(config *restclient.Config, mapper meta.RESTMapper, apiPathRes
}
}
// Instantiates a new dynamic client pool with the given config.
func NewDynamicClientPool(cfg *restclient.Config) ClientPool {
// TODO: should use a dynamic RESTMapper built from the discovery results.
restMapper := api.Registry.RESTMapper()
return NewClientPool(cfg, restMapper, LegacyAPIPathResolverFunc)
}
// ClientForGroupVersionResource uses the provided RESTMapper to identify the appropriate resource. Resource may
// be empty. If no matching kind is found the underlying client for that group is still returned.
func (c *clientPoolImpl) ClientForGroupVersionResource(resource schema.GroupVersionResource) (*Client, error) {

View File

@@ -136,7 +136,7 @@ func TestList(t *testing.T) {
}
defer srv.Close()
got, err := cl.Resource(resource, tc.namespace).List(&metav1.ListOptions{})
got, err := cl.Resource(resource, tc.namespace).List(metav1.ListOptions{})
if err != nil {
t.Errorf("unexpected error when listing %q: %v", tc.name, err)
continue
@@ -293,7 +293,7 @@ func TestDeleteCollection(t *testing.T) {
}
defer srv.Close()
err = cl.Resource(resource, tc.namespace).DeleteCollection(nil, &metav1.ListOptions{})
err = cl.Resource(resource, tc.namespace).DeleteCollection(nil, metav1.ListOptions{})
if err != nil {
t.Errorf("unexpected error when deleting collection %q: %v", tc.name, err)
continue
@@ -425,10 +425,12 @@ func TestWatch(t *testing.T) {
namespace string
events []watch.Event
path string
query string
}{
{
name: "normal_watch",
path: "/api/gtest/vtest/watch/rtest",
name: "normal_watch",
path: "/api/gtest/vtest/rtest",
query: "watch=true",
events: []watch.Event{
{Type: watch.Added, Object: getObject("vTest", "rTest", "normal_watch")},
{Type: watch.Modified, Object: getObject("vTest", "rTest", "normal_watch")},
@@ -438,7 +440,8 @@ func TestWatch(t *testing.T) {
{
name: "namespaced_watch",
namespace: "nstest",
path: "/api/gtest/vtest/watch/namespaces/nstest/rtest",
path: "/api/gtest/vtest/namespaces/nstest/rtest",
query: "watch=true",
events: []watch.Event{
{Type: watch.Added, Object: getObject("vTest", "rTest", "namespaced_watch")},
{Type: watch.Modified, Object: getObject("vTest", "rTest", "namespaced_watch")},
@@ -457,6 +460,9 @@ func TestWatch(t *testing.T) {
if r.URL.Path != tc.path {
t.Errorf("Watch(%q) got path %s. wanted %s", tc.name, r.URL.Path, tc.path)
}
if r.URL.RawQuery != tc.query {
t.Errorf("Watch(%q) got query %s. wanted %s", tc.name, r.URL.RawQuery, tc.query)
}
enc := restclientwatch.NewEncoder(streaming.NewEncoder(w, dynamicCodec{}), dynamicCodec{})
for _, e := range tc.events {
@@ -469,7 +475,7 @@ func TestWatch(t *testing.T) {
}
defer srv.Close()
watcher, err := cl.Resource(resource, tc.namespace).Watch(&metav1.ListOptions{})
watcher, err := cl.Resource(resource, tc.namespace).Watch(metav1.ListOptions{})
if err != nil {
t.Errorf("unexpected error when watching %q: %v", tc.name, err)
continue