|
| 1 | +# Renku CI Deployment Cleanup |
| 2 | + |
| 3 | +A Kubernetes-based CI deployment cleanup system that uses a Helm chart to deploy automated cleanup of old Renku CI deployments. This system runs as a CronJob that leverages the `rdu` tool for comprehensive cleanup. |
| 4 | + |
| 5 | +## Installation |
| 6 | + |
| 7 | +Install the Helm chart: |
| 8 | +```bash |
| 9 | +helm install renku-ci-cleanup ./helm-chart |
| 10 | +``` |
| 11 | + |
| 12 | +## Exemption |
| 13 | + |
| 14 | +Namespaces can be exempted from cleanup by adding the label `renku.io/cleanup-exempt: "true"` to the namespace. |
| 15 | + |
| 16 | +## How It Works |
| 17 | + |
| 18 | +1. The CronJob runs on the specified schedule (default: every 6 hours) |
| 19 | +2. It queries Kubernetes for ALL namespaces in the cluster |
| 20 | +3. For each namespace found: |
| 21 | + - Checks if the namespace has the exemption label (if so, skips it) |
| 22 | + - Checks if the namespace name matches any of the configured patterns (if enforcement is enabled) |
| 23 | + - Calculates the age based on the namespace creation timestamp |
| 24 | + - Checks GitHub PR status for PR-based cleanup (if enabled) |
| 25 | + - If the namespace is older than the configured threshold AND matches the naming patterns AND is not exempt, it uses `rdu cleanup-deployment` to: |
| 26 | + - Delete all sessions |
| 27 | + - Uninstall all Helm releases |
| 28 | + - Delete all jobs and PVCs |
| 29 | + - Delete the entire namespace |
| 30 | +4. Logging shows what actions were taken, including exemption and pattern matching results |
| 31 | + |
| 32 | +## Key Configuration |
| 33 | + |
| 34 | +The main configuration options in `values.yaml`: |
| 35 | + |
| 36 | +- `cleanup.maxAge`: Maximum age in hours before cleanup (default: 720 hours / 30 days) |
| 37 | +- `cleanup.dryRun`: Enable dry-run mode (default: false) |
| 38 | +- `cleanup.namespacePatterns`: List of regex patterns for namespace names |
| 39 | +- `cleanup.enforceNamePatterns`: Enable strict pattern matching (default: true) |
| 40 | +- `cleanup.prCleanup.enabled`: Enable GitHub PR-based cleanup (default: false) |
| 41 | +- `cronJob.schedule`: Cron schedule (default: "0 */6 * * *" - every 6 hours) |
| 42 | + |
| 43 | +## PR-Based Cleanup |
| 44 | + |
| 45 | +The system supports GitHub PR-based cleanup that can automatically clean up namespaces when their associated pull requests are closed or merged. This feature requires: |
| 46 | + |
| 47 | +- `cleanup.prCleanup.enabled: true` |
| 48 | +- GitHub API token configured |
| 49 | +- Repository mappings in `cleanup.prCleanup.repositories` |
| 50 | + |
| 51 | +Example configuration maps namespace patterns to GitHub repositories and PR numbers. |
0 commit comments