mirror of
https://github.com/k3s-io/kubernetes.git
synced 2026-01-06 07:57:35 +00:00
Switch to versioned ListOptions in client.
This commit is contained in:
15
pkg/client/cache/listwatch.go
vendored
15
pkg/client/cache/listwatch.go
vendored
@@ -20,7 +20,6 @@ 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"
|
||||
"k8s.io/kubernetes/pkg/runtime"
|
||||
@@ -28,10 +27,10 @@ import (
|
||||
)
|
||||
|
||||
// ListFunc knows how to list resources
|
||||
type ListFunc func(options unversioned.ListOptions) (runtime.Object, error)
|
||||
type ListFunc func(options api.ListOptions) (runtime.Object, error)
|
||||
|
||||
// WatchFunc knows how to watch resources
|
||||
type WatchFunc func(options unversioned.ListOptions) (watch.Interface, error)
|
||||
type WatchFunc func(options api.ListOptions) (watch.Interface, error)
|
||||
|
||||
// ListWatch knows how to list and watch a set of apiserver resources. It satisfies the ListerWatcher interface.
|
||||
// It is a convenience function for users of NewReflector, etc.
|
||||
@@ -48,7 +47,7 @@ type Getter interface {
|
||||
|
||||
// NewListWatchFromClient creates a new ListWatch from the specified client, resource, namespace and field selector.
|
||||
func NewListWatchFromClient(c Getter, resource string, namespace string, fieldSelector fields.Selector) *ListWatch {
|
||||
listFunc := func(options unversioned.ListOptions) (runtime.Object, error) {
|
||||
listFunc := func(options api.ListOptions) (runtime.Object, error) {
|
||||
return c.Get().
|
||||
Namespace(namespace).
|
||||
Resource(resource).
|
||||
@@ -57,7 +56,7 @@ func NewListWatchFromClient(c Getter, resource string, namespace string, fieldSe
|
||||
Do().
|
||||
Get()
|
||||
}
|
||||
watchFunc := func(options unversioned.ListOptions) (watch.Interface, error) {
|
||||
watchFunc := func(options api.ListOptions) (watch.Interface, error) {
|
||||
return c.Get().
|
||||
Prefix("watch").
|
||||
Namespace(namespace).
|
||||
@@ -69,7 +68,7 @@ func NewListWatchFromClient(c Getter, resource string, namespace string, fieldSe
|
||||
return &ListWatch{ListFunc: listFunc, WatchFunc: watchFunc}
|
||||
}
|
||||
|
||||
func timeoutFromListOptions(options unversioned.ListOptions) time.Duration {
|
||||
func timeoutFromListOptions(options api.ListOptions) time.Duration {
|
||||
if options.TimeoutSeconds != nil {
|
||||
return time.Duration(*options.TimeoutSeconds) * time.Second
|
||||
}
|
||||
@@ -77,11 +76,11 @@ func timeoutFromListOptions(options unversioned.ListOptions) time.Duration {
|
||||
}
|
||||
|
||||
// List a set of apiserver resources
|
||||
func (lw *ListWatch) List(options unversioned.ListOptions) (runtime.Object, error) {
|
||||
func (lw *ListWatch) List(options api.ListOptions) (runtime.Object, error) {
|
||||
return lw.ListFunc(options)
|
||||
}
|
||||
|
||||
// Watch a set of apiserver resources
|
||||
func (lw *ListWatch) Watch(options unversioned.ListOptions) (watch.Interface, error) {
|
||||
func (lw *ListWatch) Watch(options api.ListOptions) (watch.Interface, error) {
|
||||
return lw.WatchFunc(options)
|
||||
}
|
||||
|
||||
4
pkg/client/cache/listwatch_test.go
vendored
4
pkg/client/cache/listwatch_test.go
vendored
@@ -99,7 +99,7 @@ func TestListWatchesCanList(t *testing.T) {
|
||||
client := client.NewOrDie(&client.Config{Host: server.URL, GroupVersion: testapi.Default.GroupVersion()})
|
||||
lw := NewListWatchFromClient(client, item.resource, item.namespace, item.fieldSelector)
|
||||
// This test merely tests that the correct request is made.
|
||||
lw.List(unversioned.ListOptions{})
|
||||
lw.List(api.ListOptions{})
|
||||
handler.ValidateRequest(t, item.location, "GET", nil)
|
||||
}
|
||||
}
|
||||
@@ -165,7 +165,7 @@ func TestListWatchesCanWatch(t *testing.T) {
|
||||
client := client.NewOrDie(&client.Config{Host: server.URL, GroupVersion: testapi.Default.GroupVersion()})
|
||||
lw := NewListWatchFromClient(client, item.resource, item.namespace, item.fieldSelector)
|
||||
// This test merely tests that the correct request is made.
|
||||
lw.Watch(unversioned.ListOptions{ResourceVersion: item.rv})
|
||||
lw.Watch(api.ListOptions{ResourceVersion: item.rv})
|
||||
handler.ValidateRequest(t, item.location, "GET", nil)
|
||||
}
|
||||
}
|
||||
|
||||
10
pkg/client/cache/reflector.go
vendored
10
pkg/client/cache/reflector.go
vendored
@@ -31,9 +31,9 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/golang/glog"
|
||||
"k8s.io/kubernetes/pkg/api"
|
||||
apierrs "k8s.io/kubernetes/pkg/api/errors"
|
||||
"k8s.io/kubernetes/pkg/api/meta"
|
||||
"k8s.io/kubernetes/pkg/api/unversioned"
|
||||
"k8s.io/kubernetes/pkg/runtime"
|
||||
"k8s.io/kubernetes/pkg/util"
|
||||
"k8s.io/kubernetes/pkg/watch"
|
||||
@@ -43,9 +43,9 @@ import (
|
||||
type ListerWatcher interface {
|
||||
// List should return a list type object; the Items field will be extracted, and the
|
||||
// ResourceVersion field will be used to start the watch in the right place.
|
||||
List(options unversioned.ListOptions) (runtime.Object, error)
|
||||
List(options api.ListOptions) (runtime.Object, error)
|
||||
// Watch should begin a watch at the specified version.
|
||||
Watch(options unversioned.ListOptions) (watch.Interface, error)
|
||||
Watch(options api.ListOptions) (watch.Interface, error)
|
||||
}
|
||||
|
||||
// Reflector watches a specified resource and causes all changes to be reflected in the given store.
|
||||
@@ -230,7 +230,7 @@ func (r *Reflector) ListAndWatch(stopCh <-chan struct{}) error {
|
||||
// Explicitly set "0" as resource version - it's fine for the List()
|
||||
// to be served from cache and potentially be delayed relative to
|
||||
// etcd contents. Reflector framework will catch up via Watch() eventually.
|
||||
options := unversioned.ListOptions{ResourceVersion: "0"}
|
||||
options := api.ListOptions{ResourceVersion: "0"}
|
||||
list, err := r.listerWatcher.List(options)
|
||||
if err != nil {
|
||||
return fmt.Errorf("%s: Failed to list %v: %v", r.name, r.expectedType, err)
|
||||
@@ -250,7 +250,7 @@ func (r *Reflector) ListAndWatch(stopCh <-chan struct{}) error {
|
||||
r.setLastSyncResourceVersion(resourceVersion)
|
||||
|
||||
for {
|
||||
options := unversioned.ListOptions{
|
||||
options := api.ListOptions{
|
||||
ResourceVersion: resourceVersion,
|
||||
// We want to avoid situations when resyncing is breaking the TCP connection
|
||||
// - see comment for 'timeoutForWatch()' for more details.
|
||||
|
||||
4
pkg/client/cache/reflector_test.go
vendored
4
pkg/client/cache/reflector_test.go
vendored
@@ -35,10 +35,10 @@ type testLW struct {
|
||||
WatchFunc func(resourceVersion string) (watch.Interface, error)
|
||||
}
|
||||
|
||||
func (t *testLW) List(options unversioned.ListOptions) (runtime.Object, error) {
|
||||
func (t *testLW) List(options api.ListOptions) (runtime.Object, error) {
|
||||
return t.ListFunc()
|
||||
}
|
||||
func (t *testLW) Watch(options unversioned.ListOptions) (watch.Interface, error) {
|
||||
func (t *testLW) Watch(options api.ListOptions) (watch.Interface, error) {
|
||||
return t.WatchFunc(options.ResourceVersion)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user