Skip to content

Commit f43e36b

Browse files
committedMar 12, 2025
tmp
1 parent 91a160b commit f43e36b

File tree

5 files changed

+22
-16
lines changed

5 files changed

+22
-16
lines changed
 

‎backend/provisioner/scaling/k8sscaling/k8s_scaling.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,7 @@ func (r *k8sScaling) handleNewDeployment(ctx context.Context, module string, nam
424424
}
425425

426426
deployment.Spec.Template.Spec.ServiceAccountName = module
427-
changes, err := r.syncDeployment(ctx, thisImage, deployment, 1)
427+
changes, err := r.syncDeployment(ctx, thisImage, deployment, sch.Runtime.Scaling.MinReplicas)
428428

429429
if err != nil {
430430
return err

‎backend/schemaservice/events.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -198,9 +198,10 @@ func handleChangesetCreatedEvent(t *SchemaState, e *schema.ChangesetCreatedEvent
198198
}
199199
for _, dep := range e.Changeset.Modules {
200200
if dep.Runtime.Scaling == nil {
201-
dep.Runtime.Scaling = &schema.ModuleRuntimeScaling{MinReplicas: 1}
202201
if existing, ok := t.deployments[dep.Name]; ok {
203-
dep.Runtime.Scaling.MinReplicas = existing.Runtime.Scaling.MinReplicas
202+
dep.Runtime.ModScaling().MinReplicas = existing.Runtime.Scaling.MinReplicas
203+
} else {
204+
dep.Runtime.Scaling = &schema.ModuleRuntimeScaling{MinReplicas: 1}
204205
}
205206
}
206207
}

‎cmd/ftl/cmd_deploy.go

+5-4
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package main
33
import (
44
"context"
55
"fmt"
6+
"github.com/alecthomas/types/optional"
67
"time"
78

89
"github.com/block/ftl/backend/protos/xyz/block/ftl/admin/v1/adminpbconnect"
@@ -13,10 +14,10 @@ import (
1314
)
1415

1516
type deployCmd struct {
16-
Replicas int32 `short:"n" help:"Number of replicas to deploy." default:"1"`
17-
NoWait bool `help:"Do not wait for deployment to complete." default:"false"`
18-
Build buildCmd `embed:""`
19-
Timeout time.Duration `short:"t" help:"Timeout for the deployment."`
17+
Replicas optional.Option[int32] `short:"n" help:"Number of replicas to deploy."`
18+
NoWait bool `help:"Do not wait for deployment to complete." default:"false"`
19+
Build buildCmd `embed:""`
20+
Timeout time.Duration `short:"t" help:"Timeout for the deployment."`
2021
}
2122

2223
func (d *deployCmd) Run(

‎internal/buildengine/deploy.go

+6-2
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ type pendingModule struct {
5757

5858
type pendingDeploy struct {
5959
modules map[string]*pendingModule
60-
replicas int32
60+
replicas optional.Option[int32]
6161

6262
publishInSchema bool
6363
changeset optional.Option[key.Changeset]
@@ -112,7 +112,7 @@ func NewDeployCoordinator(ctx context.Context, adminClient AdminClient, schemaSo
112112
return c
113113
}
114114

115-
func (c *DeployCoordinator) deploy(ctx context.Context, projConfig projectconfig.Config, modules []Module, replicas int32) error {
115+
func (c *DeployCoordinator) deploy(ctx context.Context, projConfig projectconfig.Config, modules []Module, replicas optional.Option[int32]) error {
116116
for _, module := range modules {
117117
c.engineUpdates <- &buildenginepb.EngineEvent{
118118
Event: &buildenginepb.EngineEvent_ModuleDeployWaiting{
@@ -344,6 +344,10 @@ func (c *DeployCoordinator) tryDeployFromQueue(ctx context.Context, deployment *
344344
},
345345
},
346346
}
347+
if repo, ok := deployment.replicas.Get(); ok {
348+
log.FromContext(ctx).Infof("Deploying %s with %d replicas", module.name, repo) //nolint:forbidigo
349+
module.schema.ModRuntime().ModScaling().MinReplicas = repo
350+
}
347351
}
348352

349353
keyChan := make(chan result.Result[key.Changeset], 1)

‎internal/buildengine/engine.go

+7-7
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,7 @@ func (e *Engine) watchForModuleChanges(ctx context.Context, period time.Duration
384384
}()
385385

386386
// Build and deploy all modules first.
387-
_ = e.BuildAndDeploy(ctx, 1, true, false) //nolint:errcheck
387+
_ = e.BuildAndDeploy(ctx, optional.None[int32](), true, false) //nolint:errcheck
388388

389389
// Update schema and set initial module hashes
390390
for {
@@ -432,7 +432,7 @@ func (e *Engine) watchForModuleChanges(ctx context.Context, period time.Duration
432432
},
433433
}
434434
logger.Debugf("calling build and deploy %q", event.Config.Module)
435-
_ = e.BuildAndDeploy(ctx, 1, false, false, config.Module) //nolint:errcheck
435+
_ = e.BuildAndDeploy(ctx, optional.None[int32](), false, false, config.Module) //nolint:errcheck
436436
}
437437
case watch.WatchEventModuleRemoved:
438438
err := e.deployCoordinator.terminateModuleDeployment(ctx, event.Config.Module)
@@ -476,7 +476,7 @@ func (e *Engine) watchForModuleChanges(ctx context.Context, period time.Duration
476476
meta.module.Config = validConfig
477477
e.moduleMetas.Store(event.Config.Module, meta)
478478

479-
_ = e.BuildAndDeploy(ctx, 1, false, false, event.Config.Module) //nolint:errcheck
479+
_ = e.BuildAndDeploy(ctx, optional.None[int32](), false, false, event.Config.Module) //nolint:errcheck
480480
}
481481
case event := <-e.deployCoordinator.SchemaUpdates:
482482
e.targetSchema.Store(event.schema)
@@ -509,7 +509,7 @@ func (e *Engine) watchForModuleChanges(ctx context.Context, period time.Duration
509509
})
510510
if len(dependentModuleNames) > 0 {
511511
logger.Infof("%s's schema changed; processing %s", module.Name, strings.Join(dependentModuleNames, ", ")) //nolint:forbidigo
512-
_ = e.BuildAndDeploy(ctx, 1, false, false, dependentModuleNames...) //nolint:errcheck
512+
_ = e.BuildAndDeploy(ctx, optional.None[int32](), false, false, dependentModuleNames...) //nolint:errcheck
513513
}
514514
}
515515

@@ -561,7 +561,7 @@ func (e *Engine) watchForModuleChanges(ctx context.Context, period time.Duration
561561
}
562562
}
563563
go func() {
564-
_ = e.deployCoordinator.deploy(ctx, e.projectConfig, modulesToDeploy, 1) //nolint:errcheck
564+
_ = e.deployCoordinator.deploy(ctx, e.projectConfig, modulesToDeploy, optional.None[int32]()) //nolint:errcheck
565565
}()
566566
}
567567

@@ -575,7 +575,7 @@ func (e *Engine) watchForModuleChanges(ctx context.Context, period time.Duration
575575
modulesToBuild[event.module] = true
576576
}
577577
if len(modulesToBuild) > 0 {
578-
_ = e.BuildAndDeploy(ctx, 1, false, false, maps.Keys(modulesToBuild)...) //nolint
578+
_ = e.BuildAndDeploy(ctx, optional.None[int32](), false, false, maps.Keys(modulesToBuild)...) //nolint
579579
}
580580
}
581581
}
@@ -789,7 +789,7 @@ func (e *Engine) getDependentModuleNames(moduleName string) []string {
789789
}
790790

791791
// BuildAndDeploy attempts to build and deploy all local modules.
792-
func (e *Engine) BuildAndDeploy(ctx context.Context, replicas int32, waitForDeployOnline bool, singleChangeset bool, moduleNames ...string) (err error) {
792+
func (e *Engine) BuildAndDeploy(ctx context.Context, replicas optional.Option[int32], waitForDeployOnline bool, singleChangeset bool, moduleNames ...string) (err error) {
793793
logger := log.FromContext(ctx)
794794
if len(moduleNames) == 0 {
795795
moduleNames = e.Modules()

0 commit comments

Comments
 (0)