Skip to content

Commit 56aa8bc

Browse files
committed
Manage status
1 parent fdbec82 commit 56aa8bc

File tree

1 file changed

+33
-2
lines changed

1 file changed

+33
-2
lines changed

pkg/controller/operators/olm/operator.go

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
rbacv1 "k8s.io/api/rbac/v1"
1616
extinf "k8s.io/apiextensions-apiserver/pkg/client/informers/externalversions"
1717
k8serrors "k8s.io/apimachinery/pkg/api/errors"
18+
"k8s.io/apimachinery/pkg/api/meta"
1819
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1920
"k8s.io/apimachinery/pkg/labels"
2021
"k8s.io/apimachinery/pkg/runtime"
@@ -74,6 +75,7 @@ type Operator struct {
7475
copiedCSVLister operatorsv1alpha1listers.ClusterServiceVersionLister
7576
ogQueueSet *queueinformer.ResourceQueueSet
7677
csvQueueSet *queueinformer.ResourceQueueSet
78+
olmConfigQueue workqueue.RateLimitingInterface
7779
csvCopyQueueSet *queueinformer.ResourceQueueSet
7880
copiedCSVGCQueueSet *queueinformer.ResourceQueueSet
7981
objGCQueueSet *queueinformer.ResourceQueueSet
@@ -130,6 +132,7 @@ func newOperatorWithConfig(ctx context.Context, config *operatorConfig) (*Operat
130132
client: config.externalClient,
131133
ogQueueSet: queueinformer.NewEmptyResourceQueueSet(),
132134
csvQueueSet: queueinformer.NewEmptyResourceQueueSet(),
135+
olmConfigQueue: workqueue.NewNamedRateLimitingQueue(workqueue.DefaultControllerRateLimiter(), "olmConfig"),
133136
csvCopyQueueSet: queueinformer.NewEmptyResourceQueueSet(),
134137
copiedCSVGCQueueSet: queueinformer.NewEmptyResourceQueueSet(),
135138
objGCQueueSet: queueinformer.NewEmptyResourceQueueSet(),
@@ -262,12 +265,11 @@ func newOperatorWithConfig(ctx context.Context, config *operatorConfig) (*Operat
262265
op.client,
263266
config.resyncPeriod(),
264267
).Operators().V1().OLMConfigs().Informer()
265-
olmConfigQueue := workqueue.NewNamedRateLimitingQueue(workqueue.DefaultControllerRateLimiter(), fmt.Sprintf("%s/olm-config", namespace))
266268
olmConfigQueueInformer, err := queueinformer.NewQueueInformer(
267269
ctx,
268270
queueinformer.WithInformer(olmConfigInformer),
269271
queueinformer.WithLogger(op.logger),
270-
queueinformer.WithQueue(olmConfigQueue),
272+
queueinformer.WithQueue(op.olmConfigQueue),
271273
queueinformer.WithIndexer(olmConfigInformer.GetIndexer()),
272274
queueinformer.WithSyncer(queueinformer.LegacySyncHandler(op.syncOLMConfig).ToSyncer()),
273275
)
@@ -1247,6 +1249,7 @@ func isNamespaceClusterScopedMap(operatorGroups ...*v1.OperatorGroup) map[string
12471249
}
12481250

12491251
func (a *Operator) syncOLMConfig(obj interface{}) (syncError error) {
1252+
a.logger.Info("Processing olmConfig")
12501253
olmConfig, ok := obj.(*v1.OLMConfig)
12511254
if !ok {
12521255
return fmt.Errorf("casting OLMConfig failed")
@@ -1271,6 +1274,7 @@ func (a *Operator) syncOLMConfig(obj interface{}) (syncError error) {
12711274
return err
12721275
}
12731276

1277+
csvIsRequeued := false
12741278
for _, csv := range csvs {
12751279
// For each cluster scope installation
12761280
if !isNamespaceClusterScoped[csv.GetNamespace()] {
@@ -1297,6 +1301,33 @@ func (a *Operator) syncOLMConfig(obj interface{}) (syncError error) {
12971301
if err := a.csvQueueSet.Requeue(csv.GetNamespace(), csv.GetName()); err != nil {
12981302
return err
12991303
}
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+
}
13001331
}
13011332

13021333
return nil

0 commit comments

Comments
 (0)