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.
chore: configurable provisioners in ftl-provisioner (#2925)
Adds a TOML config file for configuring which provisioner plugin to use for which resource. There is a hard coded `noop` provisioner doing nothing. Otherwise a binary with name `ftl-provisioner-<name>` is used as plugin. Next, I will use Localstack to test that the Cloudformation plugin actually creates a DB. --------- Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
- Loading branch information
1 parent
091a2c4
commit d55777e
Showing
9 changed files
with
211 additions
and
86 deletions.
There are no files selected for viewing
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,19 @@ | ||
package deployment | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/TBD54566975/ftl/backend/protos/xyz/block/ftl/v1beta1/provisioner" | ||
) | ||
|
||
type NoopProvisioner struct{} | ||
|
||
func (n *NoopProvisioner) Provision(ctx context.Context, module string, desired []*provisioner.ResourceContext, existing []*provisioner.Resource) (string, error) { | ||
return "", nil | ||
} | ||
|
||
func (n *NoopProvisioner) State(ctx context.Context, token string, desired []*provisioner.Resource) (TaskState, []*provisioner.Resource, error) { | ||
return TaskStateDone, desired, nil | ||
} | ||
|
||
var _ Provisioner = (*NoopProvisioner)(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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package deployment | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"connectrpc.com/connect" | ||
|
||
"github.com/TBD54566975/ftl/backend/protos/xyz/block/ftl/v1beta1/provisioner" | ||
"github.com/TBD54566975/ftl/backend/protos/xyz/block/ftl/v1beta1/provisioner/provisionerconnect" | ||
"github.com/TBD54566975/ftl/common/plugin" | ||
"github.com/TBD54566975/ftl/internal/log" | ||
) | ||
|
||
// PluginProvisioner delegates provisioning to an external plugin | ||
type PluginProvisioner struct { | ||
cmdCtx context.Context | ||
client *plugin.Plugin[provisionerconnect.ProvisionerPluginServiceClient] | ||
} | ||
|
||
var _ Provisioner = (*PluginProvisioner)(nil) | ||
|
||
func NewPluginProvisioner(ctx context.Context, name string) (*PluginProvisioner, error) { | ||
client, cmdCtx, err := plugin.Spawn( | ||
ctx, | ||
log.Debug, | ||
"ftl-provisioner-"+name, | ||
".", | ||
"ftl-provisioner-"+name, | ||
provisionerconnect.NewProvisionerPluginServiceClient, | ||
) | ||
if err != nil { | ||
return nil, fmt.Errorf("error spawning plugin: %w", err) | ||
} | ||
|
||
return &PluginProvisioner{ | ||
cmdCtx: cmdCtx, | ||
client: client, | ||
}, nil | ||
} | ||
|
||
func (p *PluginProvisioner) Provision(ctx context.Context, module string, desired []*provisioner.ResourceContext, existing []*provisioner.Resource) (string, error) { | ||
resp, err := p.client.Client.Provision(ctx, connect.NewRequest(&provisioner.ProvisionRequest{ | ||
DesiredResources: desired, | ||
ExistingResources: existing, | ||
FtlClusterId: "ftl", | ||
Module: module, | ||
})) | ||
if err != nil { | ||
return "", fmt.Errorf("error calling plugin: %w", err) | ||
} | ||
if resp.Msg.Status != provisioner.ProvisionResponse_SUBMITTED { | ||
return resp.Msg.ProvisioningToken, nil | ||
} | ||
return "", nil | ||
} | ||
|
||
func (p *PluginProvisioner) State(ctx context.Context, token string, desired []*provisioner.Resource) (TaskState, []*provisioner.Resource, error) { | ||
resp, err := p.client.Client.Status(ctx, connect.NewRequest(&provisioner.StatusRequest{ | ||
ProvisioningToken: token, | ||
})) | ||
if err != nil { | ||
return "", nil, fmt.Errorf("error getting status from plugin: %w", err) | ||
} | ||
if failed, ok := resp.Msg.Status.(*provisioner.StatusResponse_Failed); ok { | ||
return TaskStateFailed, nil, fmt.Errorf("provisioning failed: %s", failed.Failed.ErrorMessage) | ||
} else if success, ok := resp.Msg.Status.(*provisioner.StatusResponse_Success); ok { | ||
return TaskStateDone, success.Success.UpdatedResources, nil | ||
} | ||
return TaskStateRunning, nil, 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 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
Oops, something went wrong.