From a8efbe10deca0106baf4751a08b6da8ee97b040b Mon Sep 17 00:00:00 2001 From: Thomas Krampl Date: Tue, 26 Nov 2024 10:06:04 +0100 Subject: [PATCH] Use Bifrost API URL in prod --- internal/cmd/api/api.go | 1 + internal/cmd/api/config.go | 2 +- internal/cmd/api/http.go | 6 ++++-- internal/integration/manager.go | 3 ++- internal/unleash/dataloader.go | 4 +++- 5 files changed, 11 insertions(+), 5 deletions(-) diff --git a/internal/cmd/api/api.go b/internal/cmd/api/api.go index f34a236e..2b7dcf93 100644 --- a/internal/cmd/api/api.go +++ b/internal/cmd/api/api.go @@ -197,6 +197,7 @@ func run(ctx context.Context, cfg *Config, log logrus.FieldLogger) error { promReg, vulnClient, hookdClient, + cfg.Unleash.BifrostApiUrl, log, ) }) diff --git a/internal/cmd/api/config.go b/internal/cmd/api/config.go index a633885c..2e477932 100644 --- a/internal/cmd/api/config.go +++ b/internal/cmd/api/config.go @@ -131,7 +131,7 @@ type unleashConfig struct { Namespace string `env:"UNLEASH_NAMESPACE,default=bifrost-unleash"` // BifrostApiEndpoint is the endpoint for the Bifrost API - BifrostApiUrl string `env:"UNLEASH_BIFROST_API_URL,default=http://bifrost-backend"` + BifrostApiUrl string `env:"UNLEASH_BIFROST_API_URL,default=*fake*"` } type Config struct { diff --git a/internal/cmd/api/http.go b/internal/cmd/api/http.go index 8b426f18..8a894457 100644 --- a/internal/cmd/api/http.go +++ b/internal/cmd/api/http.go @@ -70,6 +70,7 @@ func runHttpServer( reg prometheus.Gatherer, vClient vulnerability.Client, hookdClient hookd.Client, + bifrostAPIURL string, log logrus.FieldLogger, ) error { router := chi.NewRouter() @@ -92,7 +93,7 @@ func runHttpServer( otelhttp.WithRouteTag("playground", otelhttp.NewHandler(playground.Handler("GraphQL playground", "/graphql"), "playground")), ) - contextDependencies, err := ConfigureGraph(ctx, insecureAuthAndFakes, watcherMgr, mgmtWatcherMgr, pool, k8sClients, vClient, tenantName, clusters, hookdClient, log) + contextDependencies, err := ConfigureGraph(ctx, insecureAuthAndFakes, watcherMgr, mgmtWatcherMgr, pool, k8sClients, vClient, tenantName, clusters, hookdClient, bifrostAPIURL, log) if err != nil { return err } @@ -177,6 +178,7 @@ func ConfigureGraph( tenantName string, clusters []string, hookdClient hookd.Client, + bifrostAPIURL string, log logrus.FieldLogger, ) (func(http.Handler) http.Handler, error) { appWatcher := application.NewWatcher(ctx, watcherMgr) @@ -254,7 +256,7 @@ func ConfigureGraph( ctx = deployment.NewLoaderContext(ctx, hookdClient) ctx = serviceaccount.NewLoaderContext(ctx, pool) ctx = session.NewLoaderContext(ctx, pool) - ctx = unleash.NewLoaderContext(ctx, tenantName, unleashWatcher, "*fake*", log) + ctx = unleash.NewLoaderContext(ctx, tenantName, unleashWatcher, bifrostAPIURL, log) return ctx }), nil } diff --git a/internal/integration/manager.go b/internal/integration/manager.go index a133db87..d3d14b1e 100644 --- a/internal/integration/manager.go +++ b/internal/integration/manager.go @@ -27,6 +27,7 @@ import ( "github.com/nais/api/internal/role" "github.com/nais/api/internal/role/rolesql" fakeHookd "github.com/nais/api/internal/thirdparty/hookd/fake" + "github.com/nais/api/internal/unleash" "github.com/nais/api/internal/user" "github.com/nais/api/internal/usersync" "github.com/nais/api/internal/vulnerability" @@ -147,7 +148,7 @@ func newGQLRunner(ctx context.Context, config *Config, pool *pgxpool.Pool, topic vulnerabilityClient := vulnerability.NewDependencyTrackClient(vulnerability.DependencyTrackConfig{EnableFakes: true}, log) - graphMiddleware, err := api.ConfigureGraph(ctx, true, watcherMgr, managementWatcherMgr, pool, clusterConfig, vulnerabilityClient, config.TenantName, clusters(), fakeHookd.New(), log) + graphMiddleware, err := api.ConfigureGraph(ctx, true, watcherMgr, managementWatcherMgr, pool, clusterConfig, vulnerabilityClient, config.TenantName, clusters(), fakeHookd.New(), unleash.FakeBifrostURL, log) if err != nil { return nil, fmt.Errorf("failed to configure graph: %w", err) } diff --git a/internal/unleash/dataloader.go b/internal/unleash/dataloader.go index bee63ec6..0a546b6a 100644 --- a/internal/unleash/dataloader.go +++ b/internal/unleash/dataloader.go @@ -20,6 +20,8 @@ type ctxKey int const ( prometheusURL = "https://nais-prometheus.%s.cloud.nais.io" loadersKey ctxKey = iota + + FakeBifrostURL = "*fake*" ) // NewLoaderContext creates a new context with a loaders value. @@ -47,7 +49,7 @@ type loaders struct { func newLoaders(tenantName string, appWatcher *watcher.Watcher[*UnleashInstance], bifrostAPIURL string, log logrus.FieldLogger) *loaders { var client BifrostClient var prometheus Prometheus - if bifrostAPIURL == "*fake*" { + if bifrostAPIURL == FakeBifrostURL { client = NewFakeBifrostClient(appWatcher) prometheus = NewFakePrometheusClient() } else {