Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 69 additions & 0 deletions cmd/crossplane/composition/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2001,6 +2001,75 @@ Summary: 1 modified`,
ExpectedExitCode: dp.ExitCodeDiffDetected,
NoColor: true,
},
"NestedXRUsesRunComposition": {
Reason: "Validates that a nested XR whose Composition is in the run renders with the run's, not the cluster's",
SetupFiles: []string{
"../../../internal/testutils/integration/testdata/comp/resources/xrd.yaml",
"../../../internal/testutils/integration/testdata/comp/resources/original-composition.yaml",
"../../../internal/testutils/integration/testdata/comp/resources/functions.yaml",
"testdata/comp/resources/nested-xr/parent-xrd.yaml",
"testdata/comp/resources/nested-xr/parent-composition.yaml",
},
CrossplaneManagedResources: []integration.HierarchicalOwnershipRelation{
{
OwnerFile: "testdata/comp/resources/nested-xr/existing-parent-xr.yaml",
OwnedFiles: map[string]*integration.HierarchicalOwnershipRelation{
"testdata/comp/resources/nested-xr/existing-parent-direct-downstream.yaml": nil,
"testdata/comp/resources/nested-xr/existing-nested-child-xr.yaml": {
OwnedFiles: map[string]*integration.HierarchicalOwnershipRelation{
"testdata/comp/resources/nested-xr/existing-child-downstream.yaml": nil,
},
},
},
},
},
// Both the parent's and the child's Compositions change.
InputFiles: []string{"testdata/comp/updated-parent-composition.yaml", "../../../internal/testutils/integration/testdata/comp/updated-composition.yaml"},
Namespace: "default",
// Under the parent, the nested XR's downstream is rendered with the run's child Composition, so
// it shows the same change as under the nested XR's own entry.
ExpectedOutput: `=== Impact Analysis ===

~~~ XDownstreamResource/test-parent-direct
apiVersion: ns.nop.example.org/v1alpha1
kind: XDownstreamResource
metadata:
annotations:
crossplane.io/composition-resource-name: direct-resource
labels:
crossplane.io/composite: test-parent
name: test-parent-direct
namespace: default
spec:
forProvider:
configData: parent-parent-value
- resourceTier: parent-tier
+ resourceTier: premium-tier

---
~~~ XDownstreamResource/test-parent-nested
apiVersion: ns.nop.example.org/v1alpha1
kind: XDownstreamResource
metadata:
annotations:
crossplane.io/composition-resource-name: nop-resource
labels:
crossplane.io/composite: test-parent
name: test-parent-nested
namespace: default
spec:
forProvider:
- configData: child-config-value
- resourceTier: basic
+ configData: updated-child-config-value
+ resourceTier: premium

---

Summary: 2 modified`,
ExpectedExitCode: dp.ExitCodeDiffDetected,
NoColor: true,
},
"CrossNamespaceResourceCollision": {
Reason: "Validates that resources with the same name in different namespaces are correctly distinguished",
Skip: true,
Expand Down
8 changes: 8 additions & 0 deletions internal/diff/client/crossplane/revision_selector.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,14 @@ func XRCompositionRevisionRef(obj map[string]any, apiVersion string) (string, er
return name, err
}

// XRCompositionRef reads the name in an XR/Claim's compositionRef, checking the paths XRUpdatePolicy
// does. Empty when the ref is unset. A non-nil error means the field is present but malformed (not a
// string).
func XRCompositionRef(obj map[string]any, apiVersion string) (string, error) {
name, _, err := nestedCrossplaneString(obj, apiVersion, "compositionRef", "name")
return name, err
}

// labelSelectorFromUnstructuredMap converts an unstructured compositionRevisionSelector map (as
// stored on an XR spec) into a typed metav1.LabelSelector via runtime conversion.
func labelSelectorFromUnstructuredMap(m map[string]any) (*metav1.LabelSelector, error) {
Expand Down
Loading
Loading