Skip to content

Commit fdbec82

Browse files
committed
Introduce informer for olmConfig
1 parent e4f17f1 commit fdbec82

File tree

1 file changed

+85
-0
lines changed

1 file changed

+85
-0
lines changed

pkg/controller/operators/olm/operator.go

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,27 @@ func newOperatorWithConfig(ctx context.Context, config *operatorConfig) (*Operat
257257
return nil, err
258258
}
259259

260+
// Register QueueInformer for olmConfig
261+
olmConfigInformer := externalversions.NewSharedInformerFactoryWithOptions(
262+
op.client,
263+
config.resyncPeriod(),
264+
).Operators().V1().OLMConfigs().Informer()
265+
olmConfigQueue := workqueue.NewNamedRateLimitingQueue(workqueue.DefaultControllerRateLimiter(), fmt.Sprintf("%s/olm-config", namespace))
266+
olmConfigQueueInformer, err := queueinformer.NewQueueInformer(
267+
ctx,
268+
queueinformer.WithInformer(olmConfigInformer),
269+
queueinformer.WithLogger(op.logger),
270+
queueinformer.WithQueue(olmConfigQueue),
271+
queueinformer.WithIndexer(olmConfigInformer.GetIndexer()),
272+
queueinformer.WithSyncer(queueinformer.LegacySyncHandler(op.syncOLMConfig).ToSyncer()),
273+
)
274+
if err != nil {
275+
return nil, err
276+
}
277+
if err := op.RegisterQueueInformer(olmConfigQueueInformer); err != nil {
278+
return nil, err
279+
}
280+
260281
// Wire OperatorGroup reconciliation
261282
extInformerFactory := externalversions.NewSharedInformerFactoryWithOptions(op.client, config.resyncPeriod(), externalversions.WithNamespace(namespace))
262283
operatorGroupInformer := extInformerFactory.Operators().V1().OperatorGroups()
@@ -1217,6 +1238,70 @@ func (a *Operator) syncClusterServiceVersion(obj interface{}) (syncError error)
12171238
return
12181239
}
12191240

1241+
func isNamespaceClusterScopedMap(operatorGroups ...*v1.OperatorGroup) map[string]bool {
1242+
result := map[string]bool{}
1243+
for _, operatorGroup := range operatorGroups {
1244+
result[operatorGroup.GetNamespace()] = NewNamespaceSet(operatorGroup.Status.Namespaces).IsAllNamespaces()
1245+
}
1246+
return result
1247+
}
1248+
1249+
func (a *Operator) syncOLMConfig(obj interface{}) (syncError error) {
1250+
olmConfig, ok := obj.(*v1.OLMConfig)
1251+
if !ok {
1252+
return fmt.Errorf("casting OLMConfig failed")
1253+
}
1254+
1255+
// Generate a map to track namespaces that are cluster scoped
1256+
operatorGroups, err := a.lister.OperatorsV1().OperatorGroupLister().List(labels.Everything())
1257+
if err != nil {
1258+
return err
1259+
}
1260+
1261+
isNamespaceClusterScoped := isNamespaceClusterScopedMap(operatorGroups...)
1262+
1263+
// Get non-copied CSVs
1264+
requirement, err := labels.NewRequirement(v1alpha1.CopiedLabelKey, selection.DoesNotExist, []string{})
1265+
if err != nil {
1266+
return err
1267+
}
1268+
1269+
csvs, err := a.lister.OperatorsV1alpha1().ClusterServiceVersionLister().List(labels.NewSelector().Add(*requirement))
1270+
if err != nil {
1271+
return err
1272+
}
1273+
1274+
for _, csv := range csvs {
1275+
// For each cluster scope installation
1276+
if !isNamespaceClusterScoped[csv.GetNamespace()] {
1277+
continue
1278+
}
1279+
1280+
// Get a count of the number of CSVS
1281+
requirement, err := labels.NewRequirement(v1alpha1.CopiedLabelKey, selection.Equals, []string{csv.GetNamespace()})
1282+
if err != nil {
1283+
return err
1284+
}
1285+
1286+
copiedCSVs, err := a.copiedCSVLister.List(labels.NewSelector().Add(*requirement))
1287+
if err != nil {
1288+
return err
1289+
}
1290+
1291+
// If the correct number of copied CSVs were found, continue
1292+
if len(copiedCSVs) == 0 == olmConfig.Spec.Features.DisableCopiedCSVs {
1293+
continue
1294+
}
1295+
1296+
// There were an incorrect number of copied CSVs, requeue the original CSV.
1297+
if err := a.csvQueueSet.Requeue(csv.GetNamespace(), csv.GetName()); err != nil {
1298+
return err
1299+
}
1300+
}
1301+
1302+
return nil
1303+
}
1304+
12201305
func (a *Operator) syncCopyCSV(obj interface{}) (syncError error) {
12211306
clusterServiceVersion, ok := obj.(*v1alpha1.ClusterServiceVersion)
12221307
if !ok {

0 commit comments

Comments
 (0)