Skip to content

Commit

Permalink
Update the --namespace <namespace> option to accept a comma-separated…
Browse files Browse the repository at this point in the history
… list of namespaces: <namespace1,namespace2,...> to enable selecting multiple namespaces to watch.
  • Loading branch information
marek-veber committed Nov 11, 2024
1 parent e13abea commit 3de925b
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 24 deletions.
13 changes: 7 additions & 6 deletions bootstrap/kubeadm/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ var (
leaderElectionRenewDeadline time.Duration
leaderElectionRetryPeriod time.Duration
watchFilterValue string
watchNamespace string
watchNamespacesList []string
profilerAddress string
enableContentionProfiling bool
syncPeriod time.Duration
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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{}
}
}

Expand Down
13 changes: 7 additions & 6 deletions controlplane/kubeadm/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ var (
leaderElectionRenewDeadline time.Duration
leaderElectionRetryPeriod time.Duration
watchFilterValue string
watchNamespace string
watchNamespacesList []string
profilerAddress string
enableContentionProfiling bool
syncPeriod time.Duration
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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{}
}
}

Expand Down
13 changes: 7 additions & 6 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ var (
leaderElectionRenewDeadline time.Duration
leaderElectionRetryPeriod time.Duration
watchFilterValue string
watchNamespace string
watchNamespacesList []string
profilerAddress string
enableContentionProfiling bool
syncPeriod time.Duration
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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{}
}
}

Expand Down
13 changes: 7 additions & 6 deletions test/infrastructure/docker/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ var (
leaderElectionRenewDeadline time.Duration
leaderElectionRetryPeriod time.Duration
watchFilterValue string
watchNamespace string
watchNamespacesList []string
profilerAddress string
enableContentionProfiling bool
syncPeriod time.Duration
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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{}
}
}

Expand Down

0 comments on commit 3de925b

Please sign in to comment.