Skip to content

Commit 6d46b8f

Browse files
committed
refactor: extract config informer factory prep
OTA-1531 will need the config.openshift.io group lister early in the CVO execution and outside of the `Context` structure, so this commit moves the necessary preparation code outside of `NewControllerContext` and passes these factories into it as parameters. Constructing factories at separate places is a little awkward but for now I try keeping the change small instead of trying to invent some centralized informer factory management. I think it is reasonable to treat config.openshift.io informers separately if they are actually used separately.
1 parent eeed4fa commit 6d46b8f

File tree

2 files changed

+24
-11
lines changed

2 files changed

+24
-11
lines changed

pkg/start/start.go

Lines changed: 15 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
@@ -510,22 +522,17 @@ type Context struct {
510522

511523
// NewControllerContext initializes the default Context for the current Options. It does
512524
// not start any background processes.
513-
func (o *Options) NewControllerContext(cb *ClientBuilder) (*Context, error) {
514-
client := cb.ClientOrDie("shared-informer")
525+
func (o *Options) NewControllerContext(cb *ClientBuilder, clusterVersionConfigInformerFactory, configInformerFactory configinformers.SharedInformerFactory) (*Context, error) {
515526
kubeClient := cb.KubeClientOrDie(internal.ConfigNamespace, useProtobuf)
516527
openshiftConfigInformerFactory := coreinformers.NewSharedInformerFactoryWithOptions(kubeClient, resyncPeriod(o.ResyncInterval), coreinformers.WithNamespace(internal.ConfigNamespace))
517528
openshiftConfigManagedInformerFactory := coreinformers.NewSharedInformerFactoryWithOptions(kubeClient, resyncPeriod(o.ResyncInterval), coreinformers.WithNamespace(internal.ConfigManagedNamespace))
518529

519-
clusterVersionConfigInformerFactory := configinformers.NewFilteredSharedInformerFactory(client, resyncPeriod(o.ResyncInterval), "", func(opts *metav1.ListOptions) {
520-
opts.FieldSelector = fmt.Sprintf("metadata.name=%s", o.Name)
521-
})
522-
configInformerFactory := configinformers.NewSharedInformerFactory(client, resyncPeriod(o.ResyncInterval))
523-
524530
operatorClient := cb.OperatorClientOrDie("operator-client")
525531
filterByName := func(opts *metav1.ListOptions) {
526532
opts.FieldSelector = fields.OneTermEqualSelector("metadata.name", configuration.ClusterVersionOperatorConfigurationName).String()
527533
}
528534
operatorInformerFactory := operatorinformers.NewSharedInformerFactoryWithOptions(operatorClient, o.ResyncInterval, operatorinformers.WithTweakListOptions(filterByName))
535+
529536
coInformer := configInformerFactory.Config().V1().ClusterOperators()
530537

531538
cvoKubeClient := cb.KubeClientOrDie(o.Namespace, useProtobuf)

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)