feat(environments): validate environment limits in webapp, worker and…#86
Merged
feat(environments): validate environment limits in webapp, worker and…#86
Conversation
… cron Environment settings are stored per environment (single JSON row). Limits (CPU, memory, max_pods) are read via EnvironmentSettingsRepository and normalized with get_environment_limits_from_settings(); validation is centralized in validate_webapp_settings_against_environment_limits() (webapp_validators), reused by webapp, worker and cron. Implementation: - Services receive an optional EnvironmentSettingsRepository; when present, create/update fetches settings by environment_id, builds limits from the JSON, and runs the validator before any cluster selection or persistence. - Validation runs before get_cluster_for_instance so invalid payloads fail fast and tests do not depend on cluster selection. - Handlers inject the repository and map EnvironmentSettingsValidationError to 400 with a clear message. - Cron has no autoscaling; validator is called with autoscaling_min=1, autoscaling_max=1 so only CPU/memory and a single-pod cap apply. Tests use a mock settings row (SimpleNamespace with a real settings list) so the validator runs; unit tests assert the exception, integration tests assert 400 on over-limit POSTs. EnvironmentSettings model uses JSONBCompat for SQLite-friendly integration tests.
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.
Description
Adds environment limits validation for webapp, worker and cron on create/update. Environment settings are stored per environment (single JSON row). Limits (CPU, memory, max pods) are loaded via
EnvironmentSettingsRepository, normalized withget_environment_limits_from_settings(), and enforced byvalidate_webapp_settings_against_environment_limits()inwebapp_validators, reused by all three components.Implementation:
EnvironmentSettingsRepository; when provided, create/update loads settings byenvironment_id, builds limits from the JSON, and runs the validator before cluster selection or persistence.get_cluster_for_instanceso invalid payloads fail fast and unit tests do not depend on cluster selection.EnvironmentSettingsValidationErrorto 400 with a clear message.autoscaling_min=1,autoscaling_max=1so only CPU, memory and a single-pod cap apply.Other changes:
EnvironmentSettingsmodel usesJSONBCompat(JSONB on PostgreSQL, JSON on SQLite) for SQLite-friendly integration tests.IdentityProviderResponseDTO migrated from Pydanticclass ConfigtoConfigDict(deprecation fix).main.py, ruff formatting.Related Issue
Closes #
Type of Change
Component Affected
Checklist
General
Testing
Documentation
Screenshots (if applicable)
N/A — backend-only changes.
Test Plan
pytest api/tests/unit/test_webapp_service.py api/tests/unit/test_worker_service.py api/tests/unit/test_cron_service.py— tests that exceed CPU, memory or replica limits expectEnvironmentSettingsValidationError.Additional Notes
settings_repositoryis not injected (e.g. legacy callers), validation is skipped and behavior remains as before.