Skip to content

Commit

Permalink
Fix backend part of compositionRef missing
Browse files Browse the repository at this point in the history
  • Loading branch information
undera committed Sep 19, 2023
1 parent b662bc8 commit ed14e59
Showing 1 changed file with 16 additions and 13 deletions.
29 changes: 16 additions & 13 deletions pkg/backend/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit ed14e59

Please sign in to comment.