Support delete ophranworks can continue the remove operation when an exception occurs, and finally return all deleted exceptions

Signed-off-by: wawa0210 <xiaozhang0210@hotmail.com>
This commit is contained in:
wawa0210 2021-10-13 23:44:17 +08:00
parent d3a5660abe
commit 2d332b7556
No known key found for this signature in database
GPG Key ID: 900C83A2C098B3B1
1 changed files with 6 additions and 1 deletions

View File

@ -141,13 +141,18 @@ func FindOrphanWorks(c client.Client, bindingNamespace, bindingName string, clus
// RemoveOrphanWorks will remove orphan works.
func RemoveOrphanWorks(c client.Client, works []workv1alpha1.Work) error {
var errs []error
for workIndex, work := range works {
err := c.Delete(context.TODO(), &works[workIndex])
if err != nil {
return err
klog.Errorf("Failed to delete orphan work %s/%s, err is %v", work.GetNamespace(), work.GetName(), err)
errs = append(errs, err)
}
klog.Infof("Delete orphan work %s/%s successfully.", work.GetNamespace(), work.GetName())
}
if len(errs) > 0 {
return errors.NewAggregate(errs)
}
return nil
}