refactor(k8s): decompose kubernetes.py into focused mixin modules#120
Open
refactor(k8s): decompose kubernetes.py into focused mixin modules#120
Conversation
Split the 3,535-line kubernetes.py into 6 focused files using the mixin pattern (same approach as existing KubernetesLauncherMixin): - kubernetes.py (779 lines): core lifecycle (init, validate, prepare, deploy, monitor, cleanup) - k8s_results.py (1,390 lines): results collection, PVC artifacts, perf CSV reporting - k8s_template_context.py (856 lines): Jinja2 context, env vars, data config, tools - k8s_scripts.py (352 lines): script/tool loading for ConfigMap embedding - k8s_pvc.py (239 lines): PVC lifecycle management All 426 unit tests and 139 integration tests pass unchanged. Co-Authored-By: Claude Opus 4 <noreply@anthropic.com>
Remove unused imports (re, sanitize_k8s_container_name), fix blank lines before nested class methods, and strip trailing whitespace. Co-Authored-By: Claude Opus 4 <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
Refactors the Kubernetes deployment implementation by decomposing the previously monolithic kubernetes.py into focused mixin modules, keeping the public deployment API intact while improving navigability and separation of concerns.
Changes:
- Split Kubernetes deployment responsibilities into new mixins for PVC lifecycle, script/tool bundling, template context building, and results collection/reporting.
- Updated
KubernetesDeploymentto compose these mixins while leaving core lifecycle methods inkubernetes.py. - Reduced
kubernetes.pyto primarily orchestration logic (init/validate/prepare/deploy/monitor/cleanup).
Reviewed changes
Copilot reviewed 4 out of 5 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
src/madengine/deployment/kubernetes.py |
Switches KubernetesDeployment to a mixin-based composition and removes inlined implementations moved to mixin modules. |
src/madengine/deployment/k8s_template_context.py |
New mixin for building the Jinja2 template context, env var merging, data config, and tools config enrichment. |
src/madengine/deployment/k8s_scripts.py |
New mixin for bundling common scripts/tool wrappers (and Primus overlays) into ConfigMaps. |
src/madengine/deployment/k8s_results.py |
New mixin for pod log/PVC artifact collection, performance parsing/aggregation, and perf reporting outputs. |
src/madengine/deployment/k8s_pvc.py |
New mixin for results/data PVC storage class resolution and PVC create/delete workflows. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
386
to
388
| # Delete existing collector pod (must be done before PVC to allow PVC deletion) | ||
| collector_pod_name = f"collector-{self.job_name}" | ||
| try: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Motivation
kubernetes.py had grown to 3,535 lines with 40+ methods spanning 5+ distinct responsibilities, making it difficult to navigate and review. The largest single method
(_prepare_template_context) was 538 lines.
New modules
MRO
KubernetesDeployment → KubernetesLauncherMixin → KubernetesResultsMixin
→ KubernetesTemplateContextMixin → KubernetesScriptsMixin
→ KubernetesPVCMixin → BaseDeployment → ABC → object
Test plan