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
5 changes: 5 additions & 0 deletions bundle/manifests/rhtpa-operator.clusterserviceversion.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,11 @@ spec:
initialDelaySeconds: 15
periodSeconds: 20
name: manager
env:
- name: WATCH_NAMESPACE
valueFrom:
fieldRef:
fieldPath: metadata.namespace
readinessProbe:
httpGet:
path: /readyz
Expand Down
5 changes: 5 additions & 0 deletions config/manager/manager.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ spec:
- --health-probe-bind-address=:8081
image: controller:latest
name: manager
env:
- name: WATCH_NAMESPACE
valueFrom:
fieldRef:
fieldPath: metadata.namespace
securityContext:
allowPrivilegeEscalation: false
capabilities:
Expand Down
15 changes: 15 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (
clientgoscheme "k8s.io/client-go/kubernetes/scheme"
_ "k8s.io/client-go/plugin/pkg/client/auth"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/cache"
"sigs.k8s.io/controller-runtime/pkg/healthz"
"sigs.k8s.io/controller-runtime/pkg/log/zap"
"sigs.k8s.io/controller-runtime/pkg/metrics/server"
Expand All @@ -41,6 +42,7 @@ var (
setupLog = ctrl.Log.WithName("setup")
defaultMaxConcurrentReconciles = runtime.NumCPU()
defaultReconcilePeriod = time.Minute
watchNamespace = os.Getenv("WATCH_NAMESPACE")
)

func init() {
Expand Down Expand Up @@ -74,6 +76,18 @@ func main() {

ctrl.SetLogger(zap.New(zap.UseFlagOptions(&opts)))

var cacheOpts cache.Options
if watchNamespace != "" {
setupLog.Info("Watching specific namespace", "namespace", watchNamespace)
cacheOpts = cache.Options{
DefaultNamespaces: map[string]cache.Config{
watchNamespace: {},
},
}
} else {
setupLog.Info("Watching all namespaces")
}

mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{
Scheme: scheme,
Metrics: server.Options{
Expand All @@ -82,6 +96,7 @@ func main() {
HealthProbeBindAddress: probeAddr,
LeaderElection: enableLeaderElection,
LeaderElectionID: leaderElectionID,
Cache: cacheOpts,
})
if err != nil {
setupLog.Error(err, "unable to start manager")
Expand Down