@@ -388,6 +388,9 @@ pub struct ClusterResources {
388
388
/// The name of the application
389
389
app_name : String ,
390
390
391
+ /// The uid of the cluster object
392
+ cluster_uid : String ,
393
+
391
394
// TODO (Techassi): Add doc comments
392
395
operator_name : String ,
393
396
@@ -434,17 +437,22 @@ impl ClusterResources {
434
437
) -> Result < Self > {
435
438
let namespace = cluster
436
439
. namespace
437
- . to_owned ( )
440
+ . clone ( )
438
441
. context ( MissingObjectKeySnafu { key : "namespace" } ) ?;
439
442
let app_instance = cluster
440
443
. name
441
- . to_owned ( )
444
+ . clone ( )
442
445
. context ( MissingObjectKeySnafu { key : "name" } ) ?;
446
+ let cluster_uid = cluster
447
+ . uid
448
+ . clone ( )
449
+ . context ( MissingObjectKeySnafu { key : "uid" } ) ?;
443
450
444
451
Ok ( ClusterResources {
445
452
namespace,
446
453
app_instance,
447
454
app_name : app_name. into ( ) ,
455
+ cluster_uid,
448
456
operator_name : operator_name. into ( ) ,
449
457
controller_name : controller_name. into ( ) ,
450
458
manager : format_full_controller_name ( operator_name, controller_name) ,
@@ -741,10 +749,22 @@ impl ClusterResources {
741
749
..Default :: default ( )
742
750
} ;
743
751
744
- let resources = client
752
+ let mut resources = client
745
753
. list_with_label_selector :: < T > ( & self . namespace , & label_selector)
746
754
. await ?;
747
755
756
+ // filter out objects without a direct ownership relationship, for example:
757
+ // - indirect ownership where the labels are still propagated
758
+ // - objects owned by versions of the cluster recreated before/after the current snapshot
759
+ resources. retain ( |resource| {
760
+ resource
761
+ . meta ( )
762
+ . owner_references
763
+ . iter ( )
764
+ . flatten ( )
765
+ . any ( |reference| reference. uid == self . cluster_uid )
766
+ } ) ;
767
+
748
768
Ok ( resources)
749
769
}
750
770
}
0 commit comments