From ed14e594c2dfabad95151796ee4d6e84194f08a5 Mon Sep 17 00:00:00 2001 From: Andrei Pohilko Date: Tue, 19 Sep 2023 15:54:34 +0100 Subject: [PATCH] Fix backend part of compositionRef missing --- pkg/backend/controller.go | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/pkg/backend/controller.go b/pkg/backend/controller.go index 75501e0..6ecadf8 100644 --- a/pkg/backend/controller.go +++ b/pkg/backend/controller.go @@ -18,6 +18,7 @@ import ( apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/client/clientset/clientset/typed/apiextensions/v1" 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/runtime/schema" "k8s.io/client-go/rest" "k8s.io/client-go/tools/clientcmd" @@ -48,6 +49,11 @@ type ConditionedObject interface { resource.Conditioned } +type UnstructuredWithCompositionRef interface { + runtime.Unstructured + resource.CompositionReferencer +} + type ManagedUnstructured struct { // no dedicated type for it in base CP, just resource.Managed interface uxres.Unstructured } @@ -265,15 +271,19 @@ func (c *Controller) GetClaim(ec echo.Context) error { return err } - compRef := claim.GetCompositionReference() - compRef.SetGroupVersionKind(cpext.CompositionGroupVersionKind) + c.fillCompositionByRef(claim) + } + return ec.JSONPretty(http.StatusOK, claim.Object, " ") +} +func (c *Controller) fillCompositionByRef(obj UnstructuredWithCompositionRef) { + compRef := obj.GetCompositionReference() + if compRef != nil { + compRef.SetGroupVersionKind(cpext.CompositionGroupVersionKind) comp := uxres.New() _ = c.getDynamicResource(compRef, comp) - claim.Object["composition"] = comp - + obj.UnstructuredContent()["composition"] = comp } - return ec.JSONPretty(http.StatusOK, claim.Object, " ") } func (c *Controller) getDynamicResource(ref *v12.ObjectReference, res ConditionedObject) (err error) { @@ -500,14 +510,7 @@ func (c *Controller) GetComposite(ec echo.Context) error { } } - // composition ref - compRef := xr.GetCompositionReference() - if compRef != nil { - compRef.SetGroupVersionKind(cpext.CompositionGroupVersionKind) - comp := uxres.New() - _ = c.getDynamicResource(compRef, comp) - xr.Object["composition"] = comp - } + c.fillCompositionByRef(xr) // MR refs err = c.fillManagedResources(ec, xr)