...
1 package kclient
2
3 import (
4 apierrors "k8s.io/apimachinery/pkg/api/errors"
5 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
6 "k8s.io/utils/pointer"
7 )
8
9
10
11 func (c *Client) TryWithBlockOwnerDeletion(ownerReference metav1.OwnerReference, exec func(ownerReference metav1.OwnerReference) error) error {
12 blockOwnerRef := ownerReference
13 blockOwnerRef.BlockOwnerDeletion = pointer.Bool(true)
14 err := exec(blockOwnerRef)
15 if err == nil {
16 return nil
17 }
18 if apierrors.IsForbidden(err) {
19 return exec(ownerReference)
20 }
21 return err
22 }
23
View as plain text