Skip to content

Commit

Permalink
Don't cache copied CSVs in the controller-runtime-based controllers.
Browse files Browse the repository at this point in the history
Only the main controller (i.e., the controller responsible for
reconciling ClusterServiceVersions) needs to watch copied
ClusterServiceVersions. The OperatorCondition and Operator controllers
-- which coincidentally maintain separate caches -- are not interested
in copied CSVs, so all copied CSVs can be excluded via from their
cache using a label selector.

Signed-off-by: Ben Luddy <bluddy@redhat.com>
  • Loading branch information
benluddy committed Jul 16, 2021
1 parent 014bd31 commit e641e76
Showing 1 changed file with 29 additions and 2 deletions.
31 changes: 29 additions & 2 deletions cmd/olm/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,58 @@ package main

import (
"context"
"k8s.io/apimachinery/pkg/labels"

corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/selection"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/cache"
"sigs.k8s.io/controller-runtime/pkg/log/zap"

operatorsv1alpha1 "github.com/operator-framework/api/pkg/operators/v1alpha1"
"github.com/operator-framework/operator-lifecycle-manager/pkg/controller/install"
"github.com/operator-framework/operator-lifecycle-manager/pkg/controller/operators"
"github.com/operator-framework/operator-lifecycle-manager/pkg/feature"
)

var (
copiedLabelDoesNotExist labels.Selector
)

func init() {
requirement, err := labels.NewRequirement(operatorsv1alpha1.CopiedLabelKey, selection.DoesNotExist, nil)
if err != nil {
panic(err)
}
copiedLabelDoesNotExist = labels.NewSelector().Add(*requirement)
}

func Manager(ctx context.Context, debug bool) (ctrl.Manager, error) {
ctrl.SetLogger(zap.New(zap.UseDevMode(debug)))
setupLog := ctrl.Log.WithName("setup").V(1)

// Setup a Manager
scheme := runtime.NewScheme()
if err := operators.AddToScheme(scheme); err != nil {
// ctrl.NewManager needs the Scheme to be populated
// up-front so that the NewCache implementation we
// provide can configure custom cache behavior on
// non-core types.
return nil, err
}

setupLog.Info("configuring manager")
mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{
Scheme: scheme,
MetricsBindAddress: "0", // TODO(njhale): Enable metrics on non-conflicting port (not 8080)
NewCache: cache.BuilderWithOptions(cache.Options{
SelectorsByObject: cache.SelectorsByObject{
&corev1.Secret{}: {
Label: labels.SelectorFromValidatedSet(map[string]string{install.OLMManagedLabelKey: install.OLMManagedLabelValue}),
},
&operatorsv1alpha1.ClusterServiceVersion{}: {
Label: copiedLabelDoesNotExist,
},
},
}),
})
Expand Down

0 comments on commit e641e76

Please sign in to comment.