diff --git a/cmd/machine-healthcheck/main.go b/cmd/machine-healthcheck/main.go index c4f1bfa5f1..d78c055bdf 100644 --- a/cmd/machine-healthcheck/main.go +++ b/cmd/machine-healthcheck/main.go @@ -4,6 +4,8 @@ import ( "flag" "runtime" + "k8s.io/klog" + "github.com/golang/glog" mapiv1 "github.com/openshift/cluster-api/pkg/apis/machine/v1beta1" "github.com/openshift/machine-api-operator/pkg/apis/healthchecking/v1alpha1" @@ -22,6 +24,7 @@ func printVersion() { } func main() { + watchNamespace := flag.String("namespace", "", "Namespace that the controller watches to reconcile machine-api objects. If unspecified, the controller watches for machine-api objects across all namespaces.") flag.Parse() printVersion() @@ -31,8 +34,13 @@ func main() { glog.Fatal(err) } + opts := manager.Options{} + if *watchNamespace != "" { + opts.Namespace = *watchNamespace + klog.Infof("Watching machine-api objects only in namespace %q for reconciliation.", opts.Namespace) + } // Create a new Cmd to provide shared dependencies and start components - mgr, err := manager.New(cfg, manager.Options{}) + mgr, err := manager.New(cfg, opts) if err != nil { glog.Fatal(err) } diff --git a/cmd/nodelink-controller/main.go b/cmd/nodelink-controller/main.go index 8802ed1d8b..c2b66e272c 100644 --- a/cmd/nodelink-controller/main.go +++ b/cmd/nodelink-controller/main.go @@ -434,6 +434,7 @@ var ( func main() { pflag.CommandLine.AddGoFlagSet(flag.CommandLine) + watchNamespace := pflag.String("namespace", "", "Namespace that the controller watches to reconcile machine-api objects. If unspecified, the controller watches for machine-api objects across all namespaces.") pflag.Parse() config, err := config.GetConfig() @@ -453,7 +454,19 @@ func main() { // TODO(jchaloup): set the resync period reasonably kubeSharedInformers := kubeinformers.NewSharedInformerFactory(kubeClient, 5*time.Second) - mapiInformers := mapiinformersfactory.NewSharedInformerFactory(client, 5*time.Second) + + var mapiInformers mapiinformersfactory.SharedInformerFactory + if *watchNamespace != "" { + glog.Infof("Watching machine-api objects only in namespace %q for reconciliation.", *watchNamespace) + mapiInformers = mapiinformersfactory.NewSharedInformerFactoryWithOptions( + client, + 5*time.Second, + mapiinformersfactory.WithNamespace(*watchNamespace)) + } else { + mapiInformers = mapiinformersfactory.NewSharedInformerFactory( + client, + 5*time.Second) + } ctrl := NewController( kubeSharedInformers.Core().V1().Nodes(),