From 3de925bf5d4080197ede38018c586416bf168de3 Mon Sep 17 00:00:00 2001 From: Marek Veber Date: Mon, 11 Nov 2024 13:09:10 +0100 Subject: [PATCH] Update the --namespace option to accept a comma-separated list of namespaces: to enable selecting multiple namespaces to watch. --- bootstrap/kubeadm/main.go | 13 +++++++------ controlplane/kubeadm/main.go | 13 +++++++------ main.go | 13 +++++++------ test/infrastructure/docker/main.go | 13 +++++++------ 4 files changed, 28 insertions(+), 24 deletions(-) diff --git a/bootstrap/kubeadm/main.go b/bootstrap/kubeadm/main.go index bd77fb1e5672..2ac37a0a5029 100644 --- a/bootstrap/kubeadm/main.go +++ b/bootstrap/kubeadm/main.go @@ -69,7 +69,7 @@ var ( leaderElectionRenewDeadline time.Duration leaderElectionRetryPeriod time.Duration watchFilterValue string - watchNamespace string + watchNamespacesList []string profilerAddress string enableContentionProfiling bool syncPeriod time.Duration @@ -116,8 +116,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)) @@ -212,9 +212,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 c54a651820f2..22dd7f7ade84 100644 --- a/controlplane/kubeadm/main.go +++ b/controlplane/kubeadm/main.go @@ -74,7 +74,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", 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)) @@ -237,9 +237,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 f2037700176d..e2050d0d496b 100644 --- a/main.go +++ b/main.go @@ -93,7 +93,7 @@ var ( leaderElectionRenewDeadline time.Duration leaderElectionRetryPeriod time.Duration watchFilterValue string - watchNamespace string + watchNamespacesList []string profilerAddress string enableContentionProfiling bool syncPeriod time.Duration @@ -166,8 +166,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)) @@ -317,9 +317,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 8ab8366569be..3b98e82346ae 100644 --- a/test/infrastructure/docker/main.go +++ b/test/infrastructure/docker/main.go @@ -75,7 +75,7 @@ var ( leaderElectionRenewDeadline time.Duration leaderElectionRetryPeriod time.Duration watchFilterValue string - watchNamespace string + watchNamespacesList []string profilerAddress string enableContentionProfiling bool syncPeriod time.Duration @@ -123,8 +123,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)) @@ -216,9 +216,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{} } }