Skip to content

Commit 81db438

Browse files
authored
Merge pull request #7 from perdasilva/catsrc_entitysrc_cont
Catsrc entitysrc cont
2 parents ef4febc + 3fb698e commit 81db438

File tree

10 files changed

+292
-129
lines changed

10 files changed

+292
-129
lines changed

controllers/catalogsource_controller.go

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,14 @@ import (
1010
"github.com/operator-framework/api/pkg/operators/v1alpha1"
1111
"github.com/operator-framework/deppy/pkg/deppy"
1212
"github.com/operator-framework/deppy/pkg/deppy/input"
13-
"github.com/operator-framework/operator-controller/internal/resolution/entity_sources/catalogsource"
1413
"k8s.io/apimachinery/pkg/api/errors"
1514
"k8s.io/apimachinery/pkg/runtime"
1615
"k8s.io/client-go/tools/record"
1716
ctrl "sigs.k8s.io/controller-runtime"
1817
"sigs.k8s.io/controller-runtime/pkg/client"
1918
"sigs.k8s.io/controller-runtime/pkg/log"
19+
20+
"github.com/operator-framework/operator-controller/internal/resolution/entity_sources/catalogsource"
2021
)
2122

2223
const (
@@ -38,31 +39,42 @@ func WithRegistryClient(registry catalogsource.RegistryClient) CatalogSourceReco
3839
}
3940
}
4041

42+
func WithUnmanagedCatalogSourceSyncInterval(interval time.Duration) CatalogSourceReconcilerOption {
43+
return func(reconciler *CatalogSourceReconciler) {
44+
reconciler.unmanagedCatalogSourceSyncInterval = interval
45+
}
46+
}
47+
4148
// applyDefaults applies default values to empty CatalogSourceReconciler fields _after_ options have been applied
4249
func applyDefaults() CatalogSourceReconcilerOption {
4350
return func(reconciler *CatalogSourceReconciler) {
4451
if reconciler.registry == nil {
4552
reconciler.registry = catalogsource.NewRegistryGRPCClient(defaultRegistryGRPCConnectionTimeout)
4653
}
54+
if reconciler.unmanagedCatalogSourceSyncInterval == 0 {
55+
reconciler.unmanagedCatalogSourceSyncInterval = defaultCatalogSourceSyncInterval
56+
}
4757
}
4858
}
4959

5060
type CatalogSourceReconciler struct {
5161
sync.RWMutex
5262
client.Client
53-
scheme *runtime.Scheme
54-
registry catalogsource.RegistryClient
55-
recorder record.EventRecorder
56-
cache map[string]map[deppy.Identifier]*input.Entity
63+
scheme *runtime.Scheme
64+
registry catalogsource.RegistryClient
65+
recorder record.EventRecorder
66+
unmanagedCatalogSourceSyncInterval time.Duration
67+
cache map[string]map[deppy.Identifier]*input.Entity
5768
}
5869

5970
func NewCatalogSourceReconciler(client client.Client, scheme *runtime.Scheme, recorder record.EventRecorder, options ...CatalogSourceReconcilerOption) *CatalogSourceReconciler {
6071
reconciler := &CatalogSourceReconciler{
61-
RWMutex: sync.RWMutex{},
62-
Client: client,
63-
scheme: scheme,
64-
recorder: recorder,
65-
cache: map[string]map[deppy.Identifier]*input.Entity{},
72+
RWMutex: sync.RWMutex{},
73+
Client: client,
74+
scheme: scheme,
75+
recorder: recorder,
76+
unmanagedCatalogSourceSyncInterval: 0,
77+
cache: map[string]map[deppy.Identifier]*input.Entity{},
6678
}
6779
// apply options
6880
options = append(options, applyDefaults())
@@ -100,7 +112,7 @@ func (r *CatalogSourceReconciler) Reconcile(ctx context.Context, req ctrl.Reques
100112
if isManagedCatalogSource(*catalogSource) {
101113
return ctrl.Result{}, nil
102114
}
103-
return ctrl.Result{RequeueAfter: defaultCatalogSourceSyncInterval}, nil
115+
return ctrl.Result{RequeueAfter: r.unmanagedCatalogSourceSyncInterval}, nil
104116
}
105117

106118
// SetupWithManager sets up the controller with the Manager.

0 commit comments

Comments
 (0)