@@ -15,7 +15,7 @@ import (
15
15
rbacv1 "k8s.io/api/rbac/v1"
16
16
"k8s.io/apiextensions-apiserver/pkg/apis/apiextensions"
17
17
v1beta1ext "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1"
18
- validation "k8s.io/apiextensions-apiserver/pkg/apiserver/validation"
18
+ "k8s.io/apiextensions-apiserver/pkg/apiserver/validation"
19
19
extinf "k8s.io/apiextensions-apiserver/pkg/client/informers/externalversions"
20
20
k8serrors "k8s.io/apimachinery/pkg/api/errors"
21
21
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -30,6 +30,7 @@ import (
30
30
"k8s.io/client-go/util/workqueue"
31
31
32
32
"github.com/operator-framework/operator-lifecycle-manager/pkg/controller/registry/grpc"
33
+ sharedtime "github.com/operator-framework/operator-lifecycle-manager/pkg/lib/time"
33
34
34
35
"github.com/operator-framework/operator-lifecycle-manager/pkg/api/apis/operators/reference"
35
36
"github.com/operator-framework/operator-lifecycle-manager/pkg/api/apis/operators/v1alpha1"
@@ -77,7 +78,7 @@ type Operator struct {
77
78
nsResolveQueue workqueue.RateLimitingInterface
78
79
namespace string
79
80
sources * grpc.SourceStore
80
- sourcesLastUpdate metav1. Time
81
+ sourcesLastUpdate sharedtime. SharedTime
81
82
resolver resolver.Resolver
82
83
reconciler reconciler.RegistryReconcilerFactory
83
84
csvProvidedAPIsIndexer map [string ]cache.Indexer
@@ -332,7 +333,7 @@ func (o *Operator) now() metav1.Time {
332
333
}
333
334
334
335
func (o * Operator ) syncSourceState (state grpc.SourceState ) {
335
- o .sourcesLastUpdate = o .now ()
336
+ o .sourcesLastUpdate . Set ( o .now (). Time )
336
337
337
338
o .logger .Infof ("state.Key.Namespace=%s state.Key.Name=%s state.State=%s" , state .Key .Namespace , state .Key .Name , state .State .String ())
338
339
@@ -467,7 +468,7 @@ func (o *Operator) syncConfigMap(logger *logrus.Entry, in *v1alpha1.CatalogSourc
467
468
out .SetError (v1alpha1 .CatalogSourceConfigMapError , syncError )
468
469
return
469
470
}
470
-
471
+
471
472
logger .Debug ("adopted configmap" )
472
473
}
473
474
@@ -541,8 +542,8 @@ func (o *Operator) syncConnection(logger *logrus.Entry, in *v1alpha1.CatalogSour
541
542
// update operator's view of sources
542
543
now := o .now ()
543
544
address := in .Address ()
544
-
545
- connectFunc := func () (source * grpc.SourceMeta , connErr error ){
545
+
546
+ connectFunc := func () (source * grpc.SourceMeta , connErr error ) {
546
547
newSource , err := o .sources .Add (sourceKey , address )
547
548
if err != nil {
548
549
connErr = fmt .Errorf ("couldn't connect to registry - %v" , err )
@@ -560,10 +561,10 @@ func (o *Operator) syncConnection(logger *logrus.Entry, in *v1alpha1.CatalogSour
560
561
561
562
updateConnectionStateFunc := func (out * v1alpha1.CatalogSource , source * grpc.SourceMeta ) {
562
563
out .Status .GRPCConnectionState = & v1alpha1.GRPCConnectionState {
563
- Address : source .Address ,
564
+ Address : source .Address ,
564
565
LastObservedState : source .ConnectionState .String (),
565
- LastConnectTime : source .LastConnect ,
566
- }
566
+ LastConnectTime : source .LastConnect ,
567
+ }
567
568
}
568
569
569
570
source := o .sources .GetMeta (sourceKey )
@@ -573,7 +574,7 @@ func (o *Operator) syncConnection(logger *logrus.Entry, in *v1alpha1.CatalogSour
573
574
out .SetError (v1alpha1 .CatalogSourceRegistryServerError , syncError )
574
575
return
575
576
}
576
-
577
+
577
578
// Set connection status and return.
578
579
updateConnectionStateFunc (out , source )
579
580
return
@@ -593,7 +594,7 @@ func (o *Operator) syncConnection(logger *logrus.Entry, in *v1alpha1.CatalogSour
593
594
}
594
595
595
596
// connection is already good, but we need to update the sync time
596
- if out .Status .GRPCConnectionState != nil && out .Status .GRPCConnectionState .LastConnectTime .Before ( & o . sourcesLastUpdate ) {
597
+ if out .Status .GRPCConnectionState != nil && o . sourcesLastUpdate . After ( out .Status .GRPCConnectionState .LastConnectTime .Time ) {
597
598
// Set connection status and return.
598
599
out .Status .GRPCConnectionState .LastConnectTime = now
599
600
out .Status .GRPCConnectionState .LastObservedState = source .ConnectionState .String ()
@@ -617,7 +618,7 @@ func (o *Operator) syncCatalogSources(obj interface{}) (syncError error) {
617
618
logger .Debug ("syncing catsrc" )
618
619
619
620
syncFunc := func (in * v1alpha1.CatalogSource , chain []CatalogSourceSyncFunc ) (out * v1alpha1.CatalogSource , syncErr error ) {
620
- out = in
621
+ out = in
621
622
for _ , syncFunc := range chain {
622
623
cont := false
623
624
out , cont , syncErr = syncFunc (logger , in )
@@ -628,13 +629,13 @@ func (o *Operator) syncCatalogSources(obj interface{}) (syncError error) {
628
629
if ! cont {
629
630
return
630
631
}
631
-
632
+
632
633
in = out
633
634
}
634
635
635
636
return
636
637
}
637
-
638
+
638
639
equalFunc := func (a , b * v1alpha1.CatalogSourceStatus ) bool {
639
640
return reflect .DeepEqual (a , b )
640
641
}
@@ -648,7 +649,7 @@ func (o *Operator) syncCatalogSources(obj interface{}) (syncError error) {
648
649
649
650
out := latest .DeepCopy ()
650
651
out .Status = catsrc .Status
651
-
652
+
652
653
if _ , err := o .client .OperatorsV1alpha1 ().CatalogSources (out .GetNamespace ()).UpdateStatus (out ); err != nil {
653
654
logger .Errorf ("error while setting catalogsource status condition - %v" , err )
654
655
return err
@@ -663,7 +664,6 @@ func (o *Operator) syncCatalogSources(obj interface{}) (syncError error) {
663
664
o .syncConnection ,
664
665
}
665
666
666
-
667
667
in := catsrc .DeepCopy ()
668
668
in .SetError ("" , nil )
669
669
@@ -797,7 +797,7 @@ func (o *Operator) syncSubscriptions(obj interface{}) error {
797
797
798
798
func (o * Operator ) nothingToUpdate (logger * logrus.Entry , sub * v1alpha1.Subscription ) bool {
799
799
// Only sync if catalog has been updated since last sync time
800
- if o .sourcesLastUpdate .Before (& sub .Status .LastUpdated ) && sub .Status .State != v1alpha1 .SubscriptionStateNone && sub .Status .State != v1alpha1 .SubscriptionStateUpgradeAvailable {
800
+ if o .sourcesLastUpdate .Before (sub .Status .LastUpdated . Time ) && sub .Status .State != v1alpha1 .SubscriptionStateNone && sub .Status .State != v1alpha1 .SubscriptionStateUpgradeAvailable {
801
801
logger .Debugf ("skipping update: no new updates to catalog since last sync at %s" , sub .Status .LastUpdated .String ())
802
802
return true
803
803
}
0 commit comments