Skip to content

Commit

Permalink
Merge pull request #304 from sabre1041/multinamespace-support
Browse files Browse the repository at this point in the history
Support for accessing resources explicitly in multiple namespaces
  • Loading branch information
raffaelespazzoli committed Feb 29, 2024
2 parents 6a8e921 + 1652c15 commit 5956ecb
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions main.go
Expand Up @@ -18,11 +18,14 @@ package main

import (
"flag"
v1 "k8s.io/api/core/v1"
"os"
"sigs.k8s.io/controller-runtime/pkg/client"
"strings"
"time"

v1 "k8s.io/api/core/v1"
"sigs.k8s.io/controller-runtime/pkg/cache"
"sigs.k8s.io/controller-runtime/pkg/client"

userv1 "github.com/openshift/api/user/v1"
"github.com/redhat-cop/operator-utils/pkg/util"
"k8s.io/apimachinery/pkg/runtime"
Expand Down Expand Up @@ -86,7 +89,7 @@ func main() {

watchNamespace := getWatchNamespace()

mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{
options := ctrl.Options{
Scheme: scheme,
ClientDisableCacheFor: []client.Object{&v1.Secret{}},
MetricsBindAddress: metricsAddr,
Expand All @@ -99,7 +102,15 @@ func main() {
RenewDeadline: &renewDeadline,
RetryPeriod: &retryPeriod,
Namespace: watchNamespace,
})
}

if strings.Contains(watchNamespace, ",") {
setupLog.Info("manager set up with multiple namespaces", "namespaces", watchNamespace)
options.Namespace = ""
options.NewCache = cache.MultiNamespacedCacheBuilder(strings.Split(watchNamespace, ","))
}

mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), options)
if err != nil {
setupLog.Error(err, "unable to start manager")
os.Exit(1)
Expand Down

0 comments on commit 5956ecb

Please sign in to comment.