@@ -21,11 +21,14 @@ import (
21
21
"fmt"
22
22
"sync"
23
23
24
+ "k8s.io/apimachinery/pkg/api/meta"
24
25
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
25
26
"k8s.io/apimachinery/pkg/labels"
26
27
"k8s.io/apimachinery/pkg/runtime/schema"
28
+ "k8s.io/client-go/dynamic"
27
29
"k8s.io/client-go/rest"
28
30
ctrl "sigs.k8s.io/controller-runtime"
31
+ "sigs.k8s.io/controller-runtime/pkg/client/apiutil"
29
32
"sigs.k8s.io/controller-runtime/pkg/controller"
30
33
"sigs.k8s.io/controller-runtime/pkg/handler"
31
34
"sigs.k8s.io/controller-runtime/pkg/log"
@@ -85,7 +88,31 @@ func WatchChildren(options WatchChildrenOptions) (chan struct{}, error) {
85
88
return nil , fmt .Errorf ("labelMaker is required to scope watches" )
86
89
}
87
90
88
- dw , events , err := watch .NewDynamicWatch (* options .RESTConfig )
91
+ if options .RESTConfig == nil {
92
+ if options .Manager != nil {
93
+ options .RESTConfig = options .Manager .GetConfig ()
94
+ } else {
95
+ return nil , fmt .Errorf ("RESTConfig or Manager should be set" )
96
+ }
97
+ }
98
+
99
+ var restMapper meta.RESTMapper
100
+ if options .Manager != nil {
101
+ restMapper = options .Manager .GetRESTMapper ()
102
+ } else {
103
+ rm , err := apiutil .NewDiscoveryRESTMapper (options .RESTConfig )
104
+ if err != nil {
105
+ return nil , err
106
+ }
107
+ restMapper = rm
108
+ }
109
+
110
+ client , err := dynamic .NewForConfig (options .RESTConfig )
111
+ if err != nil {
112
+ return nil , err
113
+ }
114
+
115
+ dw , events , err := watch .NewDynamicWatch (restMapper , client )
89
116
if err != nil {
90
117
return nil , fmt .Errorf ("creating dynamic watch: %v" , err )
91
118
}
0 commit comments