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
20 changes: 20 additions & 0 deletions cmd/crossplane/composition/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2511,6 +2511,26 @@ Summary: 2 modified`,
WithCompositionModified().
WithXRImpact("XNopResource", "selector-match-resource", "default", "changed"),
},
// A Manual XR that names no revision yet is not pinned: Crossplane gives it the latest revision,
// the one this composition produces, so it is evaluated like an Automatic one, not deferred.
"ManualXRWithoutRevisionRefIsEvaluated": {
Reason: "--resource matching a Manual-policy composite with no compositionRevisionRef evaluates it against the new composition, ignoring a compositionRevisionSelector that rejects it, and counts it as re-pointing instead of marking it filtered",
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/existing-xr-manual-without-revision-ref.yaml",
},
InputFiles: []string{"testdata/comp/updated-composition-labeled.yaml"},
Resources: []string{"default/manual-unpinned-resource"},
OutputFormat: "json",
ExpectedExitCode: dp.ExitCodeDiffDetected,
ExpectedStructured: simtest.Expect().
WithComposition("xnopresources.diff.example.org").
WithCompositionModified().
WithRevisionImpact("spec", true, 1).
WithXRImpact("XNopResource", "manual-unpinned-resource", "default", "changed"),
},
}

for name, tt := range tests {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# A Manual XR that names no compositionRevisionRef yet, as one has before Crossplane first reconciles
# it. Crossplane pins a Manual XR only once it names a revision; until then it gives the XR the latest
# revision and writes the ref (crossplane v2.4.3 internal/controller/apiextensions/composite/
# api.go:163-189). The selector is there only so the fixture loader leaves the ref unset (it derives a
# ref for an XR naming neither). It deliberately rejects the diffed composition's labels
# (version: 0.0.2): Crossplane ignores a selector under Manual (api.go:203), so the XR is still
# evaluated and re-points.
apiVersion: ns.diff.example.org/v1alpha1
kind: XNopResource
metadata:
name: manual-unpinned-resource
namespace: default
spec:
coolField: manual-unpinned-existing-value
crossplane:
compositionRef:
name: xnopresources.diff.example.org
compositionUpdatePolicy: Manual
compositionRevisionSelector:
matchLabels:
version: 0.0.1
160 changes: 126 additions & 34 deletions internal/diff/diffprocessor/comp_processor.go

Large diffs are not rendered by default.

328 changes: 297 additions & 31 deletions internal/diff/diffprocessor/comp_processor_test.go

Large diffs are not rendered by default.

28 changes: 19 additions & 9 deletions internal/diff/result/comp.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ type FilterReason string

const (
// FilterReasonManualPolicy indicates the XR was excluded because it has a Manual
// compositionUpdatePolicy and --include-pinned was not set. Such XRs are pinned to a specific
// compositionUpdatePolicy, is pinned by a compositionRevisionRef, and --include-pinned was not set.
// The ref is the XR's own or, for a claim naming none, its backing XR's: Crossplane writes the pin
// onto the backing XR alone unless the claim sets one. Such XRs are pinned to a specific
// revision and would not adopt the composition change automatically.
FilterReasonManualPolicy FilterReason = "manual_policy"
// FilterReasonRevisionSelectorMismatch indicates the XR was excluded because it has an Automatic
Expand Down Expand Up @@ -131,8 +133,12 @@ type RevisionImpact struct {
// RepointedComposites counts the composites that would adopt that revision and reconcile as a
// result: those with an Automatic (or defaulted) compositionUpdatePolicy whose
// compositionRevisionSelector, if any, selects the resulting revision, and which are not being
// deleted. A Manual-policy composite is never counted — it is pinned by compositionRevisionRef, so
// --include-pinned keeping it for analysis does not make it re-point (issue #479).
// deleted, plus those with a Manual policy that name no compositionRevisionRef yet, which Crossplane
// gives the latest revision. A Manual-policy composite that names a revision (for a claim, whose
// backing XR does) is never counted — it is pinned to it, so --include-pinned keeping it for
// analysis does not make it re-point (issue #479). Nor is a Manual claim naming no revision whose
// backing XR could not be resolved: it is reported as an XRStatusError instead, even when the
// analysis is skipped.
//
// Note this counts composites that re-point, which is not the same as composites whose rendered
// output changes; re-pointing alone usually renders identically.
Expand Down Expand Up @@ -205,8 +211,8 @@ type AffectedResourcesSummary struct {
WithChanges int `json:"withChanges"`
Unchanged int `json:"unchanged"`
WithErrors int `json:"withErrors"`
// FilteredByPolicy counts XRs excluded because of a Manual compositionUpdatePolicy
// (FilterReasonManualPolicy).
// FilteredByPolicy counts XRs excluded because a Manual compositionUpdatePolicy pins them to a
// compositionRevisionRef (FilterReasonManualPolicy).
FilteredByPolicy int `json:"filteredByPolicy,omitempty"`
// FilteredBySelector counts XRs excluded because their compositionRevisionSelector does not match
// the diffed composition's labels (FilterReasonRevisionSelectorMismatch). Kept separate from
Expand All @@ -230,12 +236,16 @@ type XRImpact struct {
FilterReason FilterReason
// FilterDetail is an optional human-readable explanation for a filtered outcome (e.g. which
// selector failed to match which labels), surfaced to help users self-diagnose the exclusion. A
// Manual-policy composite names the revision it stays pinned to ("compositionRevisionRef: <name>")
// when it has a ref.
// Manual-policy composite names the revision it stays pinned to ("compositionRevisionRef: <name>").
FilterDetail string
// Pinned marks an evaluated composite that would not adopt the composition's resulting revision,
// because its Manual compositionUpdatePolicy pins it to its compositionRevisionRef. Only
// --include-pinned evaluates such a composite; without it, the composite is XRStatusFiltered.
// because its Manual compositionUpdatePolicy pins it to its compositionRevisionRef. It is an
// attribute of the composite, not a status: only one filtered for it (FilterReasonManualPolicy) is
// deferred. Such a composite is evaluated under --include-pinned, or without it when its pinned
// revision calls a changed function (see RenderedRevision); otherwise it is XRStatusFiltered. A Manual
// composite that names no revision is not pinned: Crossplane gives it the latest revision. A claim
// whose backing XR could not be resolved is an XRStatusError and not Pinned, since whether it is
// pinned is unknown.
Pinned bool
// RenderedRevision names the CompositionRevision a Pinned composite was rendered against, when that
// is its own pinned revision rather than the diffed composition: the revision calls a function that
Expand Down
12 changes: 8 additions & 4 deletions internal/simulate/help/selection.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,14 @@ how the change prints:
`--namespace`, or is cluster scoped without it.
- `--include-pinned` renders every pinned composite resource against the new
Composition. By default `simulate` skips composite resources with a `Manual`
composition update policy, because they don't adopt a new Composition
revision on their own. A pinned composite whose revision calls a function
the run changes is still simulated, rendered against the revision it's
pinned to.
composition update policy that are pinned to a Composition revision by
`compositionRevisionRef`, because they don't adopt a new revision on their
own. A `Manual` composite resource with no revision yet gets the new one,
so it's simulated like any other. A pinned composite whose revision calls
a function the run changes is simulated even without the flag, rendered
against the revision it's pinned to, so the preview shows what applying
the change does to it today. With the flag it's rendered against the new
Composition instead, which previews the composite advancing to it.
- `--analyze-on` sets the smallest Composition change that triggers impact
analysis: `spec-change` only when the Composition spec changes;
`any-change`, the default, also when only its metadata changes, which still
Expand Down
10 changes: 6 additions & 4 deletions internal/simulate/report.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,10 +156,12 @@ func FromCompReport(o *dt.CompDiffOutput, plans *ProviderPlans, keep func(*unstr
return res
}

// compositeResult maps an affected composite's impact onto its status. A
// Manual-policy composite is deferred: applying changes nothing for it until
// its revision advances, unless it was rendered against its pinned revision
// because that calls a changed function. Other filtered composites are skipped.
// compositeResult maps an affected composite's impact onto its status. Pinned
// is an attribute, not a status: a composite filtered for its Manual policy is
// deferred, since applying changes nothing for it until its revision advances,
// while a pinned one that was simulated anyway (under --include-pinned, or
// rendered against its pinned revision because that calls a changed function)
// keeps the status of its simulation. Other filtered composites are skipped.
func compositeResult(impact dt.XRImpact) CompositeResult {
c := CompositeResult{Ref: resourceRef(impact.ObjectReference), Pinned: impact.Pinned || impact.FilterReason == dt.FilterReasonManualPolicy}

Expand Down
4 changes: 3 additions & 1 deletion internal/simulate/result.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@ type CompositeReason string

const (
// CompositeReasonManualPolicy means the composite has a Manual
// compositionUpdatePolicy, so it is pinned to its current revision.
// compositionUpdatePolicy and is pinned to a revision by a
// compositionRevisionRef: its own or, for a claim naming none, its
// composite resource's.
CompositeReasonManualPolicy CompositeReason = "manualPolicy"
// CompositeReasonRevisionSelectorMismatch means the composite's
// compositionRevisionSelector does not match the changed revision.
Expand Down
Loading