@@ -6,13 +6,12 @@ import (
6
6
7
7
"github.com/openshift/library-go/pkg/controller/controllercmd"
8
8
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
9
- "k8s.io/client-go/tools/clientcmd"
10
9
11
10
clusterclientset "open-cluster-management.io/api/client/cluster/clientset/versioned"
12
11
clusterinformers "open-cluster-management.io/api/client/cluster/informers/externalversions"
13
12
workclientset "open-cluster-management.io/api/client/work/clientset/versioned"
14
13
workinformers "open-cluster-management.io/api/client/work/informers/externalversions"
15
- workv1informer "open-cluster-management.io/api/client/work/informers/externalversions/work/v1"
14
+ workv1informers "open-cluster-management.io/api/client/work/informers/externalversions/work/v1"
16
15
workapplier "open-cluster-management.io/sdk-go/pkg/apis/work/v1/applier"
17
16
"open-cluster-management.io/sdk-go/pkg/cloudevents/clients/options"
18
17
"open-cluster-management.io/sdk-go/pkg/cloudevents/clients/work"
@@ -47,7 +46,7 @@ func (c *WorkHubManagerConfig) RunWorkHubManager(ctx context.Context, controller
47
46
clusterInformerFactory := clusterinformers .NewSharedInformerFactory (hubClusterClient , 30 * time .Minute )
48
47
49
48
// build a hub work client for ManifestWorkReplicaSets
50
- replicaSetsClient , err := workclientset .NewForConfig (controllerContext .KubeConfig )
49
+ workClient , err := workclientset .NewForConfig (controllerContext .KubeConfig )
51
50
if err != nil {
52
51
return err
53
52
}
@@ -68,28 +67,38 @@ func (c *WorkHubManagerConfig) RunWorkHubManager(ctx context.Context, controller
68
67
},
69
68
)
70
69
71
- var workClient workclientset. Interface
72
- var watcherStore * store. SourceInformerWatcherStore
70
+ workInformers := workinformers . NewSharedInformerFactoryWithOptions ( workClient , 30 * time . Minute , workInformOption )
71
+ replicaSetInformers := workinformers . NewSharedInformerFactory ( workClient , 30 * time . Minute )
73
72
74
- if c .workOptions .WorkDriver == "kube" {
75
- config := controllerContext .KubeConfig
76
- if c .workOptions .WorkDriverConfig != "" {
77
- config , err = clientcmd .BuildConfigFromFlags ("" , c .workOptions .WorkDriverConfig )
78
- if err != nil {
79
- return err
80
- }
81
- }
73
+ return c .RunControllerManagerWithInformers (
74
+ ctx ,
75
+ controllerContext ,
76
+ workClient ,
77
+ replicaSetInformers ,
78
+ workInformers ,
79
+ clusterInformerFactory ,
80
+ )
81
+ }
82
82
83
- workClient , err = workclientset .NewForConfig (config )
84
- if err != nil {
85
- return err
86
- }
83
+ func (c * WorkHubManagerConfig ) RunControllerManagerWithInformers (
84
+ ctx context.Context ,
85
+ controllerContext * controllercmd.ControllerContext ,
86
+ workClient workclientset.Interface ,
87
+ replicaSetInformers workinformers.SharedInformerFactory ,
88
+ workInformers workinformers.SharedInformerFactory ,
89
+ clusterInformers clusterinformers.SharedInformerFactory ,
90
+ ) error {
91
+ var manifestWorkClient workclientset.Interface
92
+ var manifestWorkInformer workv1informers.ManifestWorkInformer
93
+
94
+ if c .workOptions .WorkDriver == "kube" {
95
+ manifestWorkClient = workClient
96
+ manifestWorkInformer = workInformers .Work ().V1 ().ManifestWorks ()
87
97
} else {
88
98
// For cloudevents drivers, we build ManifestWork client that implements the
89
99
// ManifestWorkInterface and ManifestWork informer based on different driver configuration.
90
100
// Refer to Event Based Manifestwork proposal in enhancements repo to get more details.
91
-
92
- watcherStore = store .NewSourceInformerWatcherStore (ctx )
101
+ watcherStore := store .NewSourceInformerWatcherStore (ctx )
93
102
94
103
_ , config , err := generic .NewConfigLoader (c .workOptions .WorkDriver , c .workOptions .WorkDriverConfig ).
95
104
LoadConfig ()
@@ -106,52 +115,28 @@ func (c *WorkHubManagerConfig) RunWorkHubManager(ctx context.Context, controller
106
115
return err
107
116
}
108
117
109
- workClient = clientHolder .WorkInterface ()
110
- }
118
+ manifestWorkClient = clientHolder .WorkInterface ()
111
119
112
- factory := workinformers .NewSharedInformerFactoryWithOptions (workClient , 30 * time .Minute , workInformOption )
113
- informer := factory .Work ().V1 ().ManifestWorks ()
114
-
115
- // For cloudevents work client, we use the informer store as the client store
116
- if watcherStore != nil {
117
- watcherStore .SetInformer (informer .Informer ())
120
+ ceInformers := workinformers .NewSharedInformerFactoryWithOptions (workClient , 30 * time .Minute )
121
+ manifestWorkInformer = ceInformers .Work ().V1 ().ManifestWorks ()
122
+ watcherStore .SetInformer (manifestWorkInformer .Informer ())
118
123
}
119
124
120
- return RunControllerManagerWithInformers (
121
- ctx ,
122
- controllerContext ,
123
- replicaSetsClient ,
124
- workClient ,
125
- informer ,
126
- clusterInformerFactory ,
127
- )
128
- }
129
-
130
- func RunControllerManagerWithInformers (
131
- ctx context.Context ,
132
- controllerContext * controllercmd.ControllerContext ,
133
- replicaSetClient workclientset.Interface ,
134
- workClient workclientset.Interface ,
135
- workInformer workv1informer.ManifestWorkInformer ,
136
- clusterInformers clusterinformers.SharedInformerFactory ,
137
- ) error {
138
- replicaSetInformerFactory := workinformers .NewSharedInformerFactory (replicaSetClient , 30 * time .Minute )
139
-
140
125
manifestWorkReplicaSetController := manifestworkreplicasetcontroller .NewManifestWorkReplicaSetController (
141
126
controllerContext .EventRecorder ,
142
- replicaSetClient ,
143
- workapplier .NewWorkApplierWithTypedClient (workClient , workInformer .Lister ()),
144
- replicaSetInformerFactory .Work ().V1alpha1 ().ManifestWorkReplicaSets (),
145
- workInformer ,
127
+ workClient ,
128
+ workapplier .NewWorkApplierWithTypedClient (manifestWorkClient , manifestWorkInformer .Lister ()),
129
+ replicaSetInformers .Work ().V1alpha1 ().ManifestWorkReplicaSets (),
130
+ manifestWorkInformer ,
146
131
clusterInformers .Cluster ().V1beta1 ().Placements (),
147
132
clusterInformers .Cluster ().V1beta1 ().PlacementDecisions (),
148
133
)
149
134
150
135
go clusterInformers .Start (ctx .Done ())
151
- go replicaSetInformerFactory .Start (ctx .Done ())
136
+ go replicaSetInformers .Start (ctx .Done ())
152
137
go manifestWorkReplicaSetController .Run (ctx , 5 )
153
138
154
- go workInformer .Informer ().Run (ctx .Done ())
139
+ go manifestWorkInformer .Informer ().Run (ctx .Done ())
155
140
156
141
<- ctx .Done ()
157
142
return nil
0 commit comments