Skip to content

Commit

Permalink
refactor: provisioner is no longer a SchemaService (#3555)
Browse files Browse the repository at this point in the history
I think this functionality was removed earlier anyway, so this is no
longer relevant?
  • Loading branch information
alecthomas authored Nov 28, 2024
1 parent e6d5b01 commit 547598c
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 42 deletions.
35 changes: 1 addition & 34 deletions backend/provisioner/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ func (c *Config) SetDefaults() {

type Service struct {
controllerClient ftlv1connect.ControllerServiceClient
schemaClient ftlv1connect.SchemaServiceClient
currentResources *xsync.MapOf[string, *ResourceGraph]
registry *ProvisionerRegistry
}
Expand All @@ -52,13 +51,11 @@ func New(
ctx context.Context,
config Config,
controllerClient ftlv1connect.ControllerServiceClient,
schemaClient ftlv1connect.SchemaServiceClient,
registry *ProvisionerRegistry,
) (*Service, error) {
resourceMap := xsync.NewMapOf[string, *ResourceGraph]()
return &Service{
controllerClient: controllerClient,
schemaClient: schemaClient,
currentResources: resourceMap,
registry: registry,
}, nil
Expand Down Expand Up @@ -165,14 +162,13 @@ func Start(
config Config,
registry *ProvisionerRegistry,
controllerClient ftlv1connect.ControllerServiceClient,
schemaClient ftlv1connect.SchemaServiceClient,
) error {
config.SetDefaults()

logger := log.FromContext(ctx)
logger.Debugf("Starting FTL provisioner")

svc, err := New(ctx, config, controllerClient, schemaClient, registry)
svc, err := New(ctx, config, controllerClient, registry)
if err != nil {
return err
}
Expand Down Expand Up @@ -252,32 +248,3 @@ func (s *Service) UploadArtefact(ctx context.Context, req *connect.Request[ftlv1
}
return connect.NewResponse(resp.Msg), nil
}

func (s *Service) GetSchema(ctx context.Context, req *connect.Request[ftlv1.GetSchemaRequest]) (*connect.Response[ftlv1.GetSchemaResponse], error) {
resp, err := s.schemaClient.GetSchema(ctx, req)
if err != nil {
logger := log.FromContext(ctx)
logger.Errorf(err, "get schema failed")
return nil, fmt.Errorf("call to ftl-controller failed: %w", err)
}
return connect.NewResponse(resp.Msg), nil
}

func (s *Service) PullSchema(ctx context.Context, req *connect.Request[ftlv1.PullSchemaRequest], to *connect.ServerStream[ftlv1.PullSchemaResponse]) error {
logger := log.FromContext(ctx)
stream, err := s.schemaClient.PullSchema(ctx, req)
if err != nil {
logger.Errorf(err, "pull schema failed")
return fmt.Errorf("call to ftl-controller failed: %w", err)
}
defer stream.Close()
for stream.Receive() {
if err := stream.Err(); err != nil {
return fmt.Errorf("call to ftl-controller failed: %w", err)
}
if err := to.Send(stream.Msg()); err != nil {
return fmt.Errorf("call to ftl-controller failed: %w", err)
}
}
return nil
}
3 changes: 1 addition & 2 deletions cmd/ftl-provisioner/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,10 @@ func main() {
kctx.FatalIfErrorf(err, "failed to initialize observability")

controllerClient := rpc.Dial(ftlv1connect.NewControllerServiceClient, cli.ProvisionerConfig.ControllerEndpoint.String(), log.Error)
schemaClient := rpc.Dial(ftlv1connect.NewSchemaServiceClient, cli.ProvisionerConfig.ControllerEndpoint.String(), log.Error)

registry, err := provisioner.RegistryFromConfigFile(ctx, cli.ProvisionerConfig.PluginConfigFile, controllerClient)
kctx.FatalIfErrorf(err, "failed to create provisioner registry")

err = provisioner.Start(ctx, cli.ProvisionerConfig, registry, controllerClient, schemaClient)
err = provisioner.Start(ctx, cli.ProvisionerConfig, registry, controllerClient)
kctx.FatalIfErrorf(err, "failed to start provisioner")
}
5 changes: 2 additions & 3 deletions frontend/cli/cmd_dev.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ func (d *devCmd) Run(
sm *manager.Manager[configuration.Secrets],
projConfig projectconfig.Config,
bindContext terminal.KongContextBinder,
schemaClient ftlv1connect.SchemaServiceClient,
schemaEventSourceFactory func() schemaeventsource.EventSource,
controllerClient ftlv1connect.ControllerServiceClient,
provisionerClient provisionerconnect.ProvisionerServiceClient,
Expand Down Expand Up @@ -97,15 +96,15 @@ func (d *devCmd) Run(
controllerReady := make(chan bool, 1)
if !d.NoServe {
if d.ServeCmd.Stop {
err := d.ServeCmd.run(ctx, projConfig, cm, sm, optional.Some(controllerReady), true, bindAllocator, controllerClient, schemaClient, provisionerClient, schemaEventSourceFactory, verbClient, true, nil)
err := d.ServeCmd.run(ctx, projConfig, cm, sm, optional.Some(controllerReady), true, bindAllocator, controllerClient, provisionerClient, schemaEventSourceFactory, verbClient, true, nil)
if err != nil {
return fmt.Errorf("failed to stop server: %w", err)
}
d.ServeCmd.Stop = false
}

g.Go(func() error {
return d.ServeCmd.run(ctx, projConfig, cm, sm, optional.Some(controllerReady), true, bindAllocator, controllerClient, schemaClient, provisionerClient, schemaEventSourceFactory, verbClient, true, devModeEndpointUpdates)
return d.ServeCmd.run(ctx, projConfig, cm, sm, optional.Some(controllerReady), true, bindAllocator, controllerClient, provisionerClient, schemaEventSourceFactory, verbClient, true, devModeEndpointUpdates)
})
}

Expand Down
5 changes: 2 additions & 3 deletions frontend/cli/cmd_serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ func (s *serveCmd) Run(
if err != nil {
return fmt.Errorf("could not create bind allocator: %w", err)
}
return s.run(ctx, projConfig, cm, sm, optional.None[chan bool](), false, bindAllocator, controllerClient, schemaClient, provisionerClient, schemaEventSourceFactory, verbClient, s.Recreate, nil)
return s.run(ctx, projConfig, cm, sm, optional.None[chan bool](), false, bindAllocator, controllerClient, provisionerClient, schemaEventSourceFactory, verbClient, s.Recreate, nil)
}

//nolint:maintidx
Expand All @@ -97,7 +97,6 @@ func (s *serveCommonConfig) run(
devMode bool,
bindAllocator *bind.BindAllocator,
controllerClient ftlv1connect.ControllerServiceClient,
schemaServiceClient ftlv1connect.SchemaServiceClient,
provisionerClient provisionerconnect.ProvisionerServiceClient,
schemaEventSourceFactory func() schemaeventsource.EventSource,
verbClient ftlv1connect.VerbServiceClient,
Expand Down Expand Up @@ -285,7 +284,7 @@ func (s *serveCommonConfig) run(
}

wg.Go(func() error {
if err := provisioner.Start(provisionerCtx, config, provisionerRegistry, controllerClient, schemaServiceClient); err != nil {
if err := provisioner.Start(provisionerCtx, config, provisionerRegistry, controllerClient); err != nil {
logger.Errorf(err, "provisioner%d failed: %v", i, err)
return fmt.Errorf("provisioner%d failed: %w", i, err)
}
Expand Down

0 comments on commit 547598c

Please sign in to comment.