feat: SHEK-16 — in-cluster Kubernetes auto-discovery from ConfigMap#29
Open
arieradle wants to merge 1 commit into
Open
feat: SHEK-16 — in-cluster Kubernetes auto-discovery from ConfigMap#29arieradle wants to merge 1 commit into
arieradle wants to merge 1 commit into
Conversation
New module shekel/integrations/kubernetes.py:
- is_k8s_environment(): detects KUBERNETES_SERVICE_HOST + SHEKEL_BUDGET_NAME
- _fetch_configmap(): loads shekel-budget-{name} from the pod's namespace
via kubernetes.client.CoreV1Api; soft-imports kubernetes (no crash if absent)
- apply_k8s_config(): applies ConfigMap values to Budget fields where still
None (priority: explicit kwarg > AGENT_BUDGET_USD env var > ConfigMap)
- KubernetesPoller: daemon thread that polls paused key every
SHEKEL_POLL_INTERVAL_SECONDS (default 10s); sets _paused_externally
Budget._record_spend(): raises BudgetExceededError immediately when
_paused_externally is True (before spend accumulation).
Budget.__exit__ / __aexit__: stop the poller thread on context exit.
pyproject.toml: add [k8s] extra (kubernetes>=28.0); add to [all];
add kubernetes mypy override.
36 tests; 100% coverage on kubernetes.py.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
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
shekel/integrations/kubernetes.pymodule withis_k8s_environment(),apply_k8s_config(), andKubernetesPollerdaemon threadBudget._record_spend()raisesBudgetExceededErrorimmediately when_paused_externallyis set by the pollerBudget.__exit__/__aexit__stop the poller on context exit[k8s]optional extra (kubernetes>=28.0) inpyproject.toml; included in[all]kubernetes.pyTest plan
pytest tests/test_kubernetes_integration.py— all 36 tests passpytest --cov=shekel --cov-report=term-missing— 100% coverage[k8s]extra and confirm no import errors🤖 Generated with Claude Code