@@ -77,15 +77,22 @@ func (r *ClusterResourceSetBindingReconciler) Reconcile(ctx context.Context, req
77
77
}
78
78
79
79
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
+ }
81
86
return ctrl.Result {}, err
82
87
}
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 )
89
96
}
90
97
91
98
return ctrl.Result {}, nil
0 commit comments