Skip to content

Commit

Permalink
replace deprecated opts.Namespace/cache.MultiNamespacedCacheBuilder b…
Browse files Browse the repository at this point in the history
…y opts.Cache.Namespaces
  • Loading branch information
thbkrkr committed May 30, 2023
1 parent 2d31fe0 commit d1246f6
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions cmd/manager/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ import (
"k8s.io/client-go/rest"
"k8s.io/client-go/tools/leaderelection/resourcelock"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/cache"
"sigs.k8s.io/controller-runtime/pkg/client"
logf "sigs.k8s.io/controller-runtime/pkg/log"
"sigs.k8s.io/controller-runtime/pkg/manager"
Expand Down Expand Up @@ -560,16 +559,16 @@ func startOperator(ctx context.Context) error {
log.Info("Operator configured to manage all namespaces")
case len(managedNamespaces) == 1 && managedNamespaces[0] == operatorNamespace:
log.Info("Operator configured to manage a single namespace", "namespace", managedNamespaces[0], "operator_namespace", operatorNamespace)
// opts.Namespace implicitly allows watching cluster-scoped resources (e.g. storage classes)
opts.Namespace = managedNamespaces[0]

default:
log.Info("Operator configured to manage multiple namespaces", "namespaces", managedNamespaces, "operator_namespace", operatorNamespace)
// The managed cache should always include the operator namespace so that we can work with operator-internal resources.
managedNamespaces = append(managedNamespaces, operatorNamespace)

opts.NewCache = cache.MultiNamespacedCacheBuilder(managedNamespaces)
}

// implicitly allows watching cluster-scoped resources (e.g. storage classes)
opts.Cache.Namespaces = managedNamespaces

// only expose prometheus metrics if provided a non-zero port
metricsPort := viper.GetInt(operator.MetricsPortFlag)
if metricsPort != 0 {
Expand Down

0 comments on commit d1246f6

Please sign in to comment.