Skip to content

Commit 67dfd60

Browse files
committed
Make (XR) readiness a top-level CompositionResult field
Just a drive-by nit. The convention in this struct is for XR scoped stuff to be top-level, e.g. ConnectionDetails, events, etc. Signed-off-by: Nic Cope <[email protected]>
1 parent c3b6982 commit 67dfd60

File tree

4 files changed

+33
-31
lines changed

4 files changed

+33
-31
lines changed

internal/controller/apiextensions/composite/composed.go

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,6 @@ import (
2222
v1 "github.com/crossplane/crossplane/apis/apiextensions/v1"
2323
)
2424

25-
// A CompositeResource is an output of the composition process.
26-
type CompositeResource struct { //nolint:revive // stick with CompositeResource
27-
// Ready indicated whether the composite resource should be marked as
28-
// ready or unready regardless of the state of the composed resoureces.
29-
// If it is nil the readiness of the composite is determined by the
30-
// readiness of the composed resources.
31-
Ready *bool
32-
}
33-
3425
// A ResourceName uniquely identifies the composed resource within a Composition
3526
// and within Composition Function gRPC calls. This is not the metadata.name of
3627
// the actual composed resource instance; rather it is the name of an entry in a

internal/controller/apiextensions/composite/composition_functions.go

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -439,16 +439,6 @@ func (c *FunctionComposer) Compose(ctx context.Context, xr *composite.Unstructur
439439
}
440440
}
441441

442-
compositeRes := CompositeResource{}
443-
444-
// Consider the explicit composite unready state in the function response:
445-
switch d.GetComposite().GetReady() { //nolint:exhaustive // only check for false or true
446-
case fnv1.Ready_READY_TRUE:
447-
compositeRes.Ready = ptr.To(true)
448-
case fnv1.Ready_READY_FALSE:
449-
compositeRes.Ready = ptr.To(false)
450-
}
451-
452442
// Garbage collect any observed resources that aren't part of our final
453443
// desired state. We must do this before we update the XR's resource
454444
// references to ensure that we don't forget and leak them if a delete
@@ -563,14 +553,25 @@ func (c *FunctionComposer) Compose(ctx context.Context, xr *composite.Unstructur
563553
return CompositionResult{}, errors.Wrap(err, errApplyXRStatus)
564554
}
565555

556+
var ready *bool
557+
switch d.GetComposite().GetReady() {
558+
case fnv1.Ready_READY_TRUE:
559+
ready = ptr.To(true)
560+
case fnv1.Ready_READY_FALSE:
561+
ready = ptr.To(false)
562+
case fnv1.Ready_READY_UNSPECIFIED:
563+
// Remains nil.
564+
}
565+
566566
result := CompositionResult{
567-
ConnectionDetails: d.GetComposite().GetConnectionDetails(),
568-
Composite: compositeRes,
569567
Composed: resources,
568+
ConnectionDetails: d.GetComposite().GetConnectionDetails(),
569+
Ready: ready,
570570
Events: events,
571571
Conditions: conditions,
572572
TTL: ttl,
573573
}
574+
574575
return result, nil
575576
}
576577

internal/controller/apiextensions/composite/reconciler.go

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -157,12 +157,23 @@ type CompositionRequest struct {
157157

158158
// A CompositionResult is the result of the composition process.
159159
type CompositionResult struct {
160-
Composite CompositeResource
161-
Composed []ComposedResource
160+
// Composed resource details.
161+
Composed []ComposedResource
162+
163+
// XR connection details.
162164
ConnectionDetails managed.ConnectionDetails
163-
Events []TargetedEvent
164-
Conditions []TargetedCondition
165-
TTL time.Duration
165+
166+
// XR readiness. When nil readiness is derived from composed resources.
167+
Ready *bool
168+
169+
// XR and claim events.
170+
Events []TargetedEvent
171+
172+
// XR and claim conditions.
173+
Conditions []TargetedCondition
174+
175+
// TTL for this composition result.
176+
TTL time.Duration
166177
}
167178

168179
// A CompositionTarget is the target of a composition event or condition.
@@ -679,9 +690,9 @@ func (r *Reconciler) Reconcile(ctx context.Context, req reconcile.Request) (reco
679690

680691
// If the composer explicitly specified the XR's readiness it
681692
// supersedes readiness derived from composed resources.
682-
if res.Composite.Ready != nil {
693+
if res.Ready != nil {
683694
ready = xpv1.Creating()
684-
if *res.Composite.Ready {
695+
if *res.Ready {
685696
ready = xpv1.Available()
686697
}
687698
}

internal/controller/apiextensions/composite/reconciler_test.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import (
2929
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
3030
"k8s.io/apimachinery/pkg/runtime"
3131
"k8s.io/apimachinery/pkg/runtime/schema"
32+
"k8s.io/utils/ptr"
3233
"sigs.k8s.io/controller-runtime/pkg/client"
3334
"sigs.k8s.io/controller-runtime/pkg/reconcile"
3435

@@ -1257,11 +1258,9 @@ func TestReconcile(t *testing.T) {
12571258
})),
12581259
WithComposer(ComposerFn(func(_ context.Context, _ *composite.Unstructured, _ CompositionRequest) (CompositionResult, error) {
12591260
return CompositionResult{
1260-
Composite: CompositeResource{
1261-
Ready: &valBoolFalse,
1262-
},
12631261
Composed: []ComposedResource{},
12641262
ConnectionDetails: cd,
1263+
Ready: ptr.To(false),
12651264
Events: []TargetedEvent{},
12661265
Conditions: []TargetedCondition{},
12671266
}, nil

0 commit comments

Comments
 (0)