Skip to content

Commit b17dc08

Browse files
committed
refactor: extract config informer factory prep
1 parent 0c2dfda commit b17dc08

File tree

2 files changed

+23
-11
lines changed

2 files changed

+23
-11
lines changed

pkg/start/start.go

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -214,8 +214,10 @@ func (o *Options) Run(ctx context.Context) error {
214214
klog.Infof("Determined OCP version for this CVO: %q", cvoOcpVersion)
215215
}
216216

217+
clusterVersionConfigInformerFactory, configInformerFactory := o.prepareConfigInformerFactories(cb)
218+
217219
// initialize the controllers and attempt to load the payload information
218-
controllerCtx, err := o.NewControllerContext(cb)
220+
controllerCtx, err := o.NewControllerContext(cb, clusterVersionConfigInformerFactory, configInformerFactory)
219221
if err != nil {
220222
return err
221223
}
@@ -224,6 +226,16 @@ func (o *Options) Run(ctx context.Context) error {
224226
return nil
225227
}
226228

229+
func (o *Options) prepareConfigInformerFactories(cb *ClientBuilder) (configinformers.SharedInformerFactory, configinformers.SharedInformerFactory) {
230+
client := cb.ClientOrDie("shared-informer")
231+
clusterVersionConfigInformerFactory := configinformers.NewFilteredSharedInformerFactory(client, resyncPeriod(o.ResyncInterval), "", func(opts *metav1.ListOptions) {
232+
opts.FieldSelector = fmt.Sprintf("metadata.name=%s", o.Name)
233+
})
234+
configInformerFactory := configinformers.NewSharedInformerFactory(client, resyncPeriod(o.ResyncInterval))
235+
236+
return clusterVersionConfigInformerFactory, configInformerFactory
237+
}
238+
227239
// run launches a number of goroutines to handle manifest application,
228240
// metrics serving, etc. It continues operating until ctx.Done(),
229241
// and then attempts a clean shutdown limited by an internal context
@@ -500,15 +512,9 @@ type Context struct {
500512

501513
// NewControllerContext initializes the default Context for the current Options. It does
502514
// not start any background processes.
503-
func (o *Options) NewControllerContext(cb *ClientBuilder) (*Context, error) {
504-
client := cb.ClientOrDie("shared-informer")
515+
func (o *Options) NewControllerContext(cb *ClientBuilder, clusterVersionConfigInformerFactory, configInformerFactory configinformers.SharedInformerFactory) (*Context, error) {
505516
kubeClient := cb.KubeClientOrDie(internal.ConfigNamespace, useProtobuf)
506517
operatorClient := cb.OperatorClientOrDie("operator-client")
507-
508-
clusterVersionConfigInformerFactory := configinformers.NewFilteredSharedInformerFactory(client, resyncPeriod(o.ResyncInterval), "", func(opts *metav1.ListOptions) {
509-
opts.FieldSelector = fmt.Sprintf("metadata.name=%s", o.Name)
510-
})
511-
configInformerFactory := configinformers.NewSharedInformerFactory(client, resyncPeriod(o.ResyncInterval))
512518
openshiftConfigInformer := coreinformers.NewSharedInformerFactoryWithOptions(kubeClient, resyncPeriod(o.ResyncInterval), coreinformers.WithNamespace(internal.ConfigNamespace))
513519
openshiftConfigManagedInformer := coreinformers.NewSharedInformerFactoryWithOptions(kubeClient, resyncPeriod(o.ResyncInterval), coreinformers.WithNamespace(internal.ConfigManagedNamespace))
514520
operatorInformerFactory := operatorinformers.NewSharedInformerFactoryWithOptions(operatorClient, o.ResyncInterval,

pkg/start/start_integration_test.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,9 @@ func TestIntegrationCVO_initializeAndUpgrade(t *testing.T) {
188188
if err := options.ValidateAndComplete(); err != nil {
189189
t.Fatalf("incorrectly initialized options: %v", err)
190190
}
191-
controllers, err := options.NewControllerContext(cb)
191+
192+
cvif, cif := options.prepareConfigInformerFactories(cb)
193+
controllers, err := options.NewControllerContext(cb, cvif, cif)
192194
if err != nil {
193195
t.Fatal(err)
194196
}
@@ -323,7 +325,9 @@ func TestIntegrationCVO_gracefulStepDown(t *testing.T) {
323325
if err := options.ValidateAndComplete(); err != nil {
324326
t.Fatalf("incorrectly initialized options: %v", err)
325327
}
326-
controllers, err := options.NewControllerContext(cb)
328+
329+
cvif, cif := options.prepareConfigInformerFactories(cb)
330+
controllers, err := options.NewControllerContext(cb, cvif, cif)
327331
if err != nil {
328332
t.Fatal(err)
329333
}
@@ -520,7 +524,9 @@ metadata:
520524
if err := options.ValidateAndComplete(); err != nil {
521525
t.Fatalf("incorrectly initialized options: %v", err)
522526
}
523-
controllers, err := options.NewControllerContext(cb)
527+
528+
cvif, cif := options.prepareConfigInformerFactories(cb)
529+
controllers, err := options.NewControllerContext(cb, cvif, cif)
524530
if err != nil {
525531
t.Fatal(err)
526532
}

0 commit comments

Comments
 (0)