@@ -305,10 +305,13 @@ impl ResourceControllerImpl {
305
305
// it gets properly removed by the API server and that we can recreate and sync
306
306
// it.
307
307
match remove_finalizer ( api. clone ( ) , & mut current, FINALIZER ) . await {
308
- Ok ( true ) => debug ! (
309
- "removed finalizer from deleted object {} {}/{}" ,
310
- self . gvk. kind, d. namespace, d. name
311
- ) ,
308
+ Ok ( true ) => {
309
+ debug ! (
310
+ "removed finalizer from deleted object {} {}/{}" ,
311
+ self . gvk. kind, d. namespace, d. name
312
+ ) ;
313
+ continue ;
314
+ }
312
315
Err ( e) => warn ! (
313
316
"failed to remove finalizer from deleted object {} {}/{}: {}" ,
314
317
self . gvk. kind, d. namespace, d. name, e
@@ -325,7 +328,6 @@ impl ResourceControllerImpl {
325
328
{
326
329
template. metadata . uid = current. uid ( ) ;
327
330
template. metadata . resource_version = current. resource_version ( ) ;
328
-
329
331
let result = match & d. strategy ( ) {
330
332
SyncStrategy :: Replace => {
331
333
api. replace ( d. name . as_str ( ) , & pp, & template) . await
@@ -539,6 +541,11 @@ impl ResourceControllerImpl {
539
541
let me = ctx. get_ref ( ) ;
540
542
let namespaced_name = NamespacedName :: from ( & source) ;
541
543
544
+ let source_id = format ! (
545
+ "{}/{}/{} {}" ,
546
+ me. gvk. group, me. gvk. version, me. gvk. kind, namespaced_name
547
+ ) ;
548
+
542
549
let is_source_namespace = me
543
550
. configuration
544
551
. source_namespaces
@@ -552,7 +559,9 @@ impl ResourceControllerImpl {
552
559
guard. get ( & namespaced_name) . cloned ( )
553
560
} else {
554
561
None
555
- } ;
562
+ }
563
+ . filter ( |c| !c. is_empty ( ) ) ;
564
+
556
565
// Add type information required by server-side apply.
557
566
source. types = Some ( TypeMeta {
558
567
api_version : me. gvk . version . clone ( ) ,
@@ -586,10 +595,7 @@ impl ResourceControllerImpl {
586
595
)
587
596
. await
588
597
{
589
- error ! (
590
- "failed to remove finalizer from {}/{}/{} {}: {}" ,
591
- me. gvk. group, me. gvk. version, me. gvk. kind, namespaced_name, e
592
- ) ;
598
+ error ! ( "failed to remove finalizer from {}: {}" , source_id, e) ;
593
599
}
594
600
}
595
601
}
@@ -601,26 +607,15 @@ impl ResourceControllerImpl {
601
607
)
602
608
. await
603
609
{
604
- error ! (
605
- "failed to add finalizer to {}/{}/{} {}: {}" ,
606
- me. gvk. group, me. gvk. version, me. gvk. kind, namespaced_name, e
607
- ) ;
610
+ error ! ( "failed to add finalizer to {}: {}" , source_id, e) ;
608
611
}
609
612
for sync_configuration in sync_configurations {
610
613
if let Some ( mut rs) = me
611
614
. get_object_sync ( & namespaced_name, & sync_configuration)
612
615
. await
613
616
{
614
617
if let Err ( e) = me. reconcile_source ( & mut rs, & source) . await {
615
- error ! (
616
- "failed to reconcile {}/{}/{} {} for {}: {}" ,
617
- me. gvk. group,
618
- me. gvk. version,
619
- me. gvk. kind,
620
- namespaced_name,
621
- rs. id( ) ,
622
- e
623
- ) ;
618
+ error ! ( "failed to reconcile {} for {}: {}" , source_id, rs. id( ) , e) ;
624
619
}
625
620
}
626
621
}
@@ -636,6 +631,10 @@ impl ResourceControllerImpl {
636
631
requeue_after : Some ( Duration :: from_secs ( 300 ) ) ,
637
632
} )
638
633
} else {
634
+ debug ! (
635
+ "ignoring {} as it is not references by any ObjectSync instance" ,
636
+ source_id,
637
+ ) ;
639
638
// No need to requeue objects not tracked by any ObjectSync configuration.
640
639
Ok ( ReconcilerAction {
641
640
requeue_after : None ,
@@ -654,6 +653,17 @@ impl ResourceControllerImpl {
654
653
}
655
654
}
656
655
656
+ /// Get an optimized API instance.
657
+ fn api ( & self , namespaces : & Option < HashSet < String > > ) -> Api < DynamicObject > {
658
+ match namespaces {
659
+ Some ( namespaces) if namespaces. len ( ) == 1 => match namespaces. iter ( ) . next ( ) {
660
+ Some ( ns) => Api :: namespaced_with ( self . client ( ) , ns. as_str ( ) , & self . api_resource ) ,
661
+ _ => Api :: all_with ( self . client ( ) , & self . api_resource ) ,
662
+ } ,
663
+ _ => Api :: all_with ( self . client ( ) , & self . api_resource ) ,
664
+ }
665
+ }
666
+
657
667
pub async fn start (
658
668
self ,
659
669
reload : Receiver < ( ) > ,
@@ -663,20 +673,8 @@ impl ResourceControllerImpl {
663
673
let api_resource = self . api_resource . clone ( ) ;
664
674
let api_resource2 = self . api_resource . clone ( ) ;
665
675
let api_resource3 = self . api_resource . clone ( ) ;
666
- let src_api = match & self . configuration . source_namespaces {
667
- Some ( hs) if hs. len ( ) == 1 => match hs. iter ( ) . next ( ) {
668
- Some ( ns) => Api :: namespaced_with ( self . client ( ) , ns. as_str ( ) , & self . api_resource ) ,
669
- None => Api :: all_with ( self . client ( ) , & self . api_resource ) ,
670
- } ,
671
- _ => Api :: all_with ( self . client ( ) , & self . api_resource ) ,
672
- } ;
673
- let dst_api = match & self . configuration . target_namespaces {
674
- Some ( hs) if hs. len ( ) == 1 => match hs. iter ( ) . next ( ) {
675
- Some ( ns) => Api :: namespaced_with ( self . client ( ) , ns. as_str ( ) , & self . api_resource ) ,
676
- None => Api :: all_with ( self . client ( ) , & self . api_resource ) ,
677
- } ,
678
- _ => Api :: all_with ( self . client ( ) , & self . api_resource ) ,
679
- } ;
676
+ let src_api = self . api ( & self . configuration . source_namespaces ) ;
677
+ let dst_api = self . api ( & self . configuration . target_namespaces ) ;
680
678
let list_params = ListParams :: default ( ) ;
681
679
let controller = Controller :: new_with ( src_api, list_params, self . api_resource . clone ( ) ) ;
682
680
let sources = self . sources . clone ( ) ;
@@ -691,9 +689,9 @@ impl ResourceControllerImpl {
691
689
Api :: < Namespace > :: all ( self . client ( ) ) ,
692
690
ListParams :: default ( ) ,
693
691
move |namespace| {
694
- let is_target_namespace = target_namespaces2. as_ref ( ) . map_or ( true , |v| {
695
- v . is_empty ( ) || v . contains ( namespace . name ( ) . as_str ( ) ) || v . contains ( "*" )
696
- } ) ;
692
+ let is_target_namespace = target_namespaces2
693
+ . as_ref ( )
694
+ . map_or ( true , |v| v . contains ( namespace . name ( ) . as_str ( ) ) ) ;
697
695
if let Some ( ct) = & namespace. metadata . creation_timestamp {
698
696
let age = Utc :: now ( ) - ct. 0 ;
699
697
if is_target_namespace && age. num_seconds ( ) < 300 {
@@ -736,9 +734,9 @@ impl ResourceControllerImpl {
736
734
lp_dst,
737
735
move |rs : DynamicObject | {
738
736
let namespace = rs. namespace ( ) . unwrap_or_else ( || "" . to_string ( ) ) ;
739
- let is_target_namespace = target_namespaces. as_ref ( ) . map_or ( true , |v| {
740
- v . is_empty ( ) || v . contains ( namespace . as_str ( ) ) || v . contains ( "*" )
741
- } ) ;
737
+ let is_target_namespace = target_namespaces
738
+ . as_ref ( )
739
+ . map_or ( true , |v| v . contains ( namespace . as_str ( ) ) ) ;
742
740
if let Some ( annotation) =
743
741
rs. annotations ( ) . get ( source_object_annotation_key. as_str ( ) )
744
742
{
0 commit comments