@@ -31,6 +31,7 @@ import (
31
31
"k8s.io/apimachinery/pkg/runtime/schema"
32
32
utilrand "k8s.io/apimachinery/pkg/util/rand"
33
33
"k8s.io/apimachinery/pkg/util/validation/field"
34
+ "k8s.io/apimachinery/pkg/watch"
34
35
"k8s.io/client-go/kubernetes/scheme"
35
36
"k8s.io/client-go/testing"
36
37
@@ -49,7 +50,7 @@ type fakeClient struct {
49
50
scheme * runtime.Scheme
50
51
}
51
52
52
- var _ client.Client = & fakeClient {}
53
+ var _ client.WithWatch = & fakeClient {}
53
54
54
55
const (
55
56
maxNameLength = 63
@@ -61,7 +62,7 @@ const (
61
62
// You can choose to initialize it with a slice of runtime.Object.
62
63
//
63
64
// Deprecated: Please use NewClientBuilder instead.
64
- func NewFakeClient (initObjs ... runtime.Object ) client.Client {
65
+ func NewFakeClient (initObjs ... runtime.Object ) client.WithWatch {
65
66
return NewClientBuilder ().WithRuntimeObjects (initObjs ... ).Build ()
66
67
}
67
68
@@ -70,7 +71,7 @@ func NewFakeClient(initObjs ...runtime.Object) client.Client {
70
71
// You can choose to initialize it with a slice of runtime.Object.
71
72
//
72
73
// Deprecated: Please use NewClientBuilder instead.
73
- func NewFakeClientWithScheme (clientScheme * runtime.Scheme , initObjs ... runtime.Object ) client.Client {
74
+ func NewFakeClientWithScheme (clientScheme * runtime.Scheme , initObjs ... runtime.Object ) client.WithWatch {
74
75
return NewClientBuilder ().WithScheme (clientScheme ).WithRuntimeObjects (initObjs ... ).Build ()
75
76
}
76
77
@@ -113,7 +114,7 @@ func (f *ClientBuilder) WithRuntimeObjects(initRuntimeObjs ...runtime.Object) *C
113
114
}
114
115
115
116
// Build builds and returns a new fake client.
116
- func (f * ClientBuilder ) Build () client.Client {
117
+ func (f * ClientBuilder ) Build () client.WithWatch {
117
118
if f .scheme == nil {
118
119
f .scheme = scheme .Scheme
119
120
}
@@ -284,6 +285,23 @@ func (c *fakeClient) Get(ctx context.Context, key client.ObjectKey, obj client.O
284
285
return err
285
286
}
286
287
288
+ func (c * fakeClient ) Watch (ctx context.Context , list client.ObjectList , opts ... client.ListOption ) (watch.Interface , error ) {
289
+ gvk , err := apiutil .GVKForObject (list , c .scheme )
290
+ if err != nil {
291
+ return nil , err
292
+ }
293
+
294
+ if strings .HasSuffix (gvk .Kind , "List" ) {
295
+ gvk .Kind = gvk .Kind [:len (gvk .Kind )- 4 ]
296
+ }
297
+
298
+ listOpts := client.ListOptions {}
299
+ listOpts .ApplyOptions (opts )
300
+
301
+ gvr , _ := meta .UnsafeGuessKindToResource (gvk )
302
+ return c .tracker .Watch (gvr , listOpts .Namespace )
303
+ }
304
+
287
305
func (c * fakeClient ) List (ctx context.Context , obj client.ObjectList , opts ... client.ListOption ) error {
288
306
gvk , err := apiutil .GVKForObject (obj , c .scheme )
289
307
if err != nil {
0 commit comments