From b3a07f4b0fd0bfb0c8bb06af9b081b63cb956015 Mon Sep 17 00:00:00 2001 From: Enxebre Date: Wed, 15 May 2019 12:21:55 +0200 Subject: [PATCH 1/2] Add namespace flag for nodelink controller --- cmd/nodelink-controller/main.go | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) 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(), From e83e21ac8472e7a2d1c42373ae3adb3f4fac5357 Mon Sep 17 00:00:00 2001 From: Enxebre Date: Wed, 15 May 2019 12:21:32 +0200 Subject: [PATCH 2/2] Add namespace flag for machine healthcheck --- cmd/machine-healthcheck/main.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) 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) }