Skip to content

Support composed resource dependencies - #378

Draft
stevendborrelli wants to merge 1 commit into
crossplane:mainfrom
stevendborrelli:composed-resource-dependencies
Draft

stevendborrelli wants to merge 1 commit into
crossplane:mainfrom
stevendborrelli:composed-resource-dependencies

Conversation

@stevendborrelli

Copy link
Copy Markdown
Member

Work in progress. Please don't merge. This follows crossplane/crossplane#7842, the draft prototype that adds dependencies to the function protocol and has Crossplane order composed resource creation and deletion from them. The design is in crossplane/crossplane#7841. The proto messages here come from that prototype and aren't upstream yet, so this can't land before it does. It's the Go counterpart of crossplane/function-sdk-python#241.

Description of your changes

This adds SDK support for the dependencies field that #7842 adds to RunFunctionRequest and RunFunctionResponse.

proto/v1 is synced with the prototype's proto/fn/v1 and regenerated. That adds Dependencies, Dependency, RequiredResourceDependency, the DependencyLifecycle enum, the dependencies field on the request and the response, and CAPABILITY_DEPENDENCIES.

response.To carries the request's dependencies forward, the way it carries desired state and context, so a function that adds a dependency keeps the ones earlier functions declared. It copies them only when the request has them, because an unset field means "no opinion, carry mine forward" and an empty one means "drop every constraint". It copies rather than shares them, so adding to the response doesn't change the request.

Four helpers declare dependencies:

rsp := response.To(req, response.DefaultTTL)

if request.HasCapability(req, fnv1.Capability_CAPABILITY_DEPENDENCIES) {
	// subnet is created once vpc is ready, and vpc is deleted once subnet is gone.
	response.AddDependency(rsp, "subnet", "vpc")

	// new-db is created without waiting for old-db to go, and old-db is
	// deleted once new-db is ready.
	response.AddDependency(rsp, "old-db", "new-db", response.WithCreateBeforeDestroy())

	// app waits for a resource the function requires but doesn't compose.
	response.AddRequiredResourceDependency(rsp, "app", &fnv1.RequiredResourceDependency{RequirementName: "config"})
}

response.ClearDependencies drops every dependency, including the ones To copied forward.

function-ordering, a fork of function-sequencer that emits dependencies instead of composing Usages, builds against this branch and declares its edges with AddDependency.

I have:

  • Read and followed Crossplane's contribution process.
  • Run make reviewable to ensure this PR is ready for review.

How has this code been tested

Unit tests cover To carrying dependencies forward, unset versus empty, and copying rather than sharing, along with each helper.

🤖 Generated with Claude Code

Sync proto/v1 with the composed resource ordering prototype in
crossplane/crossplane#7842 and regenerate, picking up Dependencies,
Dependency, RequiredResourceDependency, the DependencyLifecycle enum, the
dependencies field on the request and the response, and
CAPABILITY_DEPENDENCIES.

response.To carries the request's dependencies forward, as it does
desired state and context, so a function that adds one keeps the ones
earlier functions declared. It copies them only when the request has
them: unset means "no opinion, carry mine forward" and empty means "drop
every constraint", so turning one into the other would change the graph.
It copies rather than shares them, so adding to the response doesn't add
to the request.

AddDependency declares a dependency between composed resources, with
WithCreateBeforeDestroy for a replacement, AddRequiredResourceDependency
one on a resource the function requires, and ClearDependencies drops
them all.

This mirrors crossplane/function-sdk-python#241, and like it can't land
before the protocol change does.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant