diff --git a/bootstrap/kubeadm/main.go b/bootstrap/kubeadm/main.go index fca4f1870cce..3fd52bb94df3 100644 --- a/bootstrap/kubeadm/main.go +++ b/bootstrap/kubeadm/main.go @@ -71,7 +71,7 @@ var ( leaderElectionRenewDeadline time.Duration leaderElectionRetryPeriod time.Duration watchFilterValue string - watchNamespace string + watchNamespacesList []string profilerAddress string enableContentionProfiling bool syncPeriod time.Duration @@ -118,8 +118,8 @@ func InitFlags(fs *pflag.FlagSet) { fs.DurationVar(&leaderElectionRetryPeriod, "leader-elect-retry-period", 2*time.Second, "Duration the LeaderElector clients should wait between tries of actions (duration string)") - fs.StringVar(&watchNamespace, "namespace", "", - "Namespace that the controller watches to reconcile cluster-api objects. If unspecified, the controller watches for cluster-api objects across all namespaces.") + fs.StringSliceVar(&watchNamespacesList, "namespace", nil, + "Comma-separated list of namespaces that the controller watches to reconcile cluster-api objects. If unspecified, the controller watches for cluster-api objects across all namespaces.") fs.StringVar(&watchFilterValue, "watch-filter", "", fmt.Sprintf("Label value that the controller watches to reconcile cluster-api objects. Label key is always %s. If unspecified, the controller watches for all cluster-api objects.", clusterv1.WatchLabel)) @@ -214,9 +214,10 @@ func main() { } var watchNamespaces map[string]cache.Config - if watchNamespace != "" { - watchNamespaces = map[string]cache.Config{ - watchNamespace: {}, + if watchNamespacesList != nil { + watchNamespaces = map[string]cache.Config{} + for _, watchNamespace := range watchNamespacesList { + watchNamespaces[watchNamespace] = cache.Config{} } } diff --git a/controlplane/kubeadm/main.go b/controlplane/kubeadm/main.go index 3d624099fd82..d1cb39618521 100644 --- a/controlplane/kubeadm/main.go +++ b/controlplane/kubeadm/main.go @@ -77,7 +77,7 @@ var ( leaderElectionRenewDeadline time.Duration leaderElectionRetryPeriod time.Duration watchFilterValue string - watchNamespace string + watchNamespacesList []string profilerAddress string enableContentionProfiling bool syncPeriod time.Duration @@ -127,8 +127,8 @@ func InitFlags(fs *pflag.FlagSet) { fs.DurationVar(&leaderElectionRetryPeriod, "leader-elect-retry-period", 5*time.Second, "Duration the LeaderElector clients should wait between tries of actions (duration string)") - fs.StringVar(&watchNamespace, "namespace", "", - "Namespace that the controller watches to reconcile cluster-api objects. If unspecified, the controller watches for cluster-api objects across all namespaces.") + fs.StringSliceVar(&watchNamespacesList, "namespace", nil, + "Comma-separated list of namespaces that the controller watches to reconcile cluster-api objects. If unspecified, the controller watches for cluster-api objects across all namespaces.") fs.StringVar(&watchFilterValue, "watch-filter", "", fmt.Sprintf("Label value that the controller watches to reconcile cluster-api objects. Label key is always %s. If unspecified, the controller watches for all cluster-api objects.", clusterv1.WatchLabel)) @@ -235,9 +235,10 @@ func main() { } var watchNamespaces map[string]cache.Config - if watchNamespace != "" { - watchNamespaces = map[string]cache.Config{ - watchNamespace: {}, + if watchNamespacesList != nil { + watchNamespaces = map[string]cache.Config{} + for _, watchNamespace := range watchNamespacesList { + watchNamespaces[watchNamespace] = cache.Config{} } } diff --git a/main.go b/main.go index 919e0313f64f..ebc31657cf9d 100644 --- a/main.go +++ b/main.go @@ -98,7 +98,7 @@ var ( leaderElectionRenewDeadline time.Duration leaderElectionRetryPeriod time.Duration watchFilterValue string - watchNamespace string + watchNamespacesList []string profilerAddress string enableContentionProfiling bool syncPeriod time.Duration @@ -171,8 +171,8 @@ func InitFlags(fs *pflag.FlagSet) { fs.DurationVar(&leaderElectionRetryPeriod, "leader-elect-retry-period", 2*time.Second, "Duration the LeaderElector clients should wait between tries of actions (duration string)") - fs.StringVar(&watchNamespace, "namespace", "", - "Namespace that the controller watches to reconcile cluster-api objects. If unspecified, the controller watches for cluster-api objects across all namespaces.") + fs.StringSliceVar(&watchNamespacesList, "namespace", nil, + "Comma-separated list of namespaces that the controller watches to reconcile cluster-api objects. If unspecified, the controller watches for cluster-api objects across all namespaces.") fs.StringVar(&watchFilterValue, "watch-filter", "", fmt.Sprintf("Label value that the controller watches to reconcile cluster-api objects. Label key is always %s. If unspecified, the controller watches for all cluster-api objects.", clusterv1.WatchLabel)) @@ -321,9 +321,10 @@ func main() { } var watchNamespaces map[string]cache.Config - if watchNamespace != "" { - watchNamespaces = map[string]cache.Config{ - watchNamespace: {}, + if watchNamespacesList != nil { + watchNamespaces = map[string]cache.Config{} + for _, watchNamespace := range watchNamespacesList { + watchNamespaces[watchNamespace] = cache.Config{} } } diff --git a/test/infrastructure/docker/main.go b/test/infrastructure/docker/main.go index 425425c396a5..9720de0c01e8 100644 --- a/test/infrastructure/docker/main.go +++ b/test/infrastructure/docker/main.go @@ -77,7 +77,7 @@ var ( leaderElectionRenewDeadline time.Duration leaderElectionRetryPeriod time.Duration watchFilterValue string - watchNamespace string + watchNamespacesList []string profilerAddress string enableContentionProfiling bool syncPeriod time.Duration @@ -125,8 +125,8 @@ func InitFlags(fs *pflag.FlagSet) { fs.DurationVar(&leaderElectionRetryPeriod, "leader-elect-retry-period", 2*time.Second, "Duration the LeaderElector clients should wait between tries of actions (duration string)") - fs.StringVar(&watchNamespace, "namespace", "", - "Namespace that the controller watches to reconcile cluster-api objects. If unspecified, the controller watches for cluster-api objects across all namespaces.") + fs.StringSliceVar(&watchNamespacesList, "namespace", nil, + "Comma-separated list of namespaces that the controller watches to reconcile cluster-api objects. If unspecified, the controller watches for cluster-api objects across all namespaces.") fs.StringVar(&watchFilterValue, "watch-filter", "", fmt.Sprintf("Label value that the controller watches to reconcile cluster-api objects. Label key is always %s. If unspecified, the controller watches for all cluster-api objects.", clusterv1.WatchLabel)) @@ -218,9 +218,10 @@ func main() { } var watchNamespaces map[string]cache.Config - if watchNamespace != "" { - watchNamespaces = map[string]cache.Config{ - watchNamespace: {}, + if watchNamespacesList != nil { + watchNamespaces = map[string]cache.Config{} + for _, watchNamespace := range watchNamespacesList { + watchNamespaces[watchNamespace] = cache.Config{} } }