Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions internal/cmd/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,14 @@ import (
routescheme "github.com/openshift/client-go/route/clientset/versioned/scheme"
"github.com/spf13/cobra"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/fields"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/client-go/kubernetes"
clientcorev1 "k8s.io/client-go/kubernetes/typed/core/v1"
"k8s.io/client-go/tools/record"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/cache"
"sigs.k8s.io/controller-runtime/pkg/metrics/server"

"github.com/cert-manager/openshift-routes/internal/cmd/app/options"
Expand Down Expand Up @@ -85,6 +88,17 @@ func Command() *cobra.Command {
return fmt.Errorf("connected to the Kubernetes API, but the cert-manager v1 CRDs do not appear to be installed")
}

// Load in Cache Configs for limited namespaces
cacheConfig := map[string]cache.Config{}
if len(opts.LimitNamespaces) > 0 {
for _, ns := range opts.LimitNamespaces {
cacheConfig[ns] = cache.Config{
LabelSelector: labels.Everything(),
FieldSelector: fields.Everything(),
}
}
}

logger := opts.Logr.WithName("controller-manager")
eventBroadcaster := record.NewBroadcaster()
eventBroadcaster.StartLogging(func(format string, args ...interface{}) {
Expand All @@ -104,6 +118,7 @@ func Command() *cobra.Command {

mgr, err := ctrl.NewManager(opts.RestConfig, ctrl.Options{
Scheme: combinedScheme,
Cache: cache.Options{DefaultNamespaces: cacheConfig},
Logger: logger,
LeaderElection: opts.EnableLeaderElection,
LeaderElectionID: "cert-manager-openshift-routes",
Expand Down
7 changes: 7 additions & 0 deletions internal/cmd/app/options/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ type Options struct {

logLevel string
kubeConfigFlags *genericclioptions.ConfigFlags

// LimitNamespaces is the list of namespaces to which cert-manager-openshift will limit itself for reconciliation
LimitNamespaces []string
}

func New() *Options {
Expand Down Expand Up @@ -134,4 +137,8 @@ func (o *Options) addAppFlags(fs *pflag.FlagSet) {
fs.StringVar(&o.LeaderElectionNamespace,
"leader-election-namespace", "cert-manager",
"Namespace to create leader election resources in.")

fs.StringSliceVar(&o.LimitNamespaces,
"limit-namespaces", []string{""},
"List of comma ',' delimited namespaces within which openshift-routes will operator on resources")
}