Skip to content

feat: SHEK-16 — in-cluster Kubernetes auto-discovery from ConfigMap#29

Open
arieradle wants to merge 1 commit into
mainfrom
feat/shek-16
Open

feat: SHEK-16 — in-cluster Kubernetes auto-discovery from ConfigMap#29
arieradle wants to merge 1 commit into
mainfrom
feat/shek-16

Conversation

@arieradle
Copy link
Copy Markdown
Owner

Summary

  • New shekel/integrations/kubernetes.py module with is_k8s_environment(), apply_k8s_config(), and KubernetesPoller daemon thread
  • Budget._record_spend() raises BudgetExceededError immediately when _paused_externally is set by the poller
  • Budget.__exit__ / __aexit__ stop the poller on context exit
  • Adds [k8s] optional extra (kubernetes>=28.0) in pyproject.toml; included in [all]
  • 36 tests, 100% coverage on kubernetes.py

Test plan

  • pytest tests/test_kubernetes_integration.py — all 36 tests pass
  • pytest --cov=shekel --cov-report=term-missing — 100% coverage
  • Install without [k8s] extra and confirm no import errors

🤖 Generated with Claude Code

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
Copy link
Copy Markdown

codecov Bot commented Jun 4, 2026

Codecov Report

❌ Patch coverage is 99.09091% with 1 line in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
shekel/_budget.py 95.23% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

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.

1 participant