Skip to content

Commit 3de925b

Browse files
committed
Update the --namespace <namespace> option to accept a comma-separated list of namespaces: <namespace1,namespace2,...> to enable selecting multiple namespaces to watch.
1 parent e13abea commit 3de925b

File tree

4 files changed

+28
-24
lines changed

4 files changed

+28
-24
lines changed

bootstrap/kubeadm/main.go

+7-6
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ var (
6969
leaderElectionRenewDeadline time.Duration
7070
leaderElectionRetryPeriod time.Duration
7171
watchFilterValue string
72-
watchNamespace string
72+
watchNamespacesList []string
7373
profilerAddress string
7474
enableContentionProfiling bool
7575
syncPeriod time.Duration
@@ -116,8 +116,8 @@ func InitFlags(fs *pflag.FlagSet) {
116116
fs.DurationVar(&leaderElectionRetryPeriod, "leader-elect-retry-period", 2*time.Second,
117117
"Duration the LeaderElector clients should wait between tries of actions (duration string)")
118118

119-
fs.StringVar(&watchNamespace, "namespace", "",
120-
"Namespace that the controller watches to reconcile cluster-api objects. If unspecified, the controller watches for cluster-api objects across all namespaces.")
119+
fs.StringSliceVar(&watchNamespacesList, "namespace", nil,
120+
"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.")
121121

122122
fs.StringVar(&watchFilterValue, "watch-filter", "",
123123
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() {
212212
}
213213

214214
var watchNamespaces map[string]cache.Config
215-
if watchNamespace != "" {
216-
watchNamespaces = map[string]cache.Config{
217-
watchNamespace: {},
215+
if watchNamespacesList != nil {
216+
watchNamespaces = map[string]cache.Config{}
217+
for _, watchNamespace := range watchNamespacesList {
218+
watchNamespaces[watchNamespace] = cache.Config{}
218219
}
219220
}
220221

controlplane/kubeadm/main.go

+7-6
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ var (
7474
leaderElectionRenewDeadline time.Duration
7575
leaderElectionRetryPeriod time.Duration
7676
watchFilterValue string
77-
watchNamespace string
77+
watchNamespacesList []string
7878
profilerAddress string
7979
enableContentionProfiling bool
8080
syncPeriod time.Duration
@@ -125,8 +125,8 @@ func InitFlags(fs *pflag.FlagSet) {
125125
fs.DurationVar(&leaderElectionRetryPeriod, "leader-elect-retry-period", 5*time.Second,
126126
"Duration the LeaderElector clients should wait between tries of actions (duration string)")
127127

128-
fs.StringVar(&watchNamespace, "namespace", "",
129-
"Namespace that the controller watches to reconcile cluster-api objects. If unspecified, the controller watches for cluster-api objects across all namespaces.")
128+
fs.StringSliceVar(&watchNamespacesList, "namespace", nil,
129+
"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.")
130130

131131
fs.StringVar(&watchFilterValue, "watch-filter", "",
132132
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() {
237237
}
238238

239239
var watchNamespaces map[string]cache.Config
240-
if watchNamespace != "" {
241-
watchNamespaces = map[string]cache.Config{
242-
watchNamespace: {},
240+
if watchNamespacesList != nil {
241+
watchNamespaces = map[string]cache.Config{}
242+
for _, watchNamespace := range watchNamespacesList {
243+
watchNamespaces[watchNamespace] = cache.Config{}
243244
}
244245
}
245246

main.go

+7-6
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ var (
9393
leaderElectionRenewDeadline time.Duration
9494
leaderElectionRetryPeriod time.Duration
9595
watchFilterValue string
96-
watchNamespace string
96+
watchNamespacesList []string
9797
profilerAddress string
9898
enableContentionProfiling bool
9999
syncPeriod time.Duration
@@ -166,8 +166,8 @@ func InitFlags(fs *pflag.FlagSet) {
166166
fs.DurationVar(&leaderElectionRetryPeriod, "leader-elect-retry-period", 2*time.Second,
167167
"Duration the LeaderElector clients should wait between tries of actions (duration string)")
168168

169-
fs.StringVar(&watchNamespace, "namespace", "",
170-
"Namespace that the controller watches to reconcile cluster-api objects. If unspecified, the controller watches for cluster-api objects across all namespaces.")
169+
fs.StringSliceVar(&watchNamespacesList, "namespace", nil,
170+
"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.")
171171

172172
fs.StringVar(&watchFilterValue, "watch-filter", "",
173173
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() {
317317
}
318318

319319
var watchNamespaces map[string]cache.Config
320-
if watchNamespace != "" {
321-
watchNamespaces = map[string]cache.Config{
322-
watchNamespace: {},
320+
if watchNamespacesList != nil {
321+
watchNamespaces = map[string]cache.Config{}
322+
for _, watchNamespace := range watchNamespacesList {
323+
watchNamespaces[watchNamespace] = cache.Config{}
323324
}
324325
}
325326

test/infrastructure/docker/main.go

+7-6
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ var (
7575
leaderElectionRenewDeadline time.Duration
7676
leaderElectionRetryPeriod time.Duration
7777
watchFilterValue string
78-
watchNamespace string
78+
watchNamespacesList []string
7979
profilerAddress string
8080
enableContentionProfiling bool
8181
syncPeriod time.Duration
@@ -123,8 +123,8 @@ func InitFlags(fs *pflag.FlagSet) {
123123
fs.DurationVar(&leaderElectionRetryPeriod, "leader-elect-retry-period", 2*time.Second,
124124
"Duration the LeaderElector clients should wait between tries of actions (duration string)")
125125

126-
fs.StringVar(&watchNamespace, "namespace", "",
127-
"Namespace that the controller watches to reconcile cluster-api objects. If unspecified, the controller watches for cluster-api objects across all namespaces.")
126+
fs.StringSliceVar(&watchNamespacesList, "namespace", nil,
127+
"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.")
128128

129129
fs.StringVar(&watchFilterValue, "watch-filter", "",
130130
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() {
216216
}
217217

218218
var watchNamespaces map[string]cache.Config
219-
if watchNamespace != "" {
220-
watchNamespaces = map[string]cache.Config{
221-
watchNamespace: {},
219+
if watchNamespacesList != nil {
220+
watchNamespaces = map[string]cache.Config{}
221+
for _, watchNamespace := range watchNamespacesList {
222+
watchNamespaces[watchNamespace] = cache.Config{}
222223
}
223224
}
224225

0 commit comments

Comments
 (0)