Delete Orphan DNS Records
Celery task that deletes the orphaned DNS records of deleted LLMClients.
Deploying an LLMClient creates an A record for its default host, e.g.
example.3141-5926-5359.api.example.com, in the zone of the environment’s API domain.
Deleting the LLMClient should delete the record, but a record outlives its LLMClient when the
deletion’s task fails or never runs. This task, which Celery Beat runs daily, finds those orphans
and deletes them.
Main Tasks
delete_orphan_dns_records(dry_run): Delete the A records of hosts that no LLMClient or LLMHost uses.
Safety
The task deletes real DNS records, so it is conservative:
It runs only in the AWS environments, e.g.
alphaandprod. Elsewhere, the API domain is a proxy domain that every developer’s local environment shares, and a local database does not know the others’ LLMClients.It looks only in the zone of this environment’s API domain, and only at A records whose name is exactly
<label>.<account number>.<API domain>: the shape of an LLMClient’s default host. Another environment’s hosts, e.g.example.3141-5926-5359.alpha.api.example.comin the zone ofapi.example.com, have more labels, and are never touched.A host that any LLMClient or LLMHost uses is live, whether or not it is deployed. LLMHost Ingresses have hosts of the same shape, in the same zone.
It deletes nothing if the database has no LLMClients, or if a live host cannot be computed, because every record would then look orphaned.
It deletes at most
MAX_DELETIONS_PER_RUNrecords per run.
Usage
Queue the Celery task, or call it directly to run it synchronously:
delete_orphan_dns_records.delay() delete_orphan_dns_records(dry_run=True)
python manage.py delete_orphan_dns_records --dry-run lists the orphans without deleting them.
- smarter.apps.llmclient.tasks.delete_orphan_dns_records.MAX_DELETIONS_PER_RUN = 50
The most records that one run deletes.
The rest are deleted by the next runs.
- exception smarter.apps.llmclient.tasks.delete_orphan_dns_records.OrphanDNSRecordsError[source]
Bases:
ExceptionThe live hosts could not be determined, so no record can be judged orphaned.
- smarter.apps.llmclient.tasks.delete_orphan_dns_records.live_hosts()[source]
Return the hosts that existing LLMClients and LLMHosts use, deployed or not.
- Return type:
- Returns:
The hosts, normalized, e.g.
example.3141-5926-5359.api.example.com.- Raises:
OrphanDNSRecordsError – If there are no LLMClients, or a host cannot be computed.