@@ -23,7 +23,6 @@ import (
23
23
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
24
24
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
25
25
"k8s.io/apimachinery/pkg/watch"
26
- "k8s.io/client-go/dynamic"
27
26
"k8s.io/client-go/rest"
28
27
)
29
28
@@ -33,16 +32,11 @@ func NewWithWatch(config *rest.Config, options Options) (WithWatch, error) {
33
32
if err != nil {
34
33
return nil , err
35
34
}
36
- dynamicClient , err := dynamic .NewForConfig (config )
37
- if err != nil {
38
- return nil , err
39
- }
40
- return & watchingClient {client : client , dynamic : dynamicClient }, nil
35
+ return & watchingClient {client : client }, nil
41
36
}
42
37
43
38
type watchingClient struct {
44
39
* client
45
- dynamic dynamic.Interface
46
40
}
47
41
48
42
func (w * watchingClient ) Watch (ctx context.Context , list ObjectList , opts ... ListOption ) (watch.Interface , error ) {
@@ -82,20 +76,18 @@ func (w *watchingClient) metadataWatch(ctx context.Context, obj *metav1.PartialO
82
76
}
83
77
84
78
func (w * watchingClient ) unstructuredWatch (ctx context.Context , obj * unstructured.UnstructuredList , opts ... ListOption ) (watch.Interface , error ) {
85
- gvk := obj .GroupVersionKind ()
86
- gvk .Kind = strings .TrimSuffix (gvk .Kind , "List" )
87
-
88
79
r , err := w .client .unstructuredClient .resources .getResource (obj )
89
80
if err != nil {
90
81
return nil , err
91
82
}
92
83
93
84
listOpts := w .listOpts (opts ... )
94
85
95
- if listOpts .Namespace != "" && r .isNamespaced () {
96
- return w .dynamic .Resource (r .mapping .Resource ).Namespace (listOpts .Namespace ).Watch (ctx , * listOpts .AsListOptions ())
97
- }
98
- return w .dynamic .Resource (r .mapping .Resource ).Watch (ctx , * listOpts .AsListOptions ())
86
+ return r .Get ().
87
+ NamespaceIfScoped (listOpts .Namespace , r .isNamespaced ()).
88
+ Resource (r .resource ()).
89
+ VersionedParams (listOpts .AsListOptions (), w .client .unstructuredClient .paramCodec ).
90
+ Watch (ctx )
99
91
}
100
92
101
93
func (w * watchingClient ) typedWatch (ctx context.Context , obj ObjectList , opts ... ListOption ) (watch.Interface , error ) {
0 commit comments