Skip to content

feat: run python transformation tests on ephemeral per-request pyt deployments - #7177

Merged
mihir20 merged 20 commits into
masterfrom
mihir/pipe-3172
Jul 20, 2026
Merged

mihir20 merged 20 commits into
masterfrom
mihir/pipe-3172

Conversation

@mihir20

@mihir20 mihir20 commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

Description

Python transformation tests (execution ops) run arbitrary, untrusted customer code. Previously, the processor's cpservice scaled up the workspace's shared production pyt deployment (pytscaler) and
forwarded the test to it — meaning test code ran on the same pods that serve production traffic.

This PR replaces that model with ephemeral, per-request pyt deployments: every execution test request gets its own fresh Deployment + Service, created just for that request and torn down after it —
one test per pod.

Changes

New processor/internal/pytdeployer package (replaces pytscaler)

  • Deployer.RunOnEphemeral(ctx, workspaceID, forward) owns the full lifecycle: create Deployment + Service → wait for readiness → forward the request → delete both (best-effort).
  • Deployment spec mirrors the production per-workspace pytransformer chart: Kata runtime class (kata-fc), kata nodepool selector + tolerations, resource requests, image pull secret — all configurable
    via Processor.pytDeployer.* config keys (env, labels, pod annotations, and readiness timeout are hot-reloadable).
  • Zone pinning: pods are pinned to the processor's AVAILABILITY_ZONE (node selector + pod label) and the Service selector is scoped to that zone, so cross-zone traffic is avoided.
  • All created objects are stamped with contract labels (app.kubernetes.io/managed-by=rudderstack-processor, rudderstack.com/purpose=pyt-test, rudderstack.com/workspace-id) that the reaper CronJob key off.
  • Deliberately no no-op fallback (unlike pytscaler): if a real k8s-backed deployer can't be built, execution ops fail with FailedPrecondition — there is no safe fallback target for untrusted code.
    AST ops are unaffected.
  • k8s API calls retry with exponential backoff on transient errors (retry helper moved over from pytscaler).
  • Metrics port exposed on the pod for scraping.

cpservice routing changes

  • Execution ops (test, testRun) → fresh ephemeral deployment via deployer.RunOnEphemeral.
  • AST ops (testLibrary, extractLibs) never execute user code → forwarded straight to a shared static AST deployment (Processor.pytTestStaticASTURL), no k8s API involvement.
  • Per-workspace escape hatch: workspaces flagged via Processor.pytTestOverrides.<workspaceID>.routeToProduction (hot-reloadable, with a global fallback key) forward to their production pyt
    deployment instead — for workspaces whose tests need prod-only config (custom DNS, pinned egress IPs, ...) that the generic ephemeral spec can't reproduce. No readiness wait there; the forwarder's
    cold-start retries ride out the scale-from-zero window.
  • Removed the singleflight scale-group and scale-replicas config — no longer needed without shared-deployment scaling.
  • Forward now logs the end-to-end forward duration per op for performance monitoring.

user_transformer forwarder refactor

  • Test-forwarding methods (Test, TestRun, TestLibrary, ExtractLibs) now take an explicit baseURL resolved by the caller instead of deriving the URL from the workspace ID, so the same client
    serves ephemeral, prod-routed, and static-AST targets.
  • ErrPerWorkspacePyTNotEnabled replaced by ErrEmptyForwardBaseURL (mapped to FailedPrecondition, since misconfiguration must not be retried away).
  • PerWorkspacePyTBaseURL extracted as the single place the {workspaceID} template substitution lives.

Linear Ticket

PIPE-3172

Security

  • The code changed/added as part of this pull request won't create any security issues with how the software is being used.

mihir20 added 10 commits July 7, 2026 13:14
🔒 Scanned for secrets using gitleaks 8.28.0
…forwards

🔒 Scanned for secrets using gitleaks 8.28.0
…forwards

🔒 Scanned for secrets using gitleaks 8.28.0
…ring

🔒 Scanned for secrets using gitleaks 8.28.0
…ved error handling

🔒 Scanned for secrets using gitleaks 8.28.0
…ordingly

🔒 Scanned for secrets using gitleaks 8.28.0
…e resources

🔒 Scanned for secrets using gitleaks 8.28.0
🔒 Scanned for secrets using gitleaks 8.28.0
🔒 Scanned for secrets using gitleaks 8.28.0
🔒 Scanned for secrets using gitleaks 8.28.0
@mihir20
mihir20 requested review from fracasula and ktgowtham July 13, 2026 13:21
🔒 Scanned for secrets using gitleaks 8.28.0
@codecov

codecov Bot commented Jul 13, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 94.10112% with 21 lines in your changes missing coverage. Please review.
✅ Project coverage is 79.70%. Comparing base (9c01fa0) to head (b679bde).

Files with missing lines Patch % Lines
processor/internal/pytdeployer/k8s.go 92.51% 11 Missing and 3 partials ⚠️
...l/transformer/user_transformer/user_transformer.go 89.18% 3 Missing and 1 partial ⚠️
processor/internal/pytdeployer/pytdeployer.go 95.00% 2 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #7177      +/-   ##
==========================================
+ Coverage   79.62%   79.70%   +0.07%     
==========================================
  Files         595      595              
  Lines       66154    66353     +199     
==========================================
+ Hits        52677    52886     +209     
+ Misses      10359    10335      -24     
- Partials     3118     3132      +14     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

// each retry re-resolves DNS, and the pod's replacement (the forward path
// scales the deployment up before dialing) answers a later attempt.
var opErr *net.OpError
if errors.As(err, &opErr) && opErr.Op == "dial" && opErr.Timeout() {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Syntax update in Go 1.26: replace 'errors.As' with the type-safe 'errors.AsType'

return err
}
if isColdStartError(nil, resp) {
httputil.CloseResponse(resp)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not just move the defer before if isColdStartError(nil, resp)?

return backoff.Permanent(err)
// Connection broke mid-response — as transient as a failed
// request; retry.
return err

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a bit confused here. This used to be a permanent error (i.e. not retryable). Now we're saying it's "as transient as a failed request" and retry indefinitely but we don't have visibility on this, right? No metrics, no logs. We can only wait until max tries is reached and it then propagates.

Are we sure this isn't a regression? Is it really as the comment says "Connection broke mid-response"? Can it be something else as well?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, there can be multiple network errors, so just like processor transform flow, I am retrying for every error. will add some observability here.

func loadConfig(conf *config.Config) deployerConfig {
return deployerConfig{
namespace: conf.GetStringVar("test-pytransformer", "Processor.pytDeployer.pytTestNamespace"),
image: conf.GetStringVar("", "Processor.pytDeployer.pytTestImage"),

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens if this one stays empty? Is there any validation done?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there is no validation will add

return deployerConfig{
namespace: conf.GetStringVar("test-pytransformer", "Processor.pytDeployer.pytTestNamespace"),
image: conf.GetStringVar("", "Processor.pytDeployer.pytTestImage"),
imagePullSecret: conf.GetStringVar("regcred", "Processor.pytDeployer.pytTestImagePullSecret"),

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't we remove this default as it could be considered a leak and we panic if empty (or error)?

InitialDelaySeconds: 5, PeriodSeconds: 10, TimeoutSeconds: 5, FailureThreshold: 3,
},
Resources: corev1.ResourceRequirements{
Requests: corev1.ResourceList{

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given that it's untrusted code plus it's also testing code (not production grade) I think it would make sense to add a limit as well.

…oyer

🔒 Scanned for secrets using gitleaks 8.28.0
@mihir20
mihir20 requested a review from fracasula July 14, 2026 07:41
🔒 Scanned for secrets using gitleaks 8.28.0

@fracasula fracasula left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, I left a bunch of comments for you to review.

In addition to them I was thinking that we have no "rate limit" whatsoever, so a burst of test requests can provision unbounded Kata microVM pods. It's good that we'll have a reaper handling cleanups, but what about admissions? cc @ktgowtham

We could have a simple semaphore in the deployer and optionally a ResourceQuota so that a bug/misconfiguration can't exhaust the Kata nodepool.

Comment thread processor/cpservice/forward.go Outdated
// workspaceID has already passed validWorkspaceID in Forward, so it is safe
// to interpolate into the key.
func (s *Service) isProdRouted(workspaceID string) bool {
return s.conf.GetReloadableBoolVar(false,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given that this is called every time and that nothing would clean up the registered variables (and we could register any number given that we're interpolating the workspaceID), why not register it only once by using GetReloadableStringMapVar? I know it's an edge case, and that it's very unlikely that we would register that many, but it seems like an easy change to avoid a potential leak.

maxElapsedTime: conf.GetDurationVar(30, time.Second, "Processor.UserTransformer.pytScaler.retry.maxElapsedTime"),
multiplier: conf.GetFloat64Var(1.5, "Processor.UserTransformer.pytScaler.retry.multiplier"),
randomizationFactor: conf.GetFloat64Var(0.5, "Processor.UserTransformer.pytScaler.retry.randomizationFactor"),
initialInterval: conf.GetDurationVar(200, time.Millisecond, "Processor.pytDeployer.retry.initialInterval"),

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was looking at this file again due to these changes, and I was thinking if perhaps we should extend isTransient a bit further and add k8s.io/apimachinery/pkg/util/net's IsConnectionReset, IsConnectionRefused, IsProbableEOF (and optionally a net.Error.Timeout() check). It shouldn't cause issues and it could improve the detection a bit more. Wdyt?

Comment thread processor/internal/pytdeployer/k8s.go Outdated
Comment on lines +193 to +199
podLabels := maps.Clone(labels)
svcSelector := maps.Clone(labels)
if d.config.zone != "" {
podSpec.NodeSelector["topology.kubernetes.io/zone"] = d.config.zone
podLabels["zone"] = d.config.zone
svcSelector["zone"] = d.config.zone
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't we add the zone label first and the clone to avoid potential collisions?

	if d.config.zone != "" {
		podSpec.NodeSelector["topology.kubernetes.io/zone"] = d.config.zone
		labels["zone"] = d.config.zone
	}
	podLabels := maps.Clone(labels)
	svcSelector := maps.Clone(labels)

If an operator's pytTestLabels includes a key literally named "zone" while AVAILABILITY_ZONE is also set, then we might have a problem.

A test on this would be nice too.

Comment thread processor/cpservice/forward.go Outdated
@@ -28,36 +32,64 @@ type endpointForward func(ctx context.Context, workspaceID string, payload []byt
var validWorkspaceID = regexp.MustCompile(`^[a-zA-Z0-9-]{1,59}$`)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This regex allows leading/trailing hyphens as well (like -abc or abc-) while k8s label values must begin and end as alphanumeric or we could get a non-transient Create failure. Given that we're already validating it, we might as well make sure this is more precise.

Containers: []corev1.Container{{
Name: "pytransformer",
Image: d.config.image,
SecurityContext: &corev1.SecurityContext{

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I got a comment from a security agent here but haven't verified. Can you please look into it?

#### 5. Untrusted-code container lacks `Capabilities.Drop: ["ALL"]` and a `SeccompProfile` (security)

**Why:** The `SecurityContext` sets `RunAsNonRoot`, `RunAsUser/Group`, `ReadOnlyRootFilesystem`, `AllowPrivilegeEscalation: false` — but still omits a capability drop and seccomp profile, so it doesn't meet the PSS "restricted" baseline standard for untrusted workloads (this update added resource Limits but not these). Kata (`kata-fc`) is the primary boundary, so it's defense-in-depth, but a cheap, direct fit for the stated goal.

**Fix:** Add `Capabilities: {Drop: ["ALL"]}` and `SeccompProfile: {Type: RuntimeDefault}`.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I understood correctly these makes sense:

Capabilities Drop: ["ALL"] — Even non-root containers get a default set of Linux privileges (raw network access, changing file ownership, switching users, etc.). Dropping all of them means the customer's
Python code has zero privileged operations available — and pytransformer needs none of them anyway (unprivileged port, fixed user, own temp dir).

Seccomp RuntimeDefault — Filters which kernel syscalls the container can make, blocking the ~40-50 obscure ones that most kernel exploits enter through. Kubernetes leaves this off by default, so setting
it explicitly guarantees the filter regardless of cluster config.

Why together — Kata's microVM is the primary sandbox; these two are defense-in-depth inside it, and they complete the PSS "restricted" profile (the strictest k8s standard) at zero cost to the app.

corev1.ResourceMemory: d.config.memoryRequest,
},
Limits: corev1.ResourceList{
corev1.ResourceCPU: d.config.cpuLimit,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could add an easy check and make sure that limits >= requests


ticker := time.NewTicker(readinessPollInterval)
defer ticker.Stop()
var lastErr error

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see we never reset lastErr. Can this be a problem after a successful-but-not-ready Get? 🤔

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed now

@mihir20

mihir20 commented Jul 16, 2026

Copy link
Copy Markdown
Contributor Author

LGTM, I left a bunch of comments for you to review.

In addition to them I was thinking that we have no "rate limit" whatsoever, so a burst of test requests can provision unbounded Kata microVM pods. It's good that we'll have a reaper handling cleanups, but what about admissions? cc @ktgowtham

We could have a simple semaphore in the deployer and optionally a ResourceQuota so that a bug/misconfiguration can't exhaust the Kata nodepool.

This is a good point; I will pick this as a follow-up task, as this is not a blocker for the release.

mihir20 added 4 commits July 16, 2026 14:56
… selectors

🔒 Scanned for secrets using gitleaks 8.28.0
…its at startup

🔒 Scanned for secrets using gitleaks 8.28.0
@mihir20
mihir20 merged commit 1008ae7 into master Jul 20, 2026
75 checks passed
@mihir20
mihir20 deleted the mihir/pipe-3172 branch July 20, 2026 06:15
This was referenced Jul 20, 2026
mihir20 pushed a commit that referenced this pull request Jul 20, 2026
🤖 I have created a release *beep* *boop*
---


##
[1.81.0-rc.1](v1.80.0...v1.81.0-rc.1)
(2026-07-20)


### Features

* run python transformation tests on ephemeral per-request pyt
deployments
([#7177](#7177))
([1008ae7](1008ae7))
* support partition migration job fanout per jobsdb
([#7141](#7141))
([be42e48](be42e48))


### Bug Fixes

* abort snowpipe events on channel bad request
([#7118](#7118))
([6c08584](6c08584))
* avoid redundant transformer statTags unmarshalling
([#7182](#7182))
([c3c283c](c3c283c))
* classify reverse-ETL sources from config for MAR metering
([#7159](#7159))
([fa7870f](fa7870f))
* detect server-side snowpipe channel failures via per-channel status at
stuck threshold
([#7166](#7166))
([581410c](581410c))
* kafkamanager compilation error
([#7189](#7189))
([1fb7f6e](1fb7f6e))
* **kafka:** support insecure TLS skip verify config
([#7022](#7022))
([d01574f](d01574f))
* preserve order when overflowing snowpipe insert batches
([#7178](#7178))
([9c01fa0](9c01fa0))
* quote postgres warehouse ddl identifiers
([#7127](#7127))
([5aeb481](5aeb481))
* **router:** emit invalid payload metric
([#7168](#7168))
([6e2009a](6e2009a))
* update null to #N/A for salesforce bulk upload
([#7151](#7151))
([1dffd93](1dffd93))
* **warehouse:** use pod identity for rudder-storage flow; keep S3-copy
user fallback for user S3 destinations
([#7167](#7167))
([3f9aa32](3f9aa32))


### Miscellaneous

* add contract tests for test endpoints in pytransformer
([#7147](#7147))
([3b210ec](3b210ec))
* bump compose-test to v0.1.5 to remediate pgx CVE-2026-33815
([#7162](#7162))
([7672f96](7672f96))
* **deps:** bump actions/checkout from 6.0.3 to 7.0.0
([#7132](#7132))
([d453c93](d453c93))
* **deps:** bump actions/setup-go from 6.4.0 to 6.5.0
([#7150](#7150))
([75d9648](75d9648))
* **deps:** bump aws-actions/amazon-ecr-login from 2.1.5 to 2.1.6
([#7109](#7109))
([7b2a859](7b2a859))
* **deps:** bump aws-actions/configure-aws-credentials from 6.2.0 to
6.2.2 ([#7152](#7152))
([c984268](c984268))
* **deps:** bump golangci/golangci-lint-action from 9.2.1 to 9.3.0
([#7170](#7170))
([4565d25](4565d25))
* **deps:** bump the frequent group across 1 directory with 4 updates
([#6891](#6891))
([88a0ddf](88a0ddf))
* support compression in bqstream destinations
([#7142](#7142))
([0694f12](0694f12))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

Co-authored-by: rudderstack-github-actions[bot] <236995729+rudderstack-github-actions[bot]@users.noreply.github.com>
@ktgowtham

Copy link
Copy Markdown
Contributor

LGTM, I left a bunch of comments for you to review.

In addition to them I was thinking that we have no "rate limit" whatsoever, so a burst of test requests can provision unbounded Kata microVM pods. It's good that we'll have a reaper handling cleanups, but what about admissions? cc @ktgowtham

We could have a simple semaphore in the deployer and optionally a ResourceQuota so that a bug/misconfiguration can't exhaust the Kata nodepool.

We should introduce rate limit on control plane side. cc: @mihir20

mihir20 pushed a commit that referenced this pull request Jul 21, 2026
🤖 I have created a release *beep* *boop*
---


##
[1.81.0](v1.80.0...v1.81.0)
(2026-07-20)


### Features

* run python transformation tests on ephemeral per-request pyt
deployments
([#7177](#7177))
([1008ae7](1008ae7))
* support partition migration job fanout per jobsdb
([#7141](#7141))
([be42e48](be42e48))


### Bug Fixes

* abort snowpipe events on channel bad request
([#7118](#7118))
([6c08584](6c08584))
* avoid redundant transformer statTags unmarshalling
([#7182](#7182))
([c3c283c](c3c283c))
* classify reverse-ETL sources from config for MAR metering
([#7159](#7159))
([fa7870f](fa7870f))
* detect server-side snowpipe channel failures via per-channel status at
stuck threshold
([#7166](#7166))
([581410c](581410c))
* kafkamanager compilation error
([#7189](#7189))
([1fb7f6e](1fb7f6e))
* **kafka:** support insecure TLS skip verify config
([#7022](#7022))
([d01574f](d01574f))
* preserve order when overflowing snowpipe insert batches
([#7178](#7178))
([9c01fa0](9c01fa0))
* quote postgres warehouse ddl identifiers
([#7127](#7127))
([5aeb481](5aeb481))
* **router:** emit invalid payload metric
([#7168](#7168))
([6e2009a](6e2009a))
* update null to #N/A for salesforce bulk upload
([#7151](#7151))
([1dffd93](1dffd93))
* **warehouse:** use pod identity for rudder-storage flow; keep S3-copy
user fallback for user S3 destinations
([#7167](#7167))
([3f9aa32](3f9aa32))


### Miscellaneous

* add contract tests for test endpoints in pytransformer
([#7147](#7147))
([3b210ec](3b210ec))
* bump compose-test to v0.1.5 to remediate pgx CVE-2026-33815
([#7162](#7162))
([7672f96](7672f96))
* **deps:** bump actions/checkout from 6.0.3 to 7.0.0
([#7132](#7132))
([d453c93](d453c93))
* **deps:** bump actions/setup-go from 6.4.0 to 6.5.0
([#7150](#7150))
([75d9648](75d9648))
* **deps:** bump aws-actions/amazon-ecr-login from 2.1.5 to 2.1.6
([#7109](#7109))
([7b2a859](7b2a859))
* **deps:** bump aws-actions/configure-aws-credentials from 6.2.0 to
6.2.2 ([#7152](#7152))
([c984268](c984268))
* **deps:** bump golangci/golangci-lint-action from 9.2.1 to 9.3.0
([#7170](#7170))
([4565d25](4565d25))
* **deps:** bump the frequent group across 1 directory with 4 updates
([#6891](#6891))
([88a0ddf](88a0ddf))
* support compression in bqstream destinations
([#7142](#7142))
([0694f12](0694f12))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

Co-authored-by: rudderstack-github-actions[bot] <236995729+rudderstack-github-actions[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants