From d339228f8438f61413b1ea2c75adb0d8c64750f9 Mon Sep 17 00:00:00 2001 From: Wes Date: Tue, 28 May 2024 15:18:28 -0700 Subject: [PATCH] fix: panic when ftl-controller trying to access config and secrets (#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. --- cmd/ftl-controller/main.go | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/cmd/ftl-controller/main.go b/cmd/ftl-controller/main.go index e8b9e21e75..2c26db2fed 100644 --- a/cmd/ftl-controller/main.go +++ b/cmd/ftl-controller/main.go @@ -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" @@ -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() { @@ -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) }