@@ -29,7 +29,7 @@ import (
29
29
"github.com/operator-framework/operator-lifecycle-manager/pkg/api/client/clientset/versioned"
30
30
"github.com/operator-framework/operator-lifecycle-manager/pkg/api/client/informers/externalversions"
31
31
olmerrors "github.com/operator-framework/operator-lifecycle-manager/pkg/controller/errors"
32
- "github.com/operator-framework/operator-lifecycle-manager/pkg/controller/registry"
32
+ "github.com/operator-framework/operator-lifecycle-manager/pkg/controller/registry/reconciler "
33
33
"github.com/operator-framework/operator-lifecycle-manager/pkg/controller/registry/resolver"
34
34
"github.com/operator-framework/operator-lifecycle-manager/pkg/lib/operatorlister"
35
35
"github.com/operator-framework/operator-lifecycle-manager/pkg/lib/ownerutil"
@@ -54,16 +54,16 @@ var timeNow = func() metav1.Time { return metav1.NewTime(time.Now().UTC()) }
54
54
// resolving dependencies in a catalog.
55
55
type Operator struct {
56
56
* queueinformer.Operator
57
- client versioned.Interface
58
- lister operatorlister.OperatorLister
59
- namespace string
60
- sources map [resolver.CatalogKey ]resolver.SourceRef
61
- sourcesLock sync.RWMutex
62
- sourcesLastUpdate metav1.Time
63
- resolver resolver.Resolver
64
- subQueue workqueue.RateLimitingInterface
65
- catSrcQueueSet queueinformer.ResourceQueueSet
66
- configmapRegistryReconciler registry. RegistryReconciler
57
+ client versioned.Interface
58
+ lister operatorlister.OperatorLister
59
+ namespace string
60
+ sources map [resolver.CatalogKey ]resolver.SourceRef
61
+ sourcesLock sync.RWMutex
62
+ sourcesLastUpdate metav1.Time
63
+ resolver resolver.Resolver
64
+ subQueue workqueue.RateLimitingInterface
65
+ catSrcQueueSet queueinformer.ResourceQueueSet
66
+ reconciler reconciler. ReconcilerFactory
67
67
}
68
68
69
69
// NewOperator creates a new Catalog Operator.
@@ -202,10 +202,10 @@ func NewOperator(kubeconfigPath string, logger *logrus.Logger, wakeupInterval ti
202
202
op .lister .CoreV1 ().RegisterPodLister (namespace , podInformer .Lister ())
203
203
op .lister .CoreV1 ().RegisterConfigMapLister (namespace , configMapInformer .Lister ())
204
204
}
205
- op .configmapRegistryReconciler = & registry. ConfigMapRegistryReconciler {
206
- Image : configmapRegistryImage ,
207
- OpClient : op .OpClient ,
208
- Lister : op .lister ,
205
+ op .reconciler = & reconciler. RegistryReconcilerFactory {
206
+ ConfigMapServerImage : configmapRegistryImage ,
207
+ OpClient : op .OpClient ,
208
+ Lister : op .lister ,
209
209
}
210
210
return op , nil
211
211
}
@@ -315,53 +315,45 @@ func (o *Operator) syncCatalogSources(obj interface{}) (syncError error) {
315
315
"source" : catsrc .GetName (),
316
316
})
317
317
318
- if catsrc .Spec .SourceType == v1alpha1 .SourceTypeInternal || catsrc .Spec .SourceType == v1alpha1 .SourceTypeConfigmap {
319
- return o .syncConfigMapSource (logger , catsrc )
320
- }
321
-
322
- logger .WithField ("sourceType" , catsrc .Spec .SourceType ).Warn ("unknown source type" )
323
-
324
- // TODO: write status about invalid source type
325
-
326
- return nil
327
- }
328
-
329
- func (o * Operator ) syncConfigMapSource (logger * logrus.Entry , catsrc * v1alpha1.CatalogSource ) (syncError error ) {
330
- // Get the catalog source's config map
331
- configMap , err := o .lister .CoreV1 ().ConfigMapLister ().ConfigMaps (catsrc .GetNamespace ()).Get (catsrc .Spec .ConfigMap )
332
- if err != nil {
333
- return fmt .Errorf ("failed to get catalog config map %s: %s" , catsrc .Spec .ConfigMap , err )
334
- }
335
-
336
318
out := catsrc .DeepCopy ()
337
319
sourceKey := resolver.CatalogKey {Name : catsrc .GetName (), Namespace : catsrc .GetNamespace ()}
338
320
339
- if catsrc .Status .ConfigMapResource == nil || catsrc .Status .ConfigMapResource .UID != configMap .GetUID () || catsrc .Status .ConfigMapResource .ResourceVersion != configMap .GetResourceVersion () {
340
- // configmap ref nonexistent or updated, write out the new configmap ref to status and exit
341
- out .Status .ConfigMapResource = & v1alpha1.ConfigMapResourceReference {
342
- Name : configMap .GetName (),
343
- Namespace : configMap .GetNamespace (),
344
- UID : configMap .GetUID (),
345
- ResourceVersion : configMap .GetResourceVersion (),
321
+ if catsrc .Spec .SourceType == v1alpha1 .SourceTypeInternal || catsrc .Spec .SourceType == v1alpha1 .SourceTypeConfigmap {
322
+ // Get the catalog source's config map
323
+ configMap , err := o .lister .CoreV1 ().ConfigMapLister ().ConfigMaps (catsrc .GetNamespace ()).Get (catsrc .Spec .ConfigMap )
324
+ if err != nil {
325
+ return fmt .Errorf ("failed to get catalog config map %s: %s" , catsrc .Spec .ConfigMap , err )
346
326
}
347
- out .Status .LastSync = timeNow ()
348
327
349
- // update status
350
- if _ , err = o .client .OperatorsV1alpha1 ().CatalogSources (out .GetNamespace ()).UpdateStatus (out ); err != nil {
351
- return err
352
- }
328
+ if catsrc .Status .ConfigMapResource == nil || catsrc .Status .ConfigMapResource .UID != configMap .GetUID () || catsrc .Status .ConfigMapResource .ResourceVersion != configMap .GetResourceVersion () {
329
+ // configmap ref nonexistent or updated, write out the new configmap ref to status and exit
330
+ out .Status .ConfigMapResource = & v1alpha1.ConfigMapResourceReference {
331
+ Name : configMap .GetName (),
332
+ Namespace : configMap .GetNamespace (),
333
+ UID : configMap .GetUID (),
334
+ ResourceVersion : configMap .GetResourceVersion (),
335
+ }
336
+ out .Status .LastSync = timeNow ()
353
337
354
- o .sourcesLastUpdate = timeNow ()
338
+ // update status
339
+ if _ , err = o .client .OperatorsV1alpha1 ().CatalogSources (out .GetNamespace ()).UpdateStatus (out ); err != nil {
340
+ return err
341
+ }
355
342
356
- return nil
343
+ o .sourcesLastUpdate = timeNow ()
344
+
345
+ return nil
346
+ }
357
347
}
358
348
359
- // configmap ref is up to date, continue parsing
360
- if catsrc .Status .RegistryServiceStatus == nil || catsrc .Status .RegistryServiceStatus .CreatedAt .Before (& catsrc .Status .LastSync ) {
361
- // if registry pod hasn't been created or hasn't been updated since the last configmap update, recreate it
349
+ reconciler := o .reconciler .ReconcilerForSourceType (catsrc .Spec .SourceType )
350
+ if reconciler == nil {
351
+ return fmt .Errorf ("no reconciler for source type %s" , catsrc .Spec .SourceType )
352
+ }
362
353
363
- out := catsrc .DeepCopy ()
364
- if err := o .configmapRegistryReconciler .EnsureRegistryServer (out ); err != nil {
354
+ // if registry pod hasn't been created or hasn't been updated since the last configmap update, recreate it
355
+ if catsrc .Status .RegistryServiceStatus == nil || catsrc .Status .RegistryServiceStatus .CreatedAt .Before (& catsrc .Status .LastSync ) {
356
+ if err := reconciler .EnsureRegistryServer (out ); err != nil {
365
357
logger .WithError (err ).Warn ("couldn't ensure registry server" )
366
358
return err
367
359
}
@@ -371,7 +363,7 @@ func (o *Operator) syncConfigMapSource(logger *logrus.Entry, catsrc *v1alpha1.Ca
371
363
}
372
364
373
365
// update status
374
- if _ , err = o .client .OperatorsV1alpha1 ().CatalogSources (out .GetNamespace ()).UpdateStatus (out ); err != nil {
366
+ if _ , err : = o .client .OperatorsV1alpha1 ().CatalogSources (out .GetNamespace ()).UpdateStatus (out ); err != nil {
375
367
return err
376
368
}
377
369
@@ -380,6 +372,7 @@ func (o *Operator) syncConfigMapSource(logger *logrus.Entry, catsrc *v1alpha1.Ca
380
372
return nil
381
373
}
382
374
375
+ // update operator's view of sources
383
376
sourcesUpdated := false
384
377
func () {
385
378
o .sourcesLock .Lock ()
@@ -401,13 +394,14 @@ func (o *Operator) syncConfigMapSource(logger *logrus.Entry, catsrc *v1alpha1.Ca
401
394
}
402
395
}()
403
396
404
- if sourcesUpdated {
405
- // record that we've done work here onto the status
406
- out := catsrc .DeepCopy ()
407
- out .Status .LastSync = timeNow ()
408
- if _ , err = o .client .OperatorsV1alpha1 ().CatalogSources (out .GetNamespace ()).UpdateStatus (out ); err != nil {
409
- return err
410
- }
397
+ if ! sourcesUpdated {
398
+ return nil
399
+ }
400
+
401
+ // record that we've done work here onto the status
402
+ out .Status .LastSync = timeNow ()
403
+ if _ , err := o .client .OperatorsV1alpha1 ().CatalogSources (out .GetNamespace ()).UpdateStatus (out ); err != nil {
404
+ return err
411
405
}
412
406
413
407
// Sync any dependent Subscriptions
0 commit comments