@@ -36,7 +36,6 @@ import (
3636 apierrors "k8s.io/apimachinery/pkg/api/errors"
3737 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
3838 "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
39- "k8s.io/apimachinery/pkg/runtime/schema"
4039 "k8s.io/apimachinery/pkg/types"
4140 ctrlruntimeclient "sigs.k8s.io/controller-runtime/pkg/client"
4241)
@@ -425,11 +424,16 @@ func resolveRelatedResourceObjectsInNamespace(ctx context.Context, relatedOrigin
425424 return mapSlices (originNames , destNames ), nil
426425
427426 case spec .Selector != nil :
428- apiVersion := schema.GroupVersion {Group : relRes .Group , Version : relRes .Version }.String ()
427+ originGVR := projection .RelatedResourceGVR (& relRes )
428+
429+ originGVK , err := relatedOrigin .client .RESTMapper ().KindFor (originGVR )
430+ if err != nil {
431+ return nil , fmt .Errorf ("failed to lookup %v: %w" , originGVR , err )
432+ }
429433
430434 originObjects := & unstructured.UnstructuredList {}
431- originObjects .SetAPIVersion (apiVersion )
432- originObjects .SetKind (relRes .Kind )
435+ originObjects .SetAPIVersion (originGVK . GroupVersion (). String () )
436+ originObjects .SetKind (originGVK .Kind )
433437
434438 labelSelector , err := templateLabelSelector (relatedOrigin , relatedDest , relRes .Origin , & spec .Selector .LabelSelector )
435439 if err != nil {
0 commit comments