Table of Contents
TTL Extension
TTL Extension Endpoint
The endpoint /api/environments/{environment_id}/extend-ttl
is implemented in blueberry/api/environments.py
. It handles:
* Validation: Ensures TTL is positive and not exceeding 8760 hours (1 year)
* Authorization: Only the environment creator can extend TTL
* Database Updates: Updates both ttl_hours and expires_at fields
* ArgoCD Sync: Updates the Helm values in the ArgoCD application
* Audit Logging: Creates detailed logs of the extension
* Notifications: Sends webhook notifications about the extension
How TTL Extension Works with Cleanup CronJob
The cleanup system is designed to work seamlessly with TTL extensions.
Cleanup CronJob Configuration
# From charts/blueberry/values.yaml
cleanup:
enabled: true
schedule: "0 */6 * * *" # Runs every 6 hours
expiredEnvironmentLimit: 50
How the Cleanup Process Works
- Finding Expired Environments: The cleanup job uses
EnvironmentStore.find_expired()
which queries:
query = query.where("expires_at", "<=", now)
query = query.where("status", "not-in", [TERMINATED, TERMINATING, TERMINATED_ERROR])
- TTL Extension Updates: When you extend TTL, the endpoint:
# Updates expires_at based on created_at + new TTL
environment.expires_at = environment.created_at + timedelta(hours=ttl_hours)
- Automatic Protection: Since
expires_at
is updated to a future time, the cleanup job will no longer find the environment as expired until the new expiry time is reached.
Key Benefits
- No Special Handling Needed: TTL extensions automatically work with the cleanup system
- Immediate Effect: Once TTL is extended, the environment is protected from the next cleanup cycle
- Audit Trail: All extensions are logged with detailed metadata
- ArgoCD Sync: The Helm values are updated so the environment itself knows about the new TTL
The cleanup CronJob simply looks for environments where expires_at <= now()
, so extending TTL by updating expires_at
to a future time automatically removes the environment from the cleanup eligibility list. It's a clean, race-condition-free design that works with the automated cleanup system.