@@ -2,6 +2,7 @@ package main
2
2
3
3
import (
4
4
"context"
5
+ "fmt"
5
6
"github.com/crossplane/function-sdk-go/resource"
6
7
7
8
"github.com/crossplane/crossplane-runtime/pkg/errors"
@@ -31,9 +32,6 @@ func (f *Function) RunFunction(_ context.Context, req *fnv1beta1.RunFunctionRequ
31
32
return rsp , nil
32
33
}
33
34
34
- response .Normalf (rsp , "I was run with input %q!" , in .Sequence )
35
- f .log .Info ("I was run!" , "input" , in .Sequence )
36
-
37
35
// Get the desired composed resources from the request.
38
36
desiredComposed , err := request .GetDesiredComposedResources (req )
39
37
if err != nil {
@@ -47,22 +45,32 @@ func (f *Function) RunFunction(_ context.Context, req *fnv1beta1.RunFunctionRequ
47
45
return rsp , nil
48
46
}
49
47
50
- for i , r := range in .Sequence {
51
- if i == 0 {
52
- // We don't need to do anything for the first resource in the sequence.
53
- continue
54
- }
55
- if _ , created := observedComposed [r ]; created {
56
- // We've already created this resource, so we don't need to do anything.
57
- // We only sequence creation of resources that don't exist yet.
58
- continue
59
- }
60
- for _ , before := range in .Sequence [:i ] {
61
- if b , ok := desiredComposed [before ]; ! ok || b .Ready != resource .ReadyTrue {
62
- // A resource that should exist before this one is not in the desired list, or it is not ready yet.
63
- // So, we should not create the resource waiting for it yet.
64
- delete (desiredComposed , r )
65
- break
48
+ sequences := make ([][]resource.Name , 0 , len (in .Rules ))
49
+ for _ , rule := range in .Rules {
50
+ sequences = append (sequences , rule .Sequence )
51
+ }
52
+
53
+ for _ , sequence := range sequences {
54
+ for i , r := range sequence {
55
+ if i == 0 {
56
+ // We don't need to do anything for the first resource in the sequence.
57
+ continue
58
+ }
59
+ if _ , created := observedComposed [r ]; created {
60
+ // We've already created this resource, so we don't need to do anything.
61
+ // We only sequence creation of resources that don't exist yet.
62
+ continue
63
+ }
64
+ for _ , before := range sequence [:i ] {
65
+ if b , ok := desiredComposed [before ]; ! ok || b .Ready != resource .ReadyTrue {
66
+ // A resource that should exist before this one is not in the desired list, or it is not ready yet.
67
+ // So, we should not create the resource waiting for it yet.
68
+ msg := fmt .Sprintf ("Delaying creation of resource %q because %q is not ready or does not exist yet" , r , before )
69
+ response .Normal (rsp , msg )
70
+ f .log .Info (msg )
71
+ delete (desiredComposed , r )
72
+ break
73
+ }
66
74
}
67
75
}
68
76
}
0 commit comments