Skip to content
Merged
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
11 changes: 7 additions & 4 deletions cmd/crossplane/project/integration_plan_output_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import (

dp "github.com/crossplane/cli/v2/internal/diff/diffprocessor"
"github.com/crossplane/cli/v2/internal/exitcode"
"github.com/crossplane/cli/v2/internal/health"
"github.com/crossplane/cli/v2/internal/plan"
"github.com/crossplane/cli/v2/internal/simulate"
"github.com/crossplane/cli/v2/internal/testutils/integration"
Expand Down Expand Up @@ -73,6 +74,8 @@ func TestSimulatePlanOutput(t *testing.T) {
another := xnop
another.Name = "another-resource"
comp := plan.ResourceRef{APIVersion: "apiextensions.crossplane.io/v1", Kind: "Composition", Name: "xnopresources.diff.example.org"}
// healthy is a live composite's health with no failing condition.
healthy := &health.Health{State: health.Healthy}

xrArgs := []string{"-f", "../../../internal/testutils/integration/testdata/diff/modified-xr.yaml"}
compArgs := []string{"-f", "../../../internal/testutils/integration/testdata/comp/updated-composition.yaml", "--namespace=default"}
Expand Down Expand Up @@ -140,7 +143,7 @@ Note: Provider plan not run: no provider diff server planned these resources.
args: append([]string{"-o", "json"}, xrArgs...),
wantResult: &planShape{
Summary: plan.Summary{Update: 2},
Composites: []simulate.CompositeResult{{Ref: xnop, Status: simulate.CompositeChanged}},
Composites: []simulate.CompositeResult{{Ref: xnop, Status: simulate.CompositeChanged, Health: healthy}},
Plans: []planEntry{
{Kind: "XDownstreamResource", Name: "test-resource", Action: plan.ActionUpdate, Composite: "test-resource"},
{Kind: "XNopResource", Name: "test-resource", Action: plan.ActionUpdate, Composite: "test-resource"},
Expand Down Expand Up @@ -184,7 +187,7 @@ Note: Provider plan not run: no provider diff server planned these resources.
args: append([]string{"-o", "json"}, compArgs...),
wantResult: &planShape{
Summary: plan.Summary{Update: 3, NoOp: 2},
Composites: []simulate.CompositeResult{{Ref: another, Status: simulate.CompositeChanged, Composition: &comp}, {Ref: xnop, Status: simulate.CompositeChanged, Composition: &comp}},
Composites: []simulate.CompositeResult{{Ref: another, Status: simulate.CompositeChanged, Composition: &comp, Health: healthy}, {Ref: xnop, Status: simulate.CompositeChanged, Composition: &comp, Health: healthy}},
Compositions: []simulate.CompositionResult{{
Ref: comp,
RevisionImpact: &simulate.RevisionImpact{ChangeScope: "spec", CreatesRevision: true, RepointedComposites: 2},
Expand All @@ -203,7 +206,7 @@ Note: Provider plan not run: no provider diff server planned these resources.
args: []string{"-o", "json", "-n", "default", "--name=another-resource", "--name=test-resource"},
wantResult: &planShape{
Summary: plan.Summary{Update: 3, NoOp: 2},
Composites: []simulate.CompositeResult{{Ref: another, Status: simulate.CompositeChanged, Composition: &comp}, {Ref: xnop, Status: simulate.CompositeChanged, Composition: &comp}},
Composites: []simulate.CompositeResult{{Ref: another, Status: simulate.CompositeChanged, Composition: &comp, Health: healthy}, {Ref: xnop, Status: simulate.CompositeChanged, Composition: &comp, Health: healthy}},
Compositions: []simulate.CompositionResult{{
Ref: comp,
RevisionImpact: &simulate.RevisionImpact{ChangeScope: "spec", CreatesRevision: true, RepointedComposites: 2},
Expand All @@ -222,7 +225,7 @@ Note: Provider plan not run: no provider diff server planned these resources.
args: []string{"-o", "json", "--name=default/test-resource"},
wantResult: &planShape{
Summary: plan.Summary{Update: 2, NoOp: 1},
Composites: []simulate.CompositeResult{{Ref: xnop, Status: simulate.CompositeChanged, Composition: &comp}},
Composites: []simulate.CompositeResult{{Ref: xnop, Status: simulate.CompositeChanged, Composition: &comp, Health: healthy}},
Compositions: []simulate.CompositionResult{{
Ref: comp,
RevisionImpact: &simulate.RevisionImpact{ChangeScope: "spec", CreatesRevision: true, RepointedComposites: 1},
Expand Down
3 changes: 2 additions & 1 deletion cmd/crossplane/project/integration_project_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
"github.com/google/go-cmp/cmp"

dp "github.com/crossplane/cli/v2/internal/diff/diffprocessor"
"github.com/crossplane/cli/v2/internal/health"
"github.com/crossplane/cli/v2/internal/plan"
"github.com/crossplane/cli/v2/internal/simulate"
"github.com/crossplane/cli/v2/internal/testutils/integration"
Expand Down Expand Up @@ -71,7 +72,7 @@ func TestProjectSimulateIntegration(t *testing.T) {
changed := func(refs ...plan.ResourceRef) []simulate.CompositeResult {
out := make([]simulate.CompositeResult, 0, len(refs))
for _, r := range refs {
out = append(out, simulate.CompositeResult{Ref: r, Status: simulate.CompositeChanged, Composition: &comp})
out = append(out, simulate.CompositeResult{Ref: r, Status: simulate.CompositeChanged, Composition: &comp, Health: &health.Health{State: health.Healthy}})
}
return out
}
Expand Down
12 changes: 10 additions & 2 deletions internal/diff/diffprocessor/comp_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ type XRDiffResult struct {
Error error
// unchanged holds the unchanged renderings Diffs leaves out, for the overlap check only.
unchanged map[string]*dt.ResourceDiff
// health is the live health the render read, computed as the XR is diffed so that the live objects
// are not retained until impact analysis.
health dt.CompositeHealth
}

// HasChanges returns true if this XR has downstream resource changes.
Expand Down Expand Up @@ -816,7 +819,7 @@ func (p *DefaultCompDiffProcessor) collectXRDiffs(ctx context.Context, xrs []*un
}

xrCtx, cancel := p.config.xrContext(ctx)
diffs, unchanged, err := p.xrProc.DiffSingleResource(xrCtx, xr, compositionProvider)
diffs, rendered, err := p.xrProc.DiffSingleResource(xrCtx, xr, compositionProvider)
err = p.config.afterXR(ctx, xrCtx, diffs, err)
cancel()
if err != nil {
Expand All @@ -831,7 +834,8 @@ func (p *DefaultCompDiffProcessor) collectXRDiffs(ctx context.Context, xrs []*un
// Store successful result with diffs
results[resourceID] = &XRDiffResult{
Diffs: diffs,
unchanged: unchanged,
unchanged: rendered.Unchanged(),
health: rendered.Health(),
}
}
}
Expand Down Expand Up @@ -1643,6 +1647,7 @@ func (p *DefaultCompDiffProcessor) buildImpactAnalysis(xrs []*un.Unstructured, r
case result != nil && result.HasChanges():
impact.Status = dt.XRStatusChanged
impact.Diffs = result.Diffs
impact.Health = result.health
summary.WithChanges++
default:
impact.Status = dt.XRStatusUnchanged
Expand All @@ -1651,6 +1656,9 @@ func (p *DefaultCompDiffProcessor) buildImpactAnalysis(xrs []*un.Unstructured, r
if result != nil && p.config.KeepEqualDiffs != nil {
impact.Diffs = result.Diffs
}
if result != nil {
impact.Health = result.health
}
summary.Unchanged++
}

Expand Down
Loading
Loading