Skip to content

feat: implement Kubernetes deployment scaler for workspace replica management - #7123

Merged
mihir20 merged 1 commit into
masterfrom
mihir/pipe-3145
Jul 3, 2026
Merged

mihir20 merged 1 commit into
masterfrom
mihir/pipe-3145

Conversation

@mihir20

@mihir20 mihir20 commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

Description

Adds processor/internal/pytscaler — a small package that reads and sets the replica count of a workspace's per-workspace rudder-pytransformer (pyt-{workspaceID}) Deployment via the Kubernetes scale subresource.

The pyt Deployments default to 0 replicas (Keda scales them back to 0 when idle), so before the processor forwards a test request
to a workspace's pyt pod, it must scale that Deployment up from zero. This package is the scaling primitive the Forward handler (pipe-3144) will call. No call site is wired up yet — this PR only introduces the package and its tests.

What's in here

  • Scaler interface — two thin primitives over the scale subresource:
    • GetReplicaCount(ctx, workspaceID) (int, error)
    • SetReplicaCount(ctx, workspaceID, count int) error
  • k8sScaler (unexported) — the real implementation:
    • The pyt Deployment lives in one of several pyt namespaces, not a fixed one. Since the scale subresource is namespace-scoped, it locates the Deployment cluster-wide by metadata.name=pyt-{lower(workspaceID)} (a
      universally-supported field selector) and reads the namespace off the match — no namespace config or ExternalName parsing.
    • Operates only through the scale subresource (GetScale/UpdateScale), never a full Deployment update, so the pod spec — including the Kata RuntimeClass — is never touched.
    • Transient k8s API errors (429, timeouts, 500, 503) are retried with exponential backoff; everything else fails fast.
  • noopScaler (NewNoop) — a do-nothing implementation so the processor starts and serves even when Kubernetes is unavailable (local dev, client-build failure, or the feature disabled). Its GetReplicaCount reports 1 so
    a get-before-set caller naturally skips scaling.
  • In-cluster client by default, with a kubeconfig fallback for local dev.

Design notes

  • Idempotency is the caller's job, not this layer's. SetReplicaCount writes the count unconditionally; the "scale to N only when the current count is 0" decision lives in the caller (the Forward handler). This keeps the
    k8s layer a pure pass-through to the scale subresource and mirrors the orchestrator's ReplicaManager (GetReplicaCount/SetReplicaCount) terminology.
  • The scale target (Processor.UserTransformer.pytTestScaleReplicas) is not read here — the caller decides the count and passes it in.
  • Scaler is the abstraction boundary — the Forward handler depends on the interface, not on Kubernetes. Two implementations (k8sScaler, noopScaler) plus a fake-client testing need justify the interface.

Linear Ticket

pipe-3145

Security

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

… replica management

🔒 Scanned for secrets using gitleaks 8.28.0
@mihir20 mihir20 changed the title feat(pytscaler): implement Kubernetes deployment scaler for workspace replica management feat: implement Kubernetes deployment scaler for workspace replica management Jun 25, 2026
@mihir20
mihir20 requested review from fracasula and ktgowtham June 25, 2026 06:58
@codecov

codecov Bot commented Jun 25, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 69.60000% with 38 lines in your changes missing coverage. Please review.
✅ Project coverage is 79.48%. Comparing base (9d5c58a) to head (6a44ad8).

Files with missing lines Patch % Lines
processor/internal/pytscaler/k8s.go 58.44% 28 Missing and 4 partials ⚠️
processor/internal/pytscaler/pytscaler.go 81.48% 4 Missing and 1 partial ⚠️
processor/internal/pytscaler/retry.go 95.23% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #7123      +/-   ##
==========================================
- Coverage   79.88%   79.48%   -0.40%     
==========================================
  Files         584      587       +3     
  Lines       65493    65618     +125     
==========================================
- Hits        52319    52159     -160     
- Misses      10053    10353     +300     
+ Partials     3121     3106      -15     

☔ 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.

@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.

Should we have something to prevent the keda autoscaler not to be below a certain threshold to avoid issues with this testing functionality? e.g. we scale up and then after 15-30s it is scaled down by keda potentially terminating the pod mid-request.

return int(scale.Spec.Replicas), nil
}

func (s *k8sScaler) SetReplicaCount(ctx context.Context, workspaceID string, count int) 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.

Would it make sense to return here not just after the kube-apiserver accepted the write but when the pods are ready?

@mihir20 mihir20 Jun 26, 2026 •

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.

it should be fine I am planning to use an existing transformer client that retries on cold start, which means it will retry until the pod is ready. And also, we will be emitting a cold start metric in case of any cold start failure, which will help in keeping KEDA also happy with the replica count we are manually setting.

@mihir20

mihir20 commented Jun 26, 2026

Copy link
Copy Markdown
Contributor Author

Should we have something to prevent the keda autoscaler not to be below a certain threshold to avoid issues with this testing functionality? e.g. we scale up and then after 15-30s it is scaled down by keda potentially terminating the pod mid-request.

@fracasula, once we scale up and a request is sent to pytransformer, the metrics used in KEDA will not let the pod to go away, and we have a 10-min stabilization window, which will not take the pod away even after 10 min when the traffic is 0.

@mihir20
mihir20 requested a review from fracasula June 26, 2026 05:57
@mihir20
mihir20 merged commit 84fc747 into master Jul 3, 2026
74 of 75 checks passed
@mihir20
mihir20 deleted the mihir/pipe-3145 branch July 3, 2026 07:03
This was referenced Jul 6, 2026
itsmihir pushed a commit that referenced this pull request Jul 6, 2026
🤖 I have created a release *beep* *boop*
---


##
[1.80.0-rc.1](v1.79.0...v1.80.0-rc.1)
(2026-07-06)


### Features

* add control-plane connection management for processor
([#7126](#7126))
([ea6ca00](ea6ca00))
* carry integration version on DestinationT to the transformer
([#7125](#7125))
([421c613](421c613))
* implement Forward RPC for control-plane requests to workspace pyt
transformers
([#7143](#7143))
([8a704cf](8a704cf))
* implement Kubernetes deployment scaler for workspace replica
management
([#7123](#7123))
([84fc747](84fc747))
* monthly active records (MAR) metering pipeline
([#7119](#7119))
([d1df486](d1df486))


### Bug Fixes

* **router:** transformer returning response with empty metadata array
causes server to panic
([#7144](#7144))
([d6a4dbc](d6a4dbc))


### Miscellaneous

* enable compression for google pubsub
([#7137](#7137))
([11c9ab8](11c9ab8))

---
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>
itsmihir pushed a commit that referenced this pull request Jul 7, 2026
🤖 I have created a release *beep* *boop*
---


##
[1.80.0](v1.79.0...v1.80.0)
(2026-07-06)


### Features

* add control-plane connection management for processor
([#7126](#7126))
([ea6ca00](ea6ca00))
* carry integration version on DestinationT to the transformer
([#7125](#7125))
([421c613](421c613))
* implement Forward RPC for control-plane requests to workspace pyt
transformers
([#7143](#7143))
([8a704cf](8a704cf))
* implement Kubernetes deployment scaler for workspace replica
management
([#7123](#7123))
([84fc747](84fc747))
* monthly active records (MAR) metering pipeline
([#7119](#7119))
([d1df486](d1df486))


### Bug Fixes

* **router:** transformer returning response with empty metadata array
causes server to panic
([#7144](#7144))
([d6a4dbc](d6a4dbc))


### Miscellaneous

* enable compression for google pubsub
([#7137](#7137))
([11c9ab8](11c9ab8))

---
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