Merge pull request #45894 from tnozicka/export-base-controller-ref-manager

Automatic merge from submit-queue (batch tested with PRs 49017, 45440, 48384, 45894, 48808)

Export BaseControllerRefManager

**What this PR does / why we need it**:
It exports go struct `baseControllerRefManager`. This is needed so other distributions like OpenShift or TPR controllers can reuse that code for writing ref managers for other objects. 

**Release note**:
It is not worthy of a release note.
This commit is contained in:
Kubernetes Submit Queue 2017-07-17 16:26:57 -07:00 committed by GitHub
commit e7cf03e0cf

View File

@ -44,31 +44,31 @@ func GetControllerOf(controllee metav1.Object) *metav1.OwnerReference {
return nil return nil
} }
type baseControllerRefManager struct { type BaseControllerRefManager struct {
controller metav1.Object Controller metav1.Object
selector labels.Selector Selector labels.Selector
canAdoptErr error canAdoptErr error
canAdoptOnce sync.Once canAdoptOnce sync.Once
canAdoptFunc func() error CanAdoptFunc func() error
} }
func (m *baseControllerRefManager) canAdopt() error { func (m *BaseControllerRefManager) CanAdopt() error {
m.canAdoptOnce.Do(func() { m.canAdoptOnce.Do(func() {
if m.canAdoptFunc != nil { if m.CanAdoptFunc != nil {
m.canAdoptErr = m.canAdoptFunc() m.canAdoptErr = m.CanAdoptFunc()
} }
}) })
return m.canAdoptErr return m.canAdoptErr
} }
// claimObject tries to take ownership of an object for this controller. // ClaimObject tries to take ownership of an object for this controller.
// //
// It will reconcile the following: // It will reconcile the following:
// * Adopt orphans if the match function returns true. // * Adopt orphans if the match function returns true.
// * Release owned objects if the match function returns false. // * Release owned objects if the match function returns false.
// //
// A non-nil error is returned if some form of reconciliation was attemped and // A non-nil error is returned if some form of reconciliation was attempted and
// failed. Usually, controllers should try again later in case reconciliation // failed. Usually, controllers should try again later in case reconciliation
// is still needed. // is still needed.
// //
@ -77,10 +77,10 @@ func (m *baseControllerRefManager) canAdopt() error {
// own the object. // own the object.
// //
// No reconciliation will be attempted if the controller is being deleted. // No reconciliation will be attempted if the controller is being deleted.
func (m *baseControllerRefManager) claimObject(obj metav1.Object, match func(metav1.Object) bool, adopt, release func(metav1.Object) error) (bool, error) { func (m *BaseControllerRefManager) ClaimObject(obj metav1.Object, match func(metav1.Object) bool, adopt, release func(metav1.Object) error) (bool, error) {
controllerRef := GetControllerOf(obj) controllerRef := GetControllerOf(obj)
if controllerRef != nil { if controllerRef != nil {
if controllerRef.UID != m.controller.GetUID() { if controllerRef.UID != m.Controller.GetUID() {
// Owned by someone else. Ignore. // Owned by someone else. Ignore.
return false, nil return false, nil
} }
@ -93,7 +93,7 @@ func (m *baseControllerRefManager) claimObject(obj metav1.Object, match func(met
} }
// Owned by us but selector doesn't match. // Owned by us but selector doesn't match.
// Try to release, unless we're being deleted. // Try to release, unless we're being deleted.
if m.controller.GetDeletionTimestamp() != nil { if m.Controller.GetDeletionTimestamp() != nil {
return false, nil return false, nil
} }
if err := release(obj); err != nil { if err := release(obj); err != nil {
@ -110,7 +110,7 @@ func (m *baseControllerRefManager) claimObject(obj metav1.Object, match func(met
} }
// It's an orphan. // It's an orphan.
if m.controller.GetDeletionTimestamp() != nil || !match(obj) { if m.Controller.GetDeletionTimestamp() != nil || !match(obj) {
// Ignore if we're being deleted or selector doesn't match. // Ignore if we're being deleted or selector doesn't match.
return false, nil return false, nil
} }
@ -133,7 +133,7 @@ func (m *baseControllerRefManager) claimObject(obj metav1.Object, match func(met
} }
type PodControllerRefManager struct { type PodControllerRefManager struct {
baseControllerRefManager BaseControllerRefManager
controllerKind schema.GroupVersionKind controllerKind schema.GroupVersionKind
podControl PodControlInterface podControl PodControlInterface
} }
@ -141,14 +141,14 @@ type PodControllerRefManager struct {
// NewPodControllerRefManager returns a PodControllerRefManager that exposes // NewPodControllerRefManager returns a PodControllerRefManager that exposes
// methods to manage the controllerRef of pods. // methods to manage the controllerRef of pods.
// //
// The canAdopt() function can be used to perform a potentially expensive check // The CanAdopt() function can be used to perform a potentially expensive check
// (such as a live GET from the API server) prior to the first adoption. // (such as a live GET from the API server) prior to the first adoption.
// It will only be called (at most once) if an adoption is actually attempted. // It will only be called (at most once) if an adoption is actually attempted.
// If canAdopt() returns a non-nil error, all adoptions will fail. // If CanAdopt() returns a non-nil error, all adoptions will fail.
// //
// NOTE: Once canAdopt() is called, it will not be called again by the same // NOTE: Once CanAdopt() is called, it will not be called again by the same
// PodControllerRefManager instance. Create a new instance if it makes // PodControllerRefManager instance. Create a new instance if it makes
// sense to check canAdopt() again (e.g. in a different sync pass). // sense to check CanAdopt() again (e.g. in a different sync pass).
func NewPodControllerRefManager( func NewPodControllerRefManager(
podControl PodControlInterface, podControl PodControlInterface,
controller metav1.Object, controller metav1.Object,
@ -157,10 +157,10 @@ func NewPodControllerRefManager(
canAdopt func() error, canAdopt func() error,
) *PodControllerRefManager { ) *PodControllerRefManager {
return &PodControllerRefManager{ return &PodControllerRefManager{
baseControllerRefManager: baseControllerRefManager{ BaseControllerRefManager: BaseControllerRefManager{
controller: controller, Controller: controller,
selector: selector, Selector: selector,
canAdoptFunc: canAdopt, CanAdoptFunc: canAdopt,
}, },
controllerKind: controllerKind, controllerKind: controllerKind,
podControl: podControl, podControl: podControl,
@ -176,7 +176,7 @@ func NewPodControllerRefManager(
// Optional: If one or more filters are specified, a Pod will only be claimed if // Optional: If one or more filters are specified, a Pod will only be claimed if
// all filters return true. // all filters return true.
// //
// A non-nil error is returned if some form of reconciliation was attemped and // A non-nil error is returned if some form of reconciliation was attempted and
// failed. Usually, controllers should try again later in case reconciliation // failed. Usually, controllers should try again later in case reconciliation
// is still needed. // is still needed.
// //
@ -189,7 +189,7 @@ func (m *PodControllerRefManager) ClaimPods(pods []*v1.Pod, filters ...func(*v1.
match := func(obj metav1.Object) bool { match := func(obj metav1.Object) bool {
pod := obj.(*v1.Pod) pod := obj.(*v1.Pod)
// Check selector first so filters only run on potentially matching Pods. // Check selector first so filters only run on potentially matching Pods.
if !m.selector.Matches(labels.Set(pod.Labels)) { if !m.Selector.Matches(labels.Set(pod.Labels)) {
return false return false
} }
for _, filter := range filters { for _, filter := range filters {
@ -207,7 +207,7 @@ func (m *PodControllerRefManager) ClaimPods(pods []*v1.Pod, filters ...func(*v1.
} }
for _, pod := range pods { for _, pod := range pods {
ok, err := m.claimObject(pod, match, adopt, release) ok, err := m.ClaimObject(pod, match, adopt, release)
if err != nil { if err != nil {
errlist = append(errlist, err) errlist = append(errlist, err)
continue continue
@ -222,7 +222,7 @@ func (m *PodControllerRefManager) ClaimPods(pods []*v1.Pod, filters ...func(*v1.
// AdoptPod sends a patch to take control of the pod. It returns the error if // AdoptPod sends a patch to take control of the pod. It returns the error if
// the patching fails. // the patching fails.
func (m *PodControllerRefManager) AdoptPod(pod *v1.Pod) error { func (m *PodControllerRefManager) AdoptPod(pod *v1.Pod) error {
if err := m.canAdopt(); err != nil { if err := m.CanAdopt(); err != nil {
return fmt.Errorf("can't adopt Pod %v/%v (%v): %v", pod.Namespace, pod.Name, pod.UID, err) return fmt.Errorf("can't adopt Pod %v/%v (%v): %v", pod.Namespace, pod.Name, pod.UID, err)
} }
// Note that ValidateOwnerReferences() will reject this patch if another // Note that ValidateOwnerReferences() will reject this patch if another
@ -230,7 +230,7 @@ func (m *PodControllerRefManager) AdoptPod(pod *v1.Pod) error {
addControllerPatch := fmt.Sprintf( addControllerPatch := fmt.Sprintf(
`{"metadata":{"ownerReferences":[{"apiVersion":"%s","kind":"%s","name":"%s","uid":"%s","controller":true,"blockOwnerDeletion":true}],"uid":"%s"}}`, `{"metadata":{"ownerReferences":[{"apiVersion":"%s","kind":"%s","name":"%s","uid":"%s","controller":true,"blockOwnerDeletion":true}],"uid":"%s"}}`,
m.controllerKind.GroupVersion(), m.controllerKind.Kind, m.controllerKind.GroupVersion(), m.controllerKind.Kind,
m.controller.GetName(), m.controller.GetUID(), pod.UID) m.Controller.GetName(), m.Controller.GetUID(), pod.UID)
return m.podControl.PatchPod(pod.Namespace, pod.Name, []byte(addControllerPatch)) return m.podControl.PatchPod(pod.Namespace, pod.Name, []byte(addControllerPatch))
} }
@ -238,8 +238,8 @@ func (m *PodControllerRefManager) AdoptPod(pod *v1.Pod) error {
// It returns the error if the patching fails. 404 and 422 errors are ignored. // It returns the error if the patching fails. 404 and 422 errors are ignored.
func (m *PodControllerRefManager) ReleasePod(pod *v1.Pod) error { func (m *PodControllerRefManager) ReleasePod(pod *v1.Pod) error {
glog.V(2).Infof("patching pod %s_%s to remove its controllerRef to %s/%s:%s", glog.V(2).Infof("patching pod %s_%s to remove its controllerRef to %s/%s:%s",
pod.Namespace, pod.Name, m.controllerKind.GroupVersion(), m.controllerKind.Kind, m.controller.GetName()) pod.Namespace, pod.Name, m.controllerKind.GroupVersion(), m.controllerKind.Kind, m.Controller.GetName())
deleteOwnerRefPatch := fmt.Sprintf(`{"metadata":{"ownerReferences":[{"$patch":"delete","uid":"%s"}],"uid":"%s"}}`, m.controller.GetUID(), pod.UID) deleteOwnerRefPatch := fmt.Sprintf(`{"metadata":{"ownerReferences":[{"$patch":"delete","uid":"%s"}],"uid":"%s"}}`, m.Controller.GetUID(), pod.UID)
err := m.podControl.PatchPod(pod.Namespace, pod.Name, []byte(deleteOwnerRefPatch)) err := m.podControl.PatchPod(pod.Namespace, pod.Name, []byte(deleteOwnerRefPatch))
if err != nil { if err != nil {
if errors.IsNotFound(err) { if errors.IsNotFound(err) {
@ -267,7 +267,7 @@ func (m *PodControllerRefManager) ReleasePod(pod *v1.Pod) error {
// categories and accordingly adopt or release them. See comments on these functions // categories and accordingly adopt or release them. See comments on these functions
// for more details. // for more details.
type ReplicaSetControllerRefManager struct { type ReplicaSetControllerRefManager struct {
baseControllerRefManager BaseControllerRefManager
controllerKind schema.GroupVersionKind controllerKind schema.GroupVersionKind
rsControl RSControlInterface rsControl RSControlInterface
} }
@ -275,14 +275,14 @@ type ReplicaSetControllerRefManager struct {
// NewReplicaSetControllerRefManager returns a ReplicaSetControllerRefManager that exposes // NewReplicaSetControllerRefManager returns a ReplicaSetControllerRefManager that exposes
// methods to manage the controllerRef of ReplicaSets. // methods to manage the controllerRef of ReplicaSets.
// //
// The canAdopt() function can be used to perform a potentially expensive check // The CanAdopt() function can be used to perform a potentially expensive check
// (such as a live GET from the API server) prior to the first adoption. // (such as a live GET from the API server) prior to the first adoption.
// It will only be called (at most once) if an adoption is actually attempted. // It will only be called (at most once) if an adoption is actually attempted.
// If canAdopt() returns a non-nil error, all adoptions will fail. // If CanAdopt() returns a non-nil error, all adoptions will fail.
// //
// NOTE: Once canAdopt() is called, it will not be called again by the same // NOTE: Once CanAdopt() is called, it will not be called again by the same
// ReplicaSetControllerRefManager instance. Create a new instance if it // ReplicaSetControllerRefManager instance. Create a new instance if it
// makes sense to check canAdopt() again (e.g. in a different sync pass). // makes sense to check CanAdopt() again (e.g. in a different sync pass).
func NewReplicaSetControllerRefManager( func NewReplicaSetControllerRefManager(
rsControl RSControlInterface, rsControl RSControlInterface,
controller metav1.Object, controller metav1.Object,
@ -291,10 +291,10 @@ func NewReplicaSetControllerRefManager(
canAdopt func() error, canAdopt func() error,
) *ReplicaSetControllerRefManager { ) *ReplicaSetControllerRefManager {
return &ReplicaSetControllerRefManager{ return &ReplicaSetControllerRefManager{
baseControllerRefManager: baseControllerRefManager{ BaseControllerRefManager: BaseControllerRefManager{
controller: controller, Controller: controller,
selector: selector, Selector: selector,
canAdoptFunc: canAdopt, CanAdoptFunc: canAdopt,
}, },
controllerKind: controllerKind, controllerKind: controllerKind,
rsControl: rsControl, rsControl: rsControl,
@ -307,7 +307,7 @@ func NewReplicaSetControllerRefManager(
// * Adopt orphans if the selector matches. // * Adopt orphans if the selector matches.
// * Release owned objects if the selector no longer matches. // * Release owned objects if the selector no longer matches.
// //
// A non-nil error is returned if some form of reconciliation was attemped and // A non-nil error is returned if some form of reconciliation was attempted and
// failed. Usually, controllers should try again later in case reconciliation // failed. Usually, controllers should try again later in case reconciliation
// is still needed. // is still needed.
// //
@ -319,7 +319,7 @@ func (m *ReplicaSetControllerRefManager) ClaimReplicaSets(sets []*extensions.Rep
var errlist []error var errlist []error
match := func(obj metav1.Object) bool { match := func(obj metav1.Object) bool {
return m.selector.Matches(labels.Set(obj.GetLabels())) return m.Selector.Matches(labels.Set(obj.GetLabels()))
} }
adopt := func(obj metav1.Object) error { adopt := func(obj metav1.Object) error {
return m.AdoptReplicaSet(obj.(*extensions.ReplicaSet)) return m.AdoptReplicaSet(obj.(*extensions.ReplicaSet))
@ -329,7 +329,7 @@ func (m *ReplicaSetControllerRefManager) ClaimReplicaSets(sets []*extensions.Rep
} }
for _, rs := range sets { for _, rs := range sets {
ok, err := m.claimObject(rs, match, adopt, release) ok, err := m.ClaimObject(rs, match, adopt, release)
if err != nil { if err != nil {
errlist = append(errlist, err) errlist = append(errlist, err)
continue continue
@ -344,7 +344,7 @@ func (m *ReplicaSetControllerRefManager) ClaimReplicaSets(sets []*extensions.Rep
// AdoptReplicaSet sends a patch to take control of the ReplicaSet. It returns // AdoptReplicaSet sends a patch to take control of the ReplicaSet. It returns
// the error if the patching fails. // the error if the patching fails.
func (m *ReplicaSetControllerRefManager) AdoptReplicaSet(rs *extensions.ReplicaSet) error { func (m *ReplicaSetControllerRefManager) AdoptReplicaSet(rs *extensions.ReplicaSet) error {
if err := m.canAdopt(); err != nil { if err := m.CanAdopt(); err != nil {
return fmt.Errorf("can't adopt ReplicaSet %v/%v (%v): %v", rs.Namespace, rs.Name, rs.UID, err) return fmt.Errorf("can't adopt ReplicaSet %v/%v (%v): %v", rs.Namespace, rs.Name, rs.UID, err)
} }
// Note that ValidateOwnerReferences() will reject this patch if another // Note that ValidateOwnerReferences() will reject this patch if another
@ -352,7 +352,7 @@ func (m *ReplicaSetControllerRefManager) AdoptReplicaSet(rs *extensions.ReplicaS
addControllerPatch := fmt.Sprintf( addControllerPatch := fmt.Sprintf(
`{"metadata":{"ownerReferences":[{"apiVersion":"%s","kind":"%s","name":"%s","uid":"%s","controller":true,"blockOwnerDeletion":true}],"uid":"%s"}}`, `{"metadata":{"ownerReferences":[{"apiVersion":"%s","kind":"%s","name":"%s","uid":"%s","controller":true,"blockOwnerDeletion":true}],"uid":"%s"}}`,
m.controllerKind.GroupVersion(), m.controllerKind.Kind, m.controllerKind.GroupVersion(), m.controllerKind.Kind,
m.controller.GetName(), m.controller.GetUID(), rs.UID) m.Controller.GetName(), m.Controller.GetUID(), rs.UID)
return m.rsControl.PatchReplicaSet(rs.Namespace, rs.Name, []byte(addControllerPatch)) return m.rsControl.PatchReplicaSet(rs.Namespace, rs.Name, []byte(addControllerPatch))
} }
@ -360,8 +360,8 @@ func (m *ReplicaSetControllerRefManager) AdoptReplicaSet(rs *extensions.ReplicaS
// It returns the error if the patching fails. 404 and 422 errors are ignored. // It returns the error if the patching fails. 404 and 422 errors are ignored.
func (m *ReplicaSetControllerRefManager) ReleaseReplicaSet(replicaSet *extensions.ReplicaSet) error { func (m *ReplicaSetControllerRefManager) ReleaseReplicaSet(replicaSet *extensions.ReplicaSet) error {
glog.V(2).Infof("patching ReplicaSet %s_%s to remove its controllerRef to %s/%s:%s", glog.V(2).Infof("patching ReplicaSet %s_%s to remove its controllerRef to %s/%s:%s",
replicaSet.Namespace, replicaSet.Name, m.controllerKind.GroupVersion(), m.controllerKind.Kind, m.controller.GetName()) replicaSet.Namespace, replicaSet.Name, m.controllerKind.GroupVersion(), m.controllerKind.Kind, m.Controller.GetName())
deleteOwnerRefPatch := fmt.Sprintf(`{"metadata":{"ownerReferences":[{"$patch":"delete","uid":"%s"}],"uid":"%s"}}`, m.controller.GetUID(), replicaSet.UID) deleteOwnerRefPatch := fmt.Sprintf(`{"metadata":{"ownerReferences":[{"$patch":"delete","uid":"%s"}],"uid":"%s"}}`, m.Controller.GetUID(), replicaSet.UID)
err := m.rsControl.PatchReplicaSet(replicaSet.Namespace, replicaSet.Name, []byte(deleteOwnerRefPatch)) err := m.rsControl.PatchReplicaSet(replicaSet.Namespace, replicaSet.Name, []byte(deleteOwnerRefPatch))
if err != nil { if err != nil {
if errors.IsNotFound(err) { if errors.IsNotFound(err) {
@ -379,9 +379,9 @@ func (m *ReplicaSetControllerRefManager) ReleaseReplicaSet(replicaSet *extension
return err return err
} }
// RecheckDeletionTimestamp returns a canAdopt() function to recheck deletion. // RecheckDeletionTimestamp returns a CanAdopt() function to recheck deletion.
// //
// The canAdopt() function calls getObject() to fetch the latest value, // The CanAdopt() function calls getObject() to fetch the latest value,
// and denies adoption attempts if that object has a non-nil DeletionTimestamp. // and denies adoption attempts if that object has a non-nil DeletionTimestamp.
func RecheckDeletionTimestamp(getObject func() (metav1.Object, error)) func() error { func RecheckDeletionTimestamp(getObject func() (metav1.Object, error)) func() error {
return func() error { return func() error {
@ -402,7 +402,7 @@ func RecheckDeletionTimestamp(getObject func() (metav1.Object, error)) func() er
// categories and accordingly adopt or release them. See comments on these functions // categories and accordingly adopt or release them. See comments on these functions
// for more details. // for more details.
type ControllerRevisionControllerRefManager struct { type ControllerRevisionControllerRefManager struct {
baseControllerRefManager BaseControllerRefManager
controllerKind schema.GroupVersionKind controllerKind schema.GroupVersionKind
crControl ControllerRevisionControlInterface crControl ControllerRevisionControlInterface
} }
@ -426,10 +426,10 @@ func NewControllerRevisionControllerRefManager(
canAdopt func() error, canAdopt func() error,
) *ControllerRevisionControllerRefManager { ) *ControllerRevisionControllerRefManager {
return &ControllerRevisionControllerRefManager{ return &ControllerRevisionControllerRefManager{
baseControllerRefManager: baseControllerRefManager{ BaseControllerRefManager: BaseControllerRefManager{
controller: controller, Controller: controller,
selector: selector, Selector: selector,
canAdoptFunc: canAdopt, CanAdoptFunc: canAdopt,
}, },
controllerKind: controllerKind, controllerKind: controllerKind,
crControl: crControl, crControl: crControl,
@ -454,7 +454,7 @@ func (m *ControllerRevisionControllerRefManager) ClaimControllerRevisions(histor
var errlist []error var errlist []error
match := func(obj metav1.Object) bool { match := func(obj metav1.Object) bool {
return m.selector.Matches(labels.Set(obj.GetLabels())) return m.Selector.Matches(labels.Set(obj.GetLabels()))
} }
adopt := func(obj metav1.Object) error { adopt := func(obj metav1.Object) error {
return m.AdoptControllerRevision(obj.(*appsv1beta1.ControllerRevision)) return m.AdoptControllerRevision(obj.(*appsv1beta1.ControllerRevision))
@ -464,7 +464,7 @@ func (m *ControllerRevisionControllerRefManager) ClaimControllerRevisions(histor
} }
for _, h := range histories { for _, h := range histories {
ok, err := m.claimObject(h, match, adopt, release) ok, err := m.ClaimObject(h, match, adopt, release)
if err != nil { if err != nil {
errlist = append(errlist, err) errlist = append(errlist, err)
continue continue
@ -479,7 +479,7 @@ func (m *ControllerRevisionControllerRefManager) ClaimControllerRevisions(histor
// AdoptControllerRevision sends a patch to take control of the ControllerRevision. It returns the error if // AdoptControllerRevision sends a patch to take control of the ControllerRevision. It returns the error if
// the patching fails. // the patching fails.
func (m *ControllerRevisionControllerRefManager) AdoptControllerRevision(history *appsv1beta1.ControllerRevision) error { func (m *ControllerRevisionControllerRefManager) AdoptControllerRevision(history *appsv1beta1.ControllerRevision) error {
if err := m.canAdopt(); err != nil { if err := m.CanAdopt(); err != nil {
return fmt.Errorf("can't adopt ControllerRevision %v/%v (%v): %v", history.Namespace, history.Name, history.UID, err) return fmt.Errorf("can't adopt ControllerRevision %v/%v (%v): %v", history.Namespace, history.Name, history.UID, err)
} }
// Note that ValidateOwnerReferences() will reject this patch if another // Note that ValidateOwnerReferences() will reject this patch if another
@ -487,7 +487,7 @@ func (m *ControllerRevisionControllerRefManager) AdoptControllerRevision(history
addControllerPatch := fmt.Sprintf( addControllerPatch := fmt.Sprintf(
`{"metadata":{"ownerReferences":[{"apiVersion":"%s","kind":"%s","name":"%s","uid":"%s","controller":true,"blockOwnerDeletion":true}],"uid":"%s"}}`, `{"metadata":{"ownerReferences":[{"apiVersion":"%s","kind":"%s","name":"%s","uid":"%s","controller":true,"blockOwnerDeletion":true}],"uid":"%s"}}`,
m.controllerKind.GroupVersion(), m.controllerKind.Kind, m.controllerKind.GroupVersion(), m.controllerKind.Kind,
m.controller.GetName(), m.controller.GetUID(), history.UID) m.Controller.GetName(), m.Controller.GetUID(), history.UID)
return m.crControl.PatchControllerRevision(history.Namespace, history.Name, []byte(addControllerPatch)) return m.crControl.PatchControllerRevision(history.Namespace, history.Name, []byte(addControllerPatch))
} }
@ -495,8 +495,8 @@ func (m *ControllerRevisionControllerRefManager) AdoptControllerRevision(history
// It returns the error if the patching fails. 404 and 422 errors are ignored. // It returns the error if the patching fails. 404 and 422 errors are ignored.
func (m *ControllerRevisionControllerRefManager) ReleaseControllerRevision(history *appsv1beta1.ControllerRevision) error { func (m *ControllerRevisionControllerRefManager) ReleaseControllerRevision(history *appsv1beta1.ControllerRevision) error {
glog.V(2).Infof("patching ControllerRevision %s_%s to remove its controllerRef to %s/%s:%s", glog.V(2).Infof("patching ControllerRevision %s_%s to remove its controllerRef to %s/%s:%s",
history.Namespace, history.Name, m.controllerKind.GroupVersion(), m.controllerKind.Kind, m.controller.GetName()) history.Namespace, history.Name, m.controllerKind.GroupVersion(), m.controllerKind.Kind, m.Controller.GetName())
deleteOwnerRefPatch := fmt.Sprintf(`{"metadata":{"ownerReferences":[{"$patch":"delete","uid":"%s"}],"uid":"%s"}}`, m.controller.GetUID(), history.UID) deleteOwnerRefPatch := fmt.Sprintf(`{"metadata":{"ownerReferences":[{"$patch":"delete","uid":"%s"}],"uid":"%s"}}`, m.Controller.GetUID(), history.UID)
err := m.crControl.PatchControllerRevision(history.Namespace, history.Name, []byte(deleteOwnerRefPatch)) err := m.crControl.PatchControllerRevision(history.Namespace, history.Name, []byte(deleteOwnerRefPatch))
if err != nil { if err != nil {
if errors.IsNotFound(err) { if errors.IsNotFound(err) {