Skip to content

Commit 76804ea

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 69df836 commit 76804ea

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
@@ -71,7 +71,7 @@ var (
7171
leaderElectionRenewDeadline time.Duration
7272
leaderElectionRetryPeriod time.Duration
7373
watchFilterValue string
74-
watchNamespace string
74+
watchNamespacesList []string
7575
profilerAddress string
7676
enableContentionProfiling bool
7777
syncPeriod time.Duration
@@ -118,8 +118,8 @@ func InitFlags(fs *pflag.FlagSet) {
118118
fs.DurationVar(&leaderElectionRetryPeriod, "leader-elect-retry-period", 2*time.Second,
119119
"Duration the LeaderElector clients should wait between tries of actions (duration string)")
120120

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

124124
fs.StringVar(&watchFilterValue, "watch-filter", "",
125125
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() {
214214
}
215215

216216
var watchNamespaces map[string]cache.Config
217-
if watchNamespace != "" {
218-
watchNamespaces = map[string]cache.Config{
219-
watchNamespace: {},
217+
if watchNamespacesList != nil {
218+
watchNamespaces = map[string]cache.Config{}
219+
for _, watchNamespace := range watchNamespacesList {
220+
watchNamespaces[watchNamespace] = cache.Config{}
220221
}
221222
}
222223

controlplane/kubeadm/main.go

+7-6
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ var (
7777
leaderElectionRenewDeadline time.Duration
7878
leaderElectionRetryPeriod time.Duration
7979
watchFilterValue string
80-
watchNamespace string
80+
watchNamespacesList []string
8181
profilerAddress string
8282
enableContentionProfiling bool
8383
syncPeriod time.Duration
@@ -127,8 +127,8 @@ func InitFlags(fs *pflag.FlagSet) {
127127
fs.DurationVar(&leaderElectionRetryPeriod, "leader-elect-retry-period", 5*time.Second,
128128
"Duration the LeaderElector clients should wait between tries of actions (duration string)")
129129

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

133133
fs.StringVar(&watchFilterValue, "watch-filter", "",
134134
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() {
235235
}
236236

237237
var watchNamespaces map[string]cache.Config
238-
if watchNamespace != "" {
239-
watchNamespaces = map[string]cache.Config{
240-
watchNamespace: {},
238+
if watchNamespacesList != nil {
239+
watchNamespaces = map[string]cache.Config{}
240+
for _, watchNamespace := range watchNamespacesList {
241+
watchNamespaces[watchNamespace] = cache.Config{}
241242
}
242243
}
243244

main.go

+7-6
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ var (
9898
leaderElectionRenewDeadline time.Duration
9999
leaderElectionRetryPeriod time.Duration
100100
watchFilterValue string
101-
watchNamespace string
101+
watchNamespacesList []string
102102
profilerAddress string
103103
enableContentionProfiling bool
104104
syncPeriod time.Duration
@@ -171,8 +171,8 @@ func InitFlags(fs *pflag.FlagSet) {
171171
fs.DurationVar(&leaderElectionRetryPeriod, "leader-elect-retry-period", 2*time.Second,
172172
"Duration the LeaderElector clients should wait between tries of actions (duration string)")
173173

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

177177
fs.StringVar(&watchFilterValue, "watch-filter", "",
178178
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() {
321321
}
322322

323323
var watchNamespaces map[string]cache.Config
324-
if watchNamespace != "" {
325-
watchNamespaces = map[string]cache.Config{
326-
watchNamespace: {},
324+
if watchNamespacesList != nil {
325+
watchNamespaces = map[string]cache.Config{}
326+
for _, watchNamespace := range watchNamespacesList {
327+
watchNamespaces[watchNamespace] = cache.Config{}
327328
}
328329
}
329330

test/infrastructure/docker/main.go

+7-6
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ var (
7777
leaderElectionRenewDeadline time.Duration
7878
leaderElectionRetryPeriod time.Duration
7979
watchFilterValue string
80-
watchNamespace string
80+
watchNamespacesList []string
8181
profilerAddress string
8282
enableContentionProfiling bool
8383
syncPeriod time.Duration
@@ -125,8 +125,8 @@ func InitFlags(fs *pflag.FlagSet) {
125125
fs.DurationVar(&leaderElectionRetryPeriod, "leader-elect-retry-period", 2*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))
@@ -218,9 +218,10 @@ func main() {
218218
}
219219

220220
var watchNamespaces map[string]cache.Config
221-
if watchNamespace != "" {
222-
watchNamespaces = map[string]cache.Config{
223-
watchNamespace: {},
221+
if watchNamespacesList != nil {
222+
watchNamespaces = map[string]cache.Config{}
223+
for _, watchNamespace := range watchNamespacesList {
224+
watchNamespaces[watchNamespace] = cache.Config{}
224225
}
225226
}
226227

0 commit comments

Comments
 (0)