gitrepo: Ignore patch error not found on delete
While deleting, patching an object with new status results in "not found" error because the object is already deleted. The patching operation first patches the status conditions, the rest of the object and, at the very end, the rest of the status. When an object is deleted, the garbage collection results in the artifact in the status to be updated, resulting in a diff that is attempted to be patched when the deferred patch runs. Since the status patching runs at the very end, the object gets deleted before it can be patched. Ignore "not found" error while patching when the delete timestamp is set. Signed-off-by: Sunny <darkowlzz@protonmail.com>
This commit is contained in:
parent
160432c022
commit
ea45903dd4
|
@ -25,6 +25,7 @@ import (
|
||||||
|
|
||||||
securejoin "github.com/cyphar/filepath-securejoin"
|
securejoin "github.com/cyphar/filepath-securejoin"
|
||||||
corev1 "k8s.io/api/core/v1"
|
corev1 "k8s.io/api/core/v1"
|
||||||
|
apierrors "k8s.io/apimachinery/pkg/api/errors"
|
||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
"k8s.io/apimachinery/pkg/types"
|
"k8s.io/apimachinery/pkg/types"
|
||||||
kerrors "k8s.io/apimachinery/pkg/util/errors"
|
kerrors "k8s.io/apimachinery/pkg/util/errors"
|
||||||
|
@ -172,6 +173,10 @@ func (r *GitRepositoryReconciler) Reconcile(ctx context.Context, req ctrl.Reques
|
||||||
|
|
||||||
// Finally, patch the resource
|
// Finally, patch the resource
|
||||||
if err := patchHelper.Patch(ctx, obj, patchOpts...); err != nil {
|
if err := patchHelper.Patch(ctx, obj, patchOpts...); err != nil {
|
||||||
|
// Ignore patch error "not found" when the object is being deleted.
|
||||||
|
if !obj.ObjectMeta.DeletionTimestamp.IsZero() {
|
||||||
|
err = kerrors.FilterOut(err, func(e error) bool { return apierrors.IsNotFound(e) })
|
||||||
|
}
|
||||||
retErr = kerrors.NewAggregate([]error{retErr, err})
|
retErr = kerrors.NewAggregate([]error{retErr, err})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue