@@ -147,30 +147,37 @@ func main() {
147
147
os .Exit (1 )
148
148
}
149
149
150
- unstructuredCachingClient , err := client .New (mgr .GetConfig (), client.Options {
151
- HTTPClient : mgr .GetHTTPClient (),
152
- Cache : & client.CacheOptions {
153
- Reader : mgr .GetCache (),
154
- Unstructured : true ,
155
- },
156
- })
157
- if err != nil {
158
- setupLog .Error (err , "unable to create unstructured caching client" )
159
- os .Exit (1 )
160
- }
161
-
162
- if err := (& namespacesync.Reconciler {
163
- Client : mgr .GetClient (),
164
- UnstructuredCachingClient : unstructuredCachingClient ,
165
- SourceClusterClassNamespace : namespacesyncOptions .SourceNamespace ,
166
- TargetNamespaceFilter : namespacesync .NamespaceHasLabelKey (namespacesyncOptions .TargetNamespaceLabelKey ),
167
- }).SetupWithManager (
168
- signalCtx ,
169
- mgr ,
170
- controller.Options {MaxConcurrentReconciles : namespacesyncOptions .Concurrency },
171
- ); err != nil {
172
- setupLog .Error (err , "unable to create controller" , "controller" , "namespacesync.Reconciler" )
173
- os .Exit (1 )
150
+ if namespacesyncOptions .Enabled {
151
+ if namespacesyncOptions .SourceNamespace == "" || namespacesyncOptions .TargetNamespaceLabelKey == "" {
152
+ setupLog .Error (nil , "Namespace Sync is enabled, but source namespace and/or target namespace label key are not configured." ) //nolint:lll // Usage string is wrapped in the terminal.
153
+ os .Exit (1 )
154
+ }
155
+
156
+ unstructuredCachingClient , err := client .New (mgr .GetConfig (), client.Options {
157
+ HTTPClient : mgr .GetHTTPClient (),
158
+ Cache : & client.CacheOptions {
159
+ Reader : mgr .GetCache (),
160
+ Unstructured : true ,
161
+ },
162
+ })
163
+ if err != nil {
164
+ setupLog .Error (err , "unable to create unstructured caching client" )
165
+ os .Exit (1 )
166
+ }
167
+
168
+ if err := (& namespacesync.Reconciler {
169
+ Client : mgr .GetClient (),
170
+ UnstructuredCachingClient : unstructuredCachingClient ,
171
+ SourceClusterClassNamespace : namespacesyncOptions .SourceNamespace ,
172
+ TargetNamespaceFilter : namespacesync .NamespaceHasLabelKey (namespacesyncOptions .TargetNamespaceLabelKey ),
173
+ }).SetupWithManager (
174
+ signalCtx ,
175
+ mgr ,
176
+ controller.Options {MaxConcurrentReconciles : namespacesyncOptions .Concurrency },
177
+ ); err != nil {
178
+ setupLog .Error (err , "unable to create controller" , "controller" , "namespacesync.Reconciler" )
179
+ os .Exit (1 )
180
+ }
174
181
}
175
182
176
183
if err := mgr .Start (signalCtx ); err != nil {
0 commit comments