@@ -15,6 +15,7 @@ import (
15
15
rbacv1 "k8s.io/api/rbac/v1"
16
16
extinf "k8s.io/apiextensions-apiserver/pkg/client/informers/externalversions"
17
17
k8serrors "k8s.io/apimachinery/pkg/api/errors"
18
+ "k8s.io/apimachinery/pkg/api/meta"
18
19
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
19
20
"k8s.io/apimachinery/pkg/labels"
20
21
"k8s.io/apimachinery/pkg/runtime"
@@ -74,6 +75,7 @@ type Operator struct {
74
75
copiedCSVLister operatorsv1alpha1listers.ClusterServiceVersionLister
75
76
ogQueueSet * queueinformer.ResourceQueueSet
76
77
csvQueueSet * queueinformer.ResourceQueueSet
78
+ olmConfigQueue workqueue.RateLimitingInterface
77
79
csvCopyQueueSet * queueinformer.ResourceQueueSet
78
80
copiedCSVGCQueueSet * queueinformer.ResourceQueueSet
79
81
objGCQueueSet * queueinformer.ResourceQueueSet
@@ -130,6 +132,7 @@ func newOperatorWithConfig(ctx context.Context, config *operatorConfig) (*Operat
130
132
client : config .externalClient ,
131
133
ogQueueSet : queueinformer .NewEmptyResourceQueueSet (),
132
134
csvQueueSet : queueinformer .NewEmptyResourceQueueSet (),
135
+ olmConfigQueue : workqueue .NewNamedRateLimitingQueue (workqueue .DefaultControllerRateLimiter (), "olmConfig" ),
133
136
csvCopyQueueSet : queueinformer .NewEmptyResourceQueueSet (),
134
137
copiedCSVGCQueueSet : queueinformer .NewEmptyResourceQueueSet (),
135
138
objGCQueueSet : queueinformer .NewEmptyResourceQueueSet (),
@@ -262,12 +265,11 @@ func newOperatorWithConfig(ctx context.Context, config *operatorConfig) (*Operat
262
265
op .client ,
263
266
config .resyncPeriod (),
264
267
).Operators ().V1 ().OLMConfigs ().Informer ()
265
- olmConfigQueue := workqueue .NewNamedRateLimitingQueue (workqueue .DefaultControllerRateLimiter (), fmt .Sprintf ("%s/olm-config" , namespace ))
266
268
olmConfigQueueInformer , err := queueinformer .NewQueueInformer (
267
269
ctx ,
268
270
queueinformer .WithInformer (olmConfigInformer ),
269
271
queueinformer .WithLogger (op .logger ),
270
- queueinformer .WithQueue (olmConfigQueue ),
272
+ queueinformer .WithQueue (op . olmConfigQueue ),
271
273
queueinformer .WithIndexer (olmConfigInformer .GetIndexer ()),
272
274
queueinformer .WithSyncer (queueinformer .LegacySyncHandler (op .syncOLMConfig ).ToSyncer ()),
273
275
)
@@ -1247,6 +1249,7 @@ func isNamespaceClusterScopedMap(operatorGroups ...*v1.OperatorGroup) map[string
1247
1249
}
1248
1250
1249
1251
func (a * Operator ) syncOLMConfig (obj interface {}) (syncError error ) {
1252
+ a .logger .Info ("Processing olmConfig" )
1250
1253
olmConfig , ok := obj .(* v1.OLMConfig )
1251
1254
if ! ok {
1252
1255
return fmt .Errorf ("casting OLMConfig failed" )
@@ -1271,6 +1274,7 @@ func (a *Operator) syncOLMConfig(obj interface{}) (syncError error) {
1271
1274
return err
1272
1275
}
1273
1276
1277
+ csvIsRequeued := false
1274
1278
for _ , csv := range csvs {
1275
1279
// For each cluster scope installation
1276
1280
if ! isNamespaceClusterScoped [csv .GetNamespace ()] {
@@ -1297,6 +1301,33 @@ func (a *Operator) syncOLMConfig(obj interface{}) (syncError error) {
1297
1301
if err := a .csvQueueSet .Requeue (csv .GetNamespace (), csv .GetName ()); err != nil {
1298
1302
return err
1299
1303
}
1304
+ csvIsRequeued = true
1305
+ }
1306
+ condition := metav1.Condition {
1307
+ Reason : "CopiedCSVCountCorrect" ,
1308
+ Status : metav1 .ConditionTrue ,
1309
+ Message : "Correct Number of copiedCSVs created" ,
1310
+ ObservedGeneration : olmConfig .GetGeneration (),
1311
+ Type : "ready" ,
1312
+ LastTransitionTime : metav1 .Now (),
1313
+ }
1314
+
1315
+ // If a CSV was requeued, reflect that the cluster is not yet in the expect state.
1316
+ if csvIsRequeued {
1317
+ condition .Message = "At least one CSV had an unexpected number of copied CSVs"
1318
+ condition .Status = metav1 .ConditionFalse
1319
+ defer func () {
1320
+ a .olmConfigQueue .AddAfter (olmConfig , time .Second * 5 )
1321
+ }()
1322
+ }
1323
+
1324
+ // Update the olmConfig status if it has changed.
1325
+ if ! meta .IsStatusConditionPresentAndEqual (olmConfig .Status .Conditions , condition .Type , condition .Status ) {
1326
+ a .logger .Infof ("Updating Condition: %v" , condition )
1327
+ meta .SetStatusCondition (& olmConfig .Status .Conditions , condition )
1328
+ if _ , err := a .client .OperatorsV1 ().OLMConfigs ().UpdateStatus (context .TODO (), olmConfig , metav1.UpdateOptions {}); err != nil {
1329
+ return err
1330
+ }
1300
1331
}
1301
1332
1302
1333
return nil
0 commit comments