...

Source file src/github.com/redhat-developer/odo/pkg/kclient/owner_reference.go

Documentation: github.com/redhat-developer/odo/pkg/kclient

     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  // TryWithBlockOwnerDeletion will execute `exec` a first time with `BlockOwnerDeletion` set to true in `ownerReference`
    10  // If a Forbidden errors occurs, it will call `exec` again with the original `ownerReference`
    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