diff --git a/pkg/dependenciesdistributor/dependencies_distributor.go b/pkg/dependenciesdistributor/dependencies_distributor.go index 7dad0ba3c149..f08fe1c8cfb2 100644 --- a/pkg/dependenciesdistributor/dependencies_distributor.go +++ b/pkg/dependenciesdistributor/dependencies_distributor.go @@ -518,16 +518,19 @@ func (d *DependenciesDistributor) isOrphanAttachedBindings( return true, nil } -func (d *DependenciesDistributor) listAttachedBindings(bindingID, bindingNamespace, bindingName string) (res []*workv1alpha2.ResourceBinding, err error) { - labelSet := generateBindingDependedLabels(bindingID, bindingNamespace, bindingName) - selector := labels.SelectorFromSet(labelSet) +func (d *DependenciesDistributor) listAttachedBindings(bindingID, bindingNamespace, bindingName string) ([]*workv1alpha2.ResourceBinding, error) { bindingList := &workv1alpha2.ResourceBindingList{} - err = d.Client.List(context.TODO(), bindingList, &client.ListOptions{ + err := d.Client.List(context.TODO(), bindingList, &client.ListOptions{ Namespace: bindingNamespace, - LabelSelector: selector}) + LabelSelector: labels.SelectorFromSet(generateBindingDependedLabels(bindingID, bindingNamespace, bindingName)), + }) if err != nil { + klog.Errorf("Failed to list attached bindings with independent binding(%s/%s): %v", + bindingNamespace, bindingName, err) return nil, err } + + var res []*workv1alpha2.ResourceBinding for i := range bindingList.Items { res = append(res, &bindingList.Items[i]) } @@ -546,6 +549,7 @@ func (d *DependenciesDistributor) removeScheduleResultFromAttachedBindings(bindi delete(attachedBindings[index].Labels, bindingLabelKey) updatedSnapshot := deleteBindingFromSnapshot(bindingNamespace, bindingName, attachedBindings[index].Spec.RequiredBy) attachedBindings[index].Spec.RequiredBy = updatedSnapshot + attachedBindings[index].Spec.PreserveResourcesOnDeletion = nil if err := d.Client.Update(context.TODO(), attachedBindings[index]); err != nil { klog.Errorf("Failed to update binding(%s/%s): %v", binding.Namespace, binding.Name, err) errs = append(errs, err) @@ -563,6 +567,7 @@ func (d *DependenciesDistributor) createOrUpdateAttachedBinding(attachedBinding existBinding.Spec.RequiredBy = mergeBindingSnapshot(existBinding.Spec.RequiredBy, attachedBinding.Spec.RequiredBy) existBinding.Labels = util.DedupeAndMergeLabels(existBinding.Labels, attachedBinding.Labels) existBinding.Spec.Resource = attachedBinding.Spec.Resource + existBinding.Spec.PreserveResourcesOnDeletion = attachedBinding.Spec.PreserveResourcesOnDeletion if err := d.Client.Update(context.TODO(), existBinding); err != nil { klog.Errorf("Failed to update resourceBinding(%s): %v", bindingKey, err) @@ -703,7 +708,8 @@ func buildAttachedBinding(independentBinding *workv1alpha2.ResourceBinding, obje Name: object.GetName(), ResourceVersion: object.GetResourceVersion(), }, - RequiredBy: result, + RequiredBy: result, + PreserveResourcesOnDeletion: independentBinding.Spec.PreserveResourcesOnDeletion, }, } }