Skip to content

Commit 794845f

Browse files
chrjones-rhclaude
andauthored
fix(automl,autorag): extend dynamic port-forwarding to S3 and LlamaStack paths (#7310)
* fix(automl,autorag): extend dynamic port-forwarding to S3 and LlamaStack paths The initial port-forwarding implementation only covered the DSPA middleware path. Three additional code paths also use in-cluster URLs that need rewriting for local development: - S3 resolveS3Client (both packages): when secretName is provided, the DSPA middleware is skipped and the endpoint URL from the secret is used directly. Add port-forward rewrite before S3 client creation. - LlamaStack AttachLlamaStackClientFromSecret (autorag): the base URL from the secret is used directly. Add port-forward rewrite before client creation. - LlamaStack ListProviders (autorag): auth token was stripped on HTTP requests. After port-forwarding rewrites to http://localhost, the token must be sent. Allow auth on localhost connections. All changes are guarded by portForwardManager being non-nil (requires DevMode=true) or by localhost-only scope. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * fix(automl,autorag): log port-forward errors instead of silently dropping Address review feedback: ForwardURL errors in the S3 handler and LlamaStack middleware were silently swallowed. Now log warnings consistent with the pattern used in AttachPipelineServerClient. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 46fc04a commit 794845f

3 files changed

Lines changed: 33 additions & 0 deletions

File tree

packages/automl/bff/internal/api/s3_handler.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,17 @@ func (app *App) resolveS3Client(w http.ResponseWriter, r *http.Request, secretNa
146146
}
147147
}
148148

149+
// Dev-only: rewrite S3 endpoint to localhost via dynamic port-forward.
150+
// portForwardManager is nil in production (requires DevMode=true).
151+
if app.portForwardManager != nil && creds.EndpointURL != "" {
152+
if rewritten, pfErr := app.portForwardManager.ForwardURL(ctx, creds.EndpointURL); pfErr != nil {
153+
app.logger.Warn("dynamic port-forward failed for S3 endpoint, using original URL",
154+
"error", pfErr, "url", creds.EndpointURL)
155+
} else {
156+
creds.EndpointURL = rewritten
157+
}
158+
}
159+
149160
s3Client, err := app.s3ClientFactory.CreateClient(creds)
150161
if err != nil {
151162
if errors.Is(err, s3int.ErrEndpointValidation) {

packages/autorag/bff/internal/api/middleware.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,17 @@ func (app *App) AttachLlamaStackClientFromSecret(next func(http.ResponseWriter,
384384
return
385385
}
386386

387+
// Dev-only: rewrite LlamaStack URL to localhost via dynamic port-forward.
388+
// portForwardManager is nil in production (requires DevMode=true).
389+
if app.portForwardManager != nil {
390+
if rewritten, pfErr := app.portForwardManager.ForwardURL(ctx, baseURL); pfErr != nil {
391+
logger.Warn("dynamic port-forward failed for LlamaStack endpoint, using original URL",
392+
"error", pfErr, "url", baseURL)
393+
} else {
394+
baseURL = rewritten
395+
}
396+
}
397+
387398
logger.Debug("Creating LlamaStack client from secret",
388399
"namespace", namespace,
389400
"secretName", secretName,

packages/autorag/bff/internal/api/s3_handler.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,17 @@ func (app *App) resolveS3Client(w http.ResponseWriter, r *http.Request, secretNa
144144
// A new AWS S3 client is created on every request. The AWS SDK client
145145
// is designed for reuse (connection pooling, TLS session caching). Consider caching
146146
// clients by credential identity (e.g. namespace/secretName) with a sync.Map or TTL cache.
147+
// Dev-only: rewrite S3 endpoint to localhost via dynamic port-forward.
148+
// portForwardManager is nil in production (requires DevMode=true).
149+
if app.portForwardManager != nil && creds.EndpointURL != "" {
150+
if rewritten, pfErr := app.portForwardManager.ForwardURL(ctx, creds.EndpointURL); pfErr != nil {
151+
app.logger.Warn("dynamic port-forward failed for S3 endpoint, using original URL",
152+
"error", pfErr, "url", creds.EndpointURL)
153+
} else {
154+
creds.EndpointURL = rewritten
155+
}
156+
}
157+
147158
s3Client, err := app.s3ClientFactory.CreateClient(creds)
148159
if err != nil {
149160
if errors.Is(err, s3int.ErrEndpointValidation) {

0 commit comments

Comments
 (0)