late initializing some xrc fields from the xr

Signed-off-by: RinkiyaKeDad <arshsharma461@gmail.com>
This commit is contained in:
RinkiyaKeDad 2021-10-27 19:35:52 +05:30
parent f9c9dc0324
commit 9fa38e265b
2 changed files with 16 additions and 6 deletions

View File

@ -200,13 +200,19 @@ func (c *APIClaimConfigurator) Configure(ctx context.Context, cm resource.Compos
meta.SetExternalName(cm, en)
}
// TODO(negz): Is the srcFilter below responsible for the XR's
// compositionRef not being propagated back to the claim per
// https://github.com/crossplane/crossplane/issues/2263 ?
if err := merge(ucm.Object["spec"], ucp.Object["spec"],
withSrcFilter(xcrd.GetPropFields(xcrd.CompositeResourceSpecProps())...)); err != nil {
return errors.Wrap(err, errMergeClaimSpec)
// We want to propagate the composite's spec to the claim's spec, but
// first we must filter out any well-known fields that are unique to
// composites. We do this by:
// 1. Grabbing a map whose keys represent all well-known composite fields.
// 2. Deleting any well-known fields that we want to propagate.
// 3. Filtering OUT the remaining map keys from the composite's spec so
// that we end up adding only the well-known fields to the claim's spec.
wellKnownCompositeFields := xcrd.CompositeResourceSpecProps()
for _, field := range xcrd.PropagateCompositeSpecProps {
delete(wellKnownCompositeFields, field)
}
compositeSpecFilter := xcrd.GetPropFields(wellKnownCompositeFields)
ucm.Object["spec"] = filter(ucp.Object["spec"].(map[string]interface{}), compositeSpecFilter...)
return errors.Wrap(c.client.Update(ctx, cm), errUpdateClaim)
}

View File

@ -29,6 +29,10 @@ const (
// when translating an XRC into an XR.
var PropagateClaimSpecProps = []string{"compositionRef", "compositionSelector", "compositionRevisionRef", "compositionUpdatePolicy"}
// PropagateCompositeSpecProps is the list of XR spec properties to propagate
// when translating an XR into an XRC.
var PropagateCompositeSpecProps = []string{"compositionRef", "compositionSelector"}
// TODO(negz): Add descriptions to schema fields.
// BaseProps is a partial OpenAPIV3Schema for the spec fields that Crossplane