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
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,24 @@ In other words, the following rules apply:

See `example/composition-regex.yaml` for a complete example.

### Composite Readiness
Enabling the `resetCompositeReadiness` flag causes the function to set the Composite's `Ready` flag to `False` when at
least one desired resource is deleted from the request. This prevents the Composite resource from entering the `Ready`
state prematurely when there are pending resources that the composite reconciler is unaware of.

```yaml
- step: sequence-creation
functionRef:
name: function-sequencer
input:
apiVersion: sequencer.fn.crossplane.io/v1beta1
kind: Input
resetCompositeReadiness: true
rules:
- sequence:
- first-subresource-.*
- second-resource
```
## Installation

It can be installed as follows from the Upbound marketplace: https://marketplace.upbound.io/functions/crossplane-contrib/function-sequencer
Expand Down
4 changes: 4 additions & 0 deletions fn.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,10 @@ func (f *Function) RunFunction(_ context.Context, req *v1.RunFunctionRequest) (*
continue
}
delete(desiredComposed, k)
if in.ResetCompositeReadiness {
// Reset the composite ready indicator to false when a desired resource is deleted.
rsp.Desired.Composite.Ready = v1.Ready_READY_FALSE
}
}
}
break
Expand Down
74 changes: 74 additions & 0 deletions fn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1109,6 +1109,80 @@ func TestRunFunction(t *testing.T) {
},
},
},
"MarkCompositeNotReady": {
reason: "Set the Composite ready flag to false",
args: args{
req: &v1.RunFunctionRequest{
Input: resource.MustStructObject(&v1beta1.Input{
ResetCompositeReadiness: true,
Rules: []v1beta1.SequencingRule{
{
Sequence: []resource.Name{
"first",
"second",
"third",
},
},
},
}),
Observed: &v1.State{
Composite: &v1.Resource{
Resource: resource.MustStructJSON(xr),
},
Resources: map[string]*v1.Resource{
"first": {
Resource: resource.MustStructJSON(mr),
},
"second": {
Resource: resource.MustStructJSON(mr),
},
},
},
Desired: &v1.State{
Composite: &v1.Resource{
Resource: resource.MustStructJSON(xr),
},
Resources: map[string]*v1.Resource{
"first": {
Resource: resource.MustStructJSON(mr),
},
"second": {
Resource: resource.MustStructJSON(mr),
},
"third": {
Resource: resource.MustStructJSON(mr),
},
},
},
},
},
want: want{
rsp: &v1.RunFunctionResponse{
Meta: &v1.ResponseMeta{Ttl: durationpb.New(response.DefaultTTL)},
Results: []*v1.Result{
{
Severity: v1.Severity_SEVERITY_NORMAL,
Message: "Delaying creation of resource(s) matching \"third\" because \"first\" is not fully ready (0 of 1)",
Target: &target,
},
},
Desired: &v1.State{
Composite: &v1.Resource{
Ready: v1.Ready_READY_FALSE,
Resource: resource.MustStructJSON(xr),
},
Resources: map[string]*v1.Resource{
"first": {
Resource: resource.MustStructJSON(mr),
},
"second": {
Resource: resource.MustStructJSON(mr),
},
},
},
},
},
},
}

for name, tc := range cases {
Expand Down
3 changes: 3 additions & 0 deletions input/v1beta1/input.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ type Input struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

// ResetCompositeReadiness sets the composite ready state to false if desired resources are removed from the request.
// +kubebuilder:object:default=false
ResetCompositeReadiness bool `json:"resetCompositeReadiness,omitempty"`
// Rules is a list of rules that describe sequences of resources.
Rules []SequencingRule `json:"rules"`
}
4 changes: 4 additions & 0 deletions package/input/sequencer.fn.crossplane.io_inputs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ spec:
type: string
metadata:
type: object
resetCompositeReadiness:
description: ResetCompositeReadiness sets the composite ready state to
false if desired resources are removed from the request.
type: boolean
rules:
description: Rules is a list of rules that describe sequences of resources.
items:
Expand Down
Loading