From a5aec2bc26075eea6224f3d9317e675249681df4 Mon Sep 17 00:00:00 2001 From: Simon Beck Date: Tue, 19 Nov 2024 12:53:15 +0100 Subject: [PATCH] Use a default client if controlPanel client is nil XObjectBuckets and mysql provder-sql objects did not have a valid cpClient specified. This causes nilpointers if any of these should get deleted. Resulting in errors like these: ``` Error from server (InternalError): Internal error occurred: failed calling webhook "users.mysql.vshn.appcat.vshn.io": failed to call webhook: Post "https://webhook-service.syn-appcat.svc:443/validate-mysql-sql-crossplane-io-v1alpha1-user?timeout=10s": EOF ``` These are Crossplane managed resources and always reside on the control plane. So they will always have the same clients for local and control plane connections. If the cpClient isn't specified we default to the other client. This change will make it easier in the future to add managed resources as we don't have to specify both clients seperately (and potentially forget them...). --- pkg/controller/webhooks/deletionprotection.go | 8 ++++++++ 1 file changed, 8 insertions(+) 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) {