Reallow name, namepsace, generated-name of a composed to be patched

Signed-off-by: Alper Rifat Ulucinar <ulucinar@users.noreply.github.com>
This commit is contained in:
Alper Rifat Ulucinar 2021-07-06 16:53:24 +03:00
parent 0d4427da14
commit ff60580885
No known key found for this signature in database
GPG Key ID: 22768248C8BB2D41
1 changed files with 7 additions and 7 deletions

View File

@ -336,6 +336,13 @@ func (r *APIDryRunRenderer) Render(ctx context.Context, cp resource.Composite, c
return errors.New(errNamePrefix)
}
// Unmarshalling the template will overwrite any existing fields, so we must
// restore the existing name, if any. We also set generate name in case we
// haven't yet named this composed resource.
cd.SetGenerateName(cp.GetLabels()[xcrd.LabelKeyNamePrefixForComposed] + "-")
cd.SetName(name)
cd.SetNamespace(namespace)
onlyPatches := []v1.PatchType{v1.PatchTypeFromCompositeFieldPath, v1.PatchTypeCombineFromComposite}
for i, p := range t.Patches {
if err := p.Apply(cp, cd, onlyPatches...); err != nil {
@ -354,13 +361,6 @@ func (r *APIDryRunRenderer) Render(ctx context.Context, cp resource.Composite, c
SetCompositionResourceName(cd, *t.Name)
}
// Unmarshalling the template will overwrite any existing fields, so we must
// restore the existing name, if any. We also set generate name in case we
// haven't yet named this composed resource.
cd.SetGenerateName(cp.GetLabels()[xcrd.LabelKeyNamePrefixForComposed] + "-")
cd.SetName(name)
cd.SetNamespace(namespace)
// We do this last to ensure that a Composition cannot influence owner (and
// especially controller) references.
or := meta.AsController(meta.TypedReferenceTo(cp, cp.GetObjectKind().GroupVersionKind()))