Skip to content

Commit

Permalink
Merge pull request #112 from lsviben/sync-upstream-release-1.14
Browse files Browse the repository at this point in the history
Sync upstream release 1.14 to v1.14.3
  • Loading branch information
lsviben authored Nov 24, 2023
2 parents c6425f0 + 092aac7 commit 5f05657
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 31 deletions.
14 changes: 13 additions & 1 deletion cmd/crank/beta/trace/internal/resource/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ func getResourceChildrenRefs(r *Resource, getConnectionSecrets bool) []v1.Object
return nil
}

if obj.GetNamespace() != "" {
if xrcNamespace := obj.GetNamespace(); xrcNamespace != "" {
// This is an XRC, get the XR ref, we leave the connection secret
// handling to the XR
xrc := claim.Unstructured{Unstructured: obj}
Expand All @@ -145,6 +145,18 @@ func getResourceChildrenRefs(r *Resource, getConnectionSecrets bool) []v1.Object
Namespace: ref.Namespace,
})
}
if getConnectionSecrets {
xrcSecretRef := xrc.GetWriteConnectionSecretToReference()
if xrcSecretRef != nil {
ref := v1.ObjectReference{
APIVersion: "v1",
Kind: "Secret",
Name: xrcSecretRef.Name,
Namespace: xrcNamespace,
}
refs = append(refs, ref)
}
}
return refs
}
// This could be an XR or an MR
Expand Down
6 changes: 6 additions & 0 deletions cmd/crank/beta/trace/internal/resource/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,12 @@ func TestGetResourceChildrenRefs(t *testing.T) {
},
want: want{
refs: []v1.ObjectReference{
{
APIVersion: "v1",
Kind: "Secret",
Namespace: "ns-1",
Name: "secret-1",
},
{
APIVersion: "example.com/v1",
Kind: "XR",
Expand Down
24 changes: 9 additions & 15 deletions internal/controller/apiextensions/composite/composition_pt.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,14 @@ const (
errFetchDetails = "cannot fetch connection details"
errInline = "cannot inline Composition patch sets"

errFmtPatchEnvironment = "cannot apply environment patch at index %d"
errFmtParseBase = "cannot parse base template of composed resource %q"
errFmtRenderFromCompositePatches = "cannot render FromComposite patches for composed resource %q"
errFmtRenderToCompositePatches = "cannot render ToComposite patches for composed resource %q"
errFmtRenderFromEnvironmentPatches = "cannot render FromEnvironment patches for composed resource %q"
errFmtRenderMetadata = "cannot render metadata for composed resource %q"
errFmtGenerateName = "cannot generate a name for composed resource %q"
errFmtExtractDetails = "cannot extract composite resource connection details from composed resource %q"
errFmtCheckReadiness = "cannot check whether composed resource %q is ready"
errFmtPatchEnvironment = "cannot apply environment patch at index %d"
errFmtParseBase = "cannot parse base template of composed resource %q"
errFmtRenderFromCompositePatches = "cannot render FromComposite or environment patches for composed resource %q"
errFmtRenderToCompositePatches = "cannot render ToComposite patches for composed resource %q"
errFmtRenderMetadata = "cannot render metadata for composed resource %q"
errFmtGenerateName = "cannot generate a name for composed resource %q"
errFmtExtractDetails = "cannot extract composite resource connection details from composed resource %q"
errFmtCheckReadiness = "cannot check whether composed resource %q is ready"
)

// TODO(negz): Move P&T Composition logic into its own package?
Expand Down Expand Up @@ -217,16 +216,11 @@ func (c *PTComposer) Compose(ctx context.Context, xr *composite.Unstructured, re
// unblock it.

rendered := true
if err := RenderFromCompositePatches(r, xr, ta.Template.Patches); err != nil {
if err := RenderFromCompositeAndEnvironmentPatches(r, xr, req.Environment, ta.Template.Patches); err != nil {
events = append(events, event.Warning(reasonCompose, errors.Wrapf(err, errFmtRenderFromCompositePatches, name)))
rendered = false
}

if err = RenderToAndFromEnvironmentPatches(r, req.Environment, ta.Template.Patches); err != nil {
events = append(events, event.Warning(reasonCompose, errors.Wrapf(err, errFmtRenderFromEnvironmentPatches, name)))
rendered = false
}

if err := RenderComposedResourceMetadata(r, xr, ResourceName(ptr.Deref(ta.Template.Name, ""))); err != nil {
events = append(events, event.Warning(reasonCompose, errors.Wrapf(err, errFmtRenderMetadata, name)))
rendered = false
Expand Down
23 changes: 8 additions & 15 deletions internal/controller/apiextensions/composite/composition_render.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,26 +80,19 @@ func RenderFromJSON(o resource.Object, data []byte) error {
return nil
}

// RenderFromCompositePatches renders the supplied composed resource by applying
// all patches that are _from_ the supplied composite resource.
func RenderFromCompositePatches(cd resource.Composed, xr resource.Composite, p []v1.Patch) error {
// RenderFromCompositeAndEnvironmentPatches renders the supplied composed
// resource by applying all patches that are _from_ the supplied composite
// resource or are from or to the supplied environment.
func RenderFromCompositeAndEnvironmentPatches(cd resource.Composed, xr resource.Composite, e *Environment, p []v1.Patch) error {
for i := range p {
if err := Apply(p[i], xr, cd, patchTypesFromXR()...); err != nil {
return errors.Wrapf(err, errFmtPatch, p[i].Type, i)
}
}
return nil
}

// RenderToAndFromEnvironmentPatches renders the supplied composed resource by
// applying all patches that are from or to the supplied environment.
func RenderToAndFromEnvironmentPatches(cd resource.Composed, e *Environment, p []v1.Patch) error {
if e == nil {
return nil
}
for i := range p {
if err := ApplyToObjects(p[i], e, cd, patchTypesFromToEnvironment()...); err != nil {
return errors.Wrapf(err, errFmtPatch, p[i].Type, i)
if e != nil {
if err := ApplyToObjects(p[i], e, cd, patchTypesFromToEnvironment()...); err != nil {
return errors.Wrapf(err, errFmtPatch, p[i].Type, i)
}
}
}
return nil
Expand Down

0 comments on commit 5f05657

Please sign in to comment.