Skip to content

Commit

Permalink
Merge pull request #267 from vshn/fix/deletion-protection-nilpointer
Browse files Browse the repository at this point in the history
Use a default client if controlPanel client is nil
  • Loading branch information
Kidswiss authored Nov 19, 2024
2 parents 5fe18eb + a5aec2b commit c465c54
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions pkg/controller/webhooks/deletionprotection.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit c465c54

Please sign in to comment.