Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
Signed-off-by: Rory Z <[email protected]>
  • Loading branch information
Rory-Z committed Dec 23, 2024
1 parent afe9128 commit 9ede1d3
Showing 1 changed file with 12 additions and 17 deletions.
29 changes: 12 additions & 17 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ import (
"sigs.k8s.io/controller-runtime/pkg/healthz"
"sigs.k8s.io/controller-runtime/pkg/log/zap"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

appsv1beta3 "github.com/emqx/emqx-operator/apis/apps/v1beta3"
appsv1beta4 "github.com/emqx/emqx-operator/apis/apps/v1beta4"
appsv2alpha1 "github.com/emqx/emqx-operator/apis/apps/v2alpha1"
Expand Down Expand Up @@ -103,7 +105,9 @@ func main() {
LeaderElectionID: "19fd6fcc.emqx.io",
LeaseDuration: ptr.To(time.Second * 30),
RenewDeadline: ptr.To(time.Second * 20),
Cache: getCacheOptions(),
Cache: cache.Options{
DefaultNamespaces: getWatchNamespace(),
},
})
if err != nil {
setupLog.Error(err, "unable to start manager")
Expand Down Expand Up @@ -176,26 +180,17 @@ func main() {
}
}

func getCacheOptions() cache.Options {
// getWatchNamespace returns the Namespace the operator should be watching for changes
func getWatchNamespace() map[string]cache.Config {
var watchNamespaceEnvVar = "WATCH_NAMESPACE"

ns, found := os.LookupEnv(watchNamespaceEnvVar)
if !found {
return cache.Options{}
return map[string]cache.Config{
metav1.NamespaceAll: {},
}
}

return cache.Options{
DefaultNamespaces: map[string]cache.Config{ns: {}},
return map[string]cache.Config{
ns: {},
}
}

// getWatchNamespace returns the Namespace the operator should be watching for changes
// func getWatchNamespace() string {
// var watchNamespaceEnvVar = "WATCH_NAMESPACE"

// ns, found := os.LookupEnv(watchNamespaceEnvVar)
// if !found {
// return metav1.NamespaceAll
// }
// return ns
// }

0 comments on commit 9ede1d3

Please sign in to comment.