@@ -77,15 +77,22 @@ func (r *ClusterResourceSetBindingReconciler) Reconcile(ctx context.Context, req
7777 }
7878
7979 cluster , err := util .GetOwnerCluster (ctx , r .Client , binding .ObjectMeta )
80- if err != nil && ! apierrors .IsNotFound (err ) {
80+ if err != nil {
81+ if apierrors .IsNotFound (err ) {
82+ // If the owner cluster is already deleted, delete its ClusterResourceSetBinding
83+ log .Info ("deleting ClusterResourceSetBinding because the owner Cluster no longer exists" )
84+ return ctrl.Result {}, r .Client .Delete (ctx , binding )
85+ }
8186 return ctrl.Result {}, err
8287 }
83-
84- // If the owner cluster is already deleted or in deletion process, delete its ClusterResourceSetBinding
85- if apierrors .IsNotFound (err ) || ! cluster .DeletionTimestamp .IsZero () {
86- log .Info ("deleting ClusterResourceSetBinding because the owner Cluster no longer exists" )
87- err := r .Client .Delete (ctx , binding )
88- return ctrl.Result {}, err
88+ if cluster == nil {
89+ log .Info ("ownerRef not found for the ClusterResourceSetBinding" )
90+ return ctrl.Result {}, nil
91+ }
92+ // If the owner cluster is in deletion process, delete its ClusterResourceSetBinding
93+ if ! cluster .DeletionTimestamp .IsZero () {
94+ log .Info ("deleting ClusterResourceSetBinding because the owner Cluster is currently being deleted" )
95+ return ctrl.Result {}, r .Client .Delete (ctx , binding )
8996 }
9097
9198 return ctrl.Result {}, nil
0 commit comments