Skip to content

Commit 8e5a0b2

Browse files
Support the dependency messages in the proto
Sync the vendored protos with Crossplane's and regenerate, picking up Dependencies, Dependency, RequiredResourceDependency, the DependencyLifecycle enum, the dependencies field on the request and the response, and CAPABILITY_DEPENDENCIES. Add helpers for the field. response.to carries the request's dependencies forward, like it does desired state and context, so a function that adds an edge keeps the ones it was handed. It copies them only when the request has them: an unset Dependencies means "no opinion, carry mine forward" and an empty one means "drop every constraint", so copying an unset field as an empty one would turn the former into the latter. add_dependency takes composed-to-composed edges, with create_before_destroy rather than the lifecycle enum; add_required_resource_dependency is separate because create_before_destroy is invalid for a required resource, and a separate function makes that unrepresentable. clear_dependencies returns an empty set for a function that wants no constraints at all, and request.get_dependencies reads what the pipeline accumulated. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
1 parent 98f5db7 commit 8e5a0b2

10 files changed

Lines changed: 813 additions & 142 deletions

File tree

‎crossplane/function/proto/v1/run_function.proto‎

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,10 @@ message RunFunctionRequest {
9797
// sets the map key to an empty Schema message to indicate that it attempted
9898
// to satisfy the request.
9999
map<string, Schema> required_schemas = 9;
100+
101+
// Optional ordering constraints over composed resources, accumulated by the
102+
// functions that ran before this one.
103+
Dependencies dependencies = 10;
100104
}
101105

102106
// Credentials that a function may use to communicate with an external system.
@@ -118,6 +122,78 @@ message Resources {
118122
repeated Resource items = 1;
119123
}
120124

125+
// Dependencies is a set of ordering constraints over composed resources.
126+
//
127+
// This is a message wrapping a repeated field, rather than a bare repeated
128+
// field, so that an unset value can be told apart from an empty one. A bare
129+
// repeated field can't express that difference: proto3 has no presence for
130+
// repeated fields, and an empty list and an unset field are both zero bytes on
131+
// the wire. Crossplane relies on the difference, because an unset value means
132+
// "this function has no opinion, carry my constraints forward" while an empty
133+
// one means "this function wants no constraints at all." State wraps desired
134+
// and observed resources for the same reason.
135+
message Dependencies {
136+
repeated Dependency items = 1;
137+
}
138+
139+
// A Dependency declares that one composed resource must be created after, and
140+
// deleted before, another resource. It expresses ordering only. It doesn't move
141+
// any data between resources.
142+
message Dependency {
143+
// Name of the composed resource that has the dependency. A key into the
144+
// desired or observed State.resources map.
145+
string resource = 1;
146+
147+
// What the resource depends on.
148+
oneof depends_on {
149+
// Name of another composed resource. A key into the desired or observed
150+
// State.resources map.
151+
string composed_resource = 2;
152+
153+
// A resource the pipeline required, rather than composed. Crossplane never
154+
// deletes a resource it didn't compose, so these constrain only the order
155+
// resources are created and updated.
156+
RequiredResourceDependency required_resource = 4;
157+
}
158+
159+
// How this dependency constrains the order its endpoints are created and
160+
// deleted. Defaults to symmetric ordering.
161+
DependencyLifecycle lifecycle = 3;
162+
}
163+
164+
// A DependencyLifecycle is how a dependency constrains the order its endpoints
165+
// are created and deleted.
166+
enum DependencyLifecycle {
167+
// Symmetric ordering: the resource is created only once what it depends on
168+
// is ready, and what it depends on is deleted only once the resource is
169+
// gone. This is the default, and the only valid value when depends_on is a
170+
// required resource, because Crossplane never deletes a resource it didn't
171+
// compose.
172+
DEPENDENCY_LIFECYCLE_UNSPECIFIED = 0;
173+
174+
// The resource may be created without waiting for what it depends on to be
175+
// deleted. It must still exist and be ready before what it depends on is
176+
// deleted. Use for a replacement that must exist before its predecessor is
177+
// torn down. Only valid when depends_on is a composed resource.
178+
DEPENDENCY_LIFECYCLE_CREATE_BEFORE_DESTROY = 1;
179+
}
180+
181+
// A RequiredResourceDependency identifies a resource the pipeline required,
182+
// for the purpose of ordering.
183+
message RequiredResourceDependency {
184+
// The requirement name. A key into a RunFunctionRequest's required_resources
185+
// map, and into a RunFunctionResponse's requirements.resources map.
186+
string requirement_name = 1;
187+
188+
// Optional name of a single resource within the set the requirement matched.
189+
// If unset, every resource the requirement matched must be ready.
190+
optional string name = 2;
191+
192+
// Namespace of name for a namespaced resource. Leave unset for a
193+
// cluster-scoped resource. name and namespace together identify one match.
194+
optional string namespace = 3;
195+
}
196+
121197
// A RunFunctionResponse contains the result of a function run.
122198
message RunFunctionResponse {
123199
// Metadata pertaining to this response.
@@ -156,6 +232,14 @@ message RunFunctionResponse {
156232
//
157233
// Only Operations use function output. XRs will discard any function output.
158234
optional google.protobuf.Struct output = 7;
235+
236+
// Optional ordering constraints over composed resources. A function that has
237+
// an opinion about ordering must return the full set it wants going forward,
238+
// including edges it received and still wants. Leaving this field unset means
239+
// "no opinion" - Crossplane carries forward whatever it sent in the request.
240+
//
241+
// Dependencies are only used for composition. They're ignored by Operations.
242+
Dependencies dependencies = 8;
159243
}
160244

161245
// RequestMeta contains metadata pertaining to a RunFunctionRequest.
@@ -201,6 +285,11 @@ enum Capability {
201285
// OpenAPI schemas and Crossplane will return them in required_schemas. Added
202286
// in Crossplane v2.2.
203287
CAPABILITY_REQUIRED_SCHEMAS = 5;
288+
289+
// Crossplane supports the dependencies field. Functions can declare ordering
290+
// constraints over composed resources, and Crossplane will sequence the
291+
// resources it creates, updates and deletes accordingly.
292+
CAPABILITY_DEPENDENCIES = 6;
204293
}
205294

206295
// Requirements that must be satisfied for a function to run successfully.

0 commit comments

Comments
 (0)