@@ -292,37 +292,43 @@ func addConfigSecretToHash(ctx context.Context, k8sClient client.Client, hash ha
292
292
293
293
func addConfigMapToHash (ctx context.Context , k8sClient client.Client , hash hash.Hash , provider genericprovider.GenericProvider ) error {
294
294
spec := provider .GetSpec ()
295
- if spec .FetchConfig != nil && spec .FetchConfig .Selector != nil {
296
- // List ConfigMaps that match the provider's selector
297
- selector , err := metav1 .LabelSelectorAsSelector (spec .FetchConfig .Selector )
298
- if err != nil {
299
- return err
300
- }
295
+ if spec .FetchConfig == nil || spec .FetchConfig .Selector == nil {
296
+ return nil
297
+ }
301
298
302
- configMapList := & corev1.ConfigMapList {}
303
- listOpts := []client.ListOption {
304
- client.MatchingLabelsSelector {Selector : selector },
305
- client .InNamespace (provider .GetNamespace ()),
306
- }
299
+ return processProviderConfigMaps (ctx , k8sClient , hash , provider , spec .FetchConfig .Selector )
300
+ }
307
301
308
- if err := k8sClient .List (ctx , configMapList , listOpts ... ); err != nil {
309
- return err
310
- }
302
+ func processProviderConfigMaps (ctx context.Context , k8sClient client.Client , hash hash.Hash , provider genericprovider.GenericProvider , selector * metav1.LabelSelector ) error {
303
+ // List ConfigMaps that match the provider's selector
304
+ labelSelector , err := metav1 .LabelSelectorAsSelector (selector )
305
+ if err != nil {
306
+ return err
307
+ }
311
308
312
- // Ensure only one ConfigMap matches the selector
313
- if len (configMapList .Items ) > 1 {
314
- return fmt .Errorf ("multiple ConfigMaps match the provider selector, only one ConfigMap per provider is allowed" )
315
- }
309
+ configMapList := & corev1.ConfigMapList {}
310
+ listOpts := []client.ListOption {
311
+ client.MatchingLabelsSelector {Selector : labelSelector },
312
+ client .InNamespace (provider .GetNamespace ()),
313
+ }
316
314
317
- // Add the ConfigMap's data to the hash (if any ConfigMap exists)
318
- if len (configMapList .Items ) == 1 {
319
- cm := configMapList .Items [0 ]
320
- if err := addObjectToHash (hash , cm .Data ); err != nil {
321
- return err
322
- }
323
- if err := addObjectToHash (hash , cm .BinaryData ); err != nil {
324
- return err
325
- }
315
+ if err := k8sClient .List (ctx , configMapList , listOpts ... ); err != nil {
316
+ return err
317
+ }
318
+
319
+ // Ensure only one ConfigMap matches the selector
320
+ if len (configMapList .Items ) > 1 {
321
+ return fmt .Errorf ("multiple ConfigMaps match the provider selector, only one ConfigMap per provider is allowed" )
322
+ }
323
+
324
+ // Add the ConfigMap's data to the hash (if any ConfigMap exists)
325
+ if len (configMapList .Items ) == 1 {
326
+ cm := configMapList .Items [0 ]
327
+ if err := addObjectToHash (hash , cm .Data ); err != nil {
328
+ return err
329
+ }
330
+ if err := addObjectToHash (hash , cm .BinaryData ); err != nil {
331
+ return err
326
332
}
327
333
}
328
334
0 commit comments