From 6077b10f3fb886d867d0ef1a15541e48d3b93580 Mon Sep 17 00:00:00 2001 From: Rasheed Abdul-Aziz Date: Thu, 2 Nov 2023 18:44:38 -0400 Subject: [PATCH] duck type support for builder calls - still need to deal with client.Create not working --- reconcilers/child.go | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/reconcilers/child.go b/reconcilers/child.go index df69784..6f02ab6 100644 --- a/reconcilers/child.go +++ b/reconcilers/child.go @@ -13,9 +13,12 @@ import ( "sync" "github.com/go-logr/logr" + "github.com/vmware-labs/reconciler-runtime/duck" corev1 "k8s.io/api/core/v1" apierrs "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" + "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/types" ctrl "sigs.k8s.io/controller-runtime" "sigs.k8s.io/controller-runtime/pkg/builder" @@ -197,10 +200,24 @@ func (r *ChildReconciler[T, CT, CLT]) SetupWithManager(ctx context.Context, mgr return err } - if r.SkipOwnerReference { - bldr.Watches(r.ChildType, EnqueueTracked(ctx)) + if duck.IsDuck(r.ChildType, c.Scheme()) { + uns, err := runtime.DefaultUnstructuredConverter.ToUnstructured(r.ChildType) + if err != nil { + return err + } + funs := &unstructured.Unstructured{Object: uns} + if r.SkipOwnerReference { + bldr.Watches(funs, EnqueueTracked(ctx)) + } else { + bldr.Owns(funs) + } + } else { - bldr.Owns(r.ChildType) + if r.SkipOwnerReference { + bldr.Watches(r.ChildType, EnqueueTracked(ctx)) + } else { + bldr.Owns(r.ChildType) + } } if r.Setup == nil {