generated from TBD54566975/tbd-project-template
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Provisioner for FTL modules (#3050)
Apologies, this grow a bit bigger than I hoped for. Major parts in this PR: - a new in memory provisioner for creating modules by calling `ftl-controller` - an in memory resource graph to represent that modules can depend on databases. The direct dependants are passed to the provisioner when provisioning, with outputs filled in from previous runs. Eventually, this graph will be saved to DB Next: pass the new database DSNs to the controller at deployment. --------- Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
- Loading branch information
1 parent
a658576
commit aca28c7
Showing
21 changed files
with
1,066 additions
and
372 deletions.
There are no files selected for viewing
301 changes: 253 additions & 48 deletions
301
backend/protos/xyz/block/ftl/v1beta1/provisioner/resource.pb.go
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package provisioner | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"connectrpc.com/connect" | ||
|
||
ftlv1 "github.com/TBD54566975/ftl/backend/protos/xyz/block/ftl/v1" | ||
"github.com/TBD54566975/ftl/backend/protos/xyz/block/ftl/v1/ftlv1connect" | ||
"github.com/TBD54566975/ftl/backend/protos/xyz/block/ftl/v1beta1/provisioner" | ||
"github.com/TBD54566975/ftl/internal/log" | ||
) | ||
|
||
// NewControllerProvisioner creates a new provisioner that uses the FTL controller to provision modules | ||
func NewControllerProvisioner(client ftlv1connect.ControllerServiceClient) *InMemProvisioner { | ||
return NewEmbeddedProvisioner(map[ResourceType]InMemResourceProvisionerFn{ | ||
ResourceTypeModule: func(ctx context.Context, rc *provisioner.ResourceContext, module, _ string) (*provisioner.Resource, error) { | ||
mod, ok := rc.Resource.Resource.(*provisioner.Resource_Module) | ||
if !ok { | ||
panic(fmt.Errorf("unexpected resource type: %T", rc.Resource.Resource)) | ||
} | ||
logger := log.FromContext(ctx) | ||
logger.Infof("provisioning module: %s", module) | ||
|
||
resp, err := client.CreateDeployment(ctx, connect.NewRequest(&ftlv1.CreateDeploymentRequest{ | ||
Schema: mod.Module.Schema, | ||
Artefacts: mod.Module.Artefacts, | ||
Labels: mod.Module.Labels, | ||
})) | ||
if err != nil { | ||
return nil, fmt.Errorf("failed to create deployment: %w", err) | ||
} | ||
if mod.Module.Output == nil { | ||
mod.Module.Output = &provisioner.ModuleResource_ModuleResourceOutput{} | ||
} | ||
mod.Module.Output.DeploymentKey = resp.Msg.DeploymentKey | ||
return rc.Resource, nil | ||
}, | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.