Skip to content

Commit

Permalink
feat: WATCH_NAMESPACE support multi namespace
Browse files Browse the repository at this point in the history
Signed-off-by: drivebyer <wuyangmuc@gmail.com>
  • Loading branch information
drivebyer committed May 7, 2024
1 parent c0b3c04 commit 59b5175
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ package main
import (
"flag"
"os"

Check failure on line 21 in main.go

View workflow job for this annotation

GitHub Actions / lint

File is not `gofumpt`-ed (gofumpt)
"sigs.k8s.io/controller-runtime/pkg/cache"

Check failure on line 22 in main.go

View workflow job for this annotation

GitHub Actions / lint

File is not `gci`-ed with --skip-generated -s standard -s default (gci)
"strings"

Check failure on line 23 in main.go

View workflow job for this annotation

GitHub Actions / lint

File is not `gofumpt`-ed (gofumpt)

redisv1beta1 "github.com/OT-CONTAINER-KIT/redis-operator/api/v1beta1"
redisv1beta2 "github.com/OT-CONTAINER-KIT/redis-operator/api/v1beta2"
Expand All @@ -29,7 +31,6 @@ import (
clientgoscheme "k8s.io/client-go/kubernetes/scheme"
_ "k8s.io/client-go/plugin/pkg/client/auth"
ctrl "sigs.k8s.io/controller-runtime"

Check failure on line 33 in main.go

View workflow job for this annotation

GitHub Actions / lint

File is not `gci`-ed with --skip-generated -s standard -s default (gci)
"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 Down Expand Up @@ -86,8 +87,13 @@ func main() {
LeaderElectionID: "6cab913b.redis.opstreelabs.in",
}

if ns := os.Getenv("WATCH_NAMESPACE"); ns != "" {
options.Cache.DefaultNamespaces = map[string]cache.Config{ns: {}}
if namespaces := strings.TrimSpace(os.Getenv("WATCH_NAMESPACE")); namespaces != "" {
options.Cache.DefaultNamespaces = map[string]cache.Config{}
for _, ns := range strings.Split(namespaces, ",") {
if ns = strings.TrimSpace(ns); ns != "" {
options.Cache.DefaultNamespaces[ns] = cache.Config{}
}
}
}

mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), options)
Expand Down

0 comments on commit 59b5175

Please sign in to comment.