Skip to content

Conversation

@HardMax71
Copy link
Owner

@HardMax71 HardMax71 commented Jan 28, 2026


Summary by cubic

Consolidated all Kubernetes worker config into Settings and removed K8sWorkerConfig. This centralizes pod resources, namespace, and concurrency and simplifies instantiation and tests.

  • Refactors

    • Removed K8sWorkerConfig and its exports; deleted config.py.
    • KubernetesWorker now reads from Settings (K8S_NAMESPACE, K8S_MAX_CONCURRENT_PODS) and validates namespace; updated logging.
    • PodBuilder now depends on Settings and uses K8S_POD_* values and K8S_NAMESPACE for manifests.
    • Providers create KubernetesWorker without config; consumer group set to GroupId.K8S_WORKER.
    • Added Settings.K8S_MAX_CONCURRENT_PODS (default 10).
    • Updated tests to mock Settings and simplify imports.
  • Migration

    • Stop using K8sWorkerConfig; pass Settings into KubernetesWorker and PodBuilder.
    • Set env vars as needed: K8S_NAMESPACE, K8S_POD_CPU_REQUEST/MEMORY_REQUEST/CPU_LIMIT/MEMORY_LIMIT, K8S_MAX_CONCURRENT_PODS.
    • Update imports to: from app.services.k8s_worker import KubernetesWorker, PodBuilder.

Written for commit 42c8f8d. Summary will update on new commits.

Summary by CodeRabbit

  • Refactor
    • Centralized Kubernetes worker configuration onto the global settings object; worker and pod construction now use settings instead of a legacy per-worker config.
    • Removed the legacy per-worker config export and simplified worker initialization and package imports.
    • Added K8S_MAX_CONCURRENT_PODS setting to control concurrent pod creations; tests updated accordingly.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link

coderabbitai bot commented Jan 28, 2026

📝 Walkthrough

Walkthrough

The PR removes the K8sWorkerConfig dataclass and migrates Kubernetes worker configuration into the centralized Settings object. PodBuilder and KubernetesWorker now accept Settings, namespace and resource values are read from Settings, K8S_MAX_CONCURRENT_PODS was added, and provider wiring/imports were simplified.

Changes

Cohort / File(s) Summary
Config Removal
backend/app/services/k8s_worker/config.py
Deleted K8sWorkerConfig dataclass and its file; configuration fields moved to Settings.
Package Exports
backend/app/services/k8s_worker/__init__.py
Removed import/export of K8sWorkerConfig from package __all__.
PodBuilder
backend/app/services/k8s_worker/pod_builder.py
Constructor changed from (namespace, config) to (settings: Settings); resource requests/limits and namespace now read from Settings (K8S_* keys).
KubernetesWorker
backend/app/services/k8s_worker/worker.py
Removed config: K8sWorkerConfig parameter; now uses settings: Settings for namespace, concurrency (K8S_MAX_CONCURRENT_PODS), and other k8s values; PodBuilder instantiated with settings.
Settings
backend/app/settings.py
Added K8S_MAX_CONCURRENT_PODS: int = 10.
Providers / Wiring
backend/app/core/providers.py, backend/workers/run_k8s_worker.py
Removed K8sWorkerConfig usage/imports; import paths updated to use package root exports; get_k8s_worker_consumer uses GroupId.K8S_WORKER.
Tests
backend/tests/e2e/test_k8s_worker_create_pod.py, backend/tests/unit/services/test_pod_builder.py
Tests updated to construct/use Settings (or mock settings) and import PodBuilder/KubernetesWorker from package root; removed K8sWorkerConfig-based setup.

Sequence Diagram(s)

(Skipped — changes are a refactor of configuration wiring and do not introduce a new multi-component control flow that requires visualization.)

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

Poem

🐰 I hopped through code, config in my paw,
Replaced old dataclass with Settings I saw,
Pods now spawn under one centralized law,
Semaphores hum, and imports withdraw,
A carrot for tests — green changes, hurrah! 🥕

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 78.26% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title mentions removing k8s config and routing through settings, which aligns with the core refactoring. However, 'routing stuff through settings' is somewhat vague and colloquial phrasing that doesn't precisely convey the main change.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@backend/app/settings.py`:
- Around line 37-38: Validate the K8S_MAX_CONCURRENT_PODS setting before it's
used: ensure the integer K8S_MAX_CONCURRENT_PODS is strictly greater than 0
(since it's passed to asyncio.Semaphore), and raise a clear ValueError (or
fallback to a safe default) if the value is <= 0 or not an int; update the
settings initialization/validation logic near the K8S_MAX_CONCURRENT_PODS
declaration and any config-loading function that constructs the Semaphore so the
check runs at startup.

Copy link

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

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

1 issue found across 9 files

Prompt for AI agents (all issues)

Check if these issues are valid — if so, understand the root cause of each and fix them.


<file name="backend/tests/e2e/test_k8s_worker_create_pod.py">

<violation number="1" location="backend/tests/e2e/test_k8s_worker_create_pod.py:29">
P2: Using `MagicMock(wraps=test_settings)` does not preserve attribute values; it returns MagicMocks for attributes, which breaks KubernetesWorker/metrics initialization and can enable OTLP exporting with an invalid endpoint. Use a real settings copy with an updated field instead of a MagicMock.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

@sonarqubecloud
Copy link

@HardMax71 HardMax71 merged commit ce257ce into main Jan 29, 2026
21 checks passed
@HardMax71 HardMax71 deleted the fix/k8s-worker branch January 29, 2026 00:21
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.

2 participants