diff --git a/pkg/controller/webhooks/deletionprotection.go b/pkg/controller/webhooks/deletionprotection.go index 7a181d4a33..66fb3c79c1 100644 --- a/pkg/controller/webhooks/deletionprotection.go +++ b/pkg/controller/webhooks/deletionprotection.go @@ -44,6 +44,10 @@ type DeletionProtectionInfo interface { // Anything that either contains an owner reference to a composite or an owner annotation. func checkManagedObject(ctx context.Context, obj client.Object, c client.Client, cpClient client.Client, l logr.Logger) (compositeInfo, error) { + if cpClient == nil { + cpClient = c + } + ownerKind, ok := obj.GetLabels()[runtime.OwnerKindAnnotation] if !ok || ownerKind == "" { l.Info(runtime.OwnerKindAnnotation + " label not set, skipping evaluation") @@ -116,6 +120,10 @@ func checkManagedObject(ctx context.Context, obj client.Object, c client.Client, func checkUnmanagedObject(ctx context.Context, obj client.Object, c client.Client, cpClient client.Client, l logr.Logger) (compositeInfo, error) { namespace := &corev1.Namespace{} + if cpClient == nil { + cpClient = c + } + err := cpClient.Get(ctx, client.ObjectKey{Name: obj.GetNamespace()}, namespace) if err != nil { if apierrors.IsNotFound(err) {