This guide assumes familiarity with Kubernetes and an existing CMMS instance with a Kingdom deployed locally or through GKE.See the Local Kubernetes Configuration or Kingdom Deployment Guide for setup instructions.
Retention Policy CronJobs
Retention policies are enforced through configured CronJobs that are enabled by default on Kingdom deployments.Viewing Configured CronJobs
List all retention policy CronJobs:Understanding the Schedule
TheSCHEDULE column uses Cron syntax to specify execution frequency:
15 * * * *- Runs hourly at 15 minutes past the hour40 6 * * *- Runs daily at 6:40 AM45 * * * *- Runs hourly at 45 minutes past the hour
Configuration Flags
Each CronJob has two primary configuration flags:| Flag | Purpose | Values |
|---|---|---|
--dry-run | Controls whether operations are executed or just logged | true (log only) or false (execute) |
--time-to-live / --days-to-live | How long a resource must be in a state before the retention operation applies | Duration (e.g., 7d) or integer (days) |
Kingdom Retention CronJobs
The Kingdom deployment includes three retention policy CronJobs:completed-measurements-deletion-cronjob
completed-measurements-deletion-cronjob
Purpose: Deletes measurements in terminal states after a specified time.Behavior: Measurements are deleted if:This configuration deletes completed measurements that haven’t been updated in 30 days.
- They are in a terminal state (SUCCEEDED, FAILED, or CANCELLED)
- The time since their last update exceeds the
--time-to-liveduration
exchanges-deletion-cronjob
exchanges-deletion-cronjob
Purpose: Deletes exchanges after a specified number of days.Behavior: Exchanges are deleted if:This configuration deletes exchanges older than 90 days from their exchange date.
- The days since their exchange date exceeds
--days-to-live
pending-measurements-cancellation-cronjob
pending-measurements-cancellation-cronjob
Purpose: Cancels measurements that remain in non-terminal states too long.Behavior: Measurements are transitioned to CANCELLED state if:This configuration cancels measurements that have been pending for more than 7 days.
- They are in a non-terminal state (PENDING, RUNNING, etc.)
- The time since their creation exceeds the
--time-to-liveduration
Modifying Retention CronJobs
Important: Modifications to a CronJob only affect future Jobs. Currently running Jobs will not be updated.
Interactive Editing
Usekubectl edit to modify a CronJob interactively:
Configuration Paths
When editing, modify these paths in theCronJobSpec:
Non-Interactive Patching
For automated updates, usekubectl patch:
Duration Format Reference
The--time-to-live flag uses human-readable duration format consisting of a sequence of decimal numbers with unit suffixes:
| Suffix | Unit | Example |
|---|---|---|
d | Days | 7d = 7 days |
h | Hours | 24h = 24 hours |
m | Minutes | 30m = 30 minutes |
s | Seconds | 60s = 60 seconds |
ms | Milliseconds | 500ms = 500 milliseconds |
ns | Nanoseconds | 1000ns = 1000 nanoseconds |
Examples
Best Practices
Monitoring Retention Jobs
- Check CronJob execution history:
kubectl get jobs - View job logs:
kubectl logs job/<job-name> - Monitor deleted resource counts in job output
- Set up alerts for failed retention jobs
Troubleshooting
CronJob not running
CronJob not running
Check if the CronJob is suspended:If
true, resume it:Retention job failing
Retention job failing
View the job logs:Common issues:
- Insufficient permissions (RBAC)
- Database connection errors
- Invalid duration format
Verifying deletions
Verifying deletions
Check if resources are being deleted:Look for deletion counts in the job output.