@@ -388,6 +388,9 @@ pub struct ClusterResources {
388388 /// The name of the application
389389 app_name : String ,
390390
391+ /// The uid of the cluster object
392+ cluster_uid : String ,
393+
391394 // TODO (Techassi): Add doc comments
392395 operator_name : String ,
393396
@@ -434,17 +437,22 @@ impl ClusterResources {
434437 ) -> Result < Self > {
435438 let namespace = cluster
436439 . namespace
437- . to_owned ( )
440+ . clone ( )
438441 . context ( MissingObjectKeySnafu { key : "namespace" } ) ?;
439442 let app_instance = cluster
440443 . name
441- . to_owned ( )
444+ . clone ( )
442445 . context ( MissingObjectKeySnafu { key : "name" } ) ?;
446+ let cluster_uid = cluster
447+ . uid
448+ . clone ( )
449+ . context ( MissingObjectKeySnafu { key : "uid" } ) ?;
443450
444451 Ok ( ClusterResources {
445452 namespace,
446453 app_instance,
447454 app_name : app_name. into ( ) ,
455+ cluster_uid,
448456 operator_name : operator_name. into ( ) ,
449457 controller_name : controller_name. into ( ) ,
450458 manager : format_full_controller_name ( operator_name, controller_name) ,
@@ -741,10 +749,22 @@ impl ClusterResources {
741749 ..Default :: default ( )
742750 } ;
743751
744- let resources = client
752+ let mut resources = client
745753 . list_with_label_selector :: < T > ( & self . namespace , & label_selector)
746754 . await ?;
747755
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+
748768 Ok ( resources)
749769 }
750770}
0 commit comments