Skip to content

Commit

Permalink
fix: panic when ftl-controller trying to access config and secrets (#…
Browse files Browse the repository at this point in the history
…1592)

Fixes #1588 by providing a workaround to load `ftl-project.toml`s from
paths specified in command line args or `FTL_CONFIG` env.

I doubt we want this long-term given the work that is being done with
AWS secrets manager, db config, and `AdminService` but this might help
unblock the deployment work for now.
  • Loading branch information
wesbillman authored May 28, 2024
1 parent 662a289 commit d339228
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions cmd/ftl-controller/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/TBD54566975/ftl"
"github.com/TBD54566975/ftl/backend/controller"
"github.com/TBD54566975/ftl/backend/controller/scaling"
cf "github.com/TBD54566975/ftl/common/configuration"
_ "github.com/TBD54566975/ftl/internal/automaxprocs" // Set GOMAXPROCS to match Linux container CPU quota.
"github.com/TBD54566975/ftl/internal/log"
"github.com/TBD54566975/ftl/internal/observability"
Expand All @@ -22,6 +23,7 @@ var cli struct {
ObservabilityConfig observability.Config `embed:"" prefix:"o11y-"`
LogConfig log.Config `embed:"" prefix:"log-"`
ControllerConfig controller.Config `embed:""`
ConfigFlag []string `name:"config" short:"C" help:"Paths to FTL project configuration files." env:"FTL_CONFIG" placeholder:"FILE[,FILE,...]"`
}

func main() {
Expand All @@ -38,6 +40,28 @@ func main() {
err = observability.Init(ctx, "ftl-controller", ftl.Version, cli.ObservabilityConfig)
kctx.FatalIfErrorf(err, "failed to initialize observability")

// This is duplicating the logic in the `ftl/main.go` to resolve the current panic
// However, this should be updated to only allow providers that are supported on the current environment
// See https://github.com/TBD54566975/ftl/issues/1473 for more information
sr := cf.ProjectConfigResolver[cf.Secrets]{Config: cli.ConfigFlag}
cr := cf.ProjectConfigResolver[cf.Configuration]{Config: cli.ConfigFlag}
kctx.BindTo(sr, (*cf.Resolver[cf.Secrets])(nil))
kctx.BindTo(cr, (*cf.Resolver[cf.Configuration])(nil))

// Add config manager to context.
cm, err := cf.NewConfigurationManager(ctx, cr)
if err != nil {
kctx.Fatalf(err.Error())
}
ctx = cf.ContextWithConfig(ctx, cm)

// Add secrets manager to context.
sm, err := cf.NewSecretsManager(ctx, sr)
if err != nil {
kctx.Fatalf(err.Error())
}
ctx = cf.ContextWithSecrets(ctx, sm)

err = controller.Start(ctx, cli.ControllerConfig, scaling.NewK8sScaling())
kctx.FatalIfErrorf(err)
}

0 comments on commit d339228

Please sign in to comment.