OpenStack Cron Cleanup #2020
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
| --- | |
| # SPDX-License-Identifier: Apache-2.0 | |
| # SPDX-FileCopyrightText: 2025 The Linux Foundation | |
| # OpenStack Cron Cleanup - Scheduled job | |
| # Cleans up orphaned resources on OpenStack cloud hourly | |
| # Uses repository variables for project-specific configuration | |
| name: OpenStack Cron Cleanup | |
| on: | |
| schedule: | |
| # Run every hour | |
| - cron: "0 * * * *" | |
| # Run smart cleanup on 1st of every month at 02:00 UTC | |
| - cron: "0 2 1 * *" | |
| workflow_dispatch: | |
| inputs: | |
| enable_debug: | |
| description: "Enable verbose debug logging" | |
| required: false | |
| default: false | |
| type: boolean | |
| openstack_cloud: | |
| description: "OpenStack cloud name from clouds.yaml" | |
| required: false | |
| default: "vex" | |
| type: string | |
| cleanup_k8s_clusters: | |
| description: "Enable K8s cluster cleanup" | |
| required: false | |
| default: true | |
| type: boolean | |
| enable_smart_cleanup: | |
| description: "Enable smart image cleanup (checks repo for unused images)" | |
| required: false | |
| default: false | |
| type: boolean | |
| cleanup_stacks: | |
| description: "Enable stack cleanup" | |
| required: false | |
| default: true | |
| type: boolean | |
| cleanup_servers: | |
| description: "Enable server cleanup" | |
| required: false | |
| default: true | |
| type: boolean | |
| cleanup_ports: | |
| description: "Enable port cleanup" | |
| required: false | |
| default: true | |
| type: boolean | |
| cleanup_volumes: | |
| description: "Enable volume cleanup" | |
| required: false | |
| default: true | |
| type: boolean | |
| protect_images: | |
| description: "Enable image protection" | |
| required: false | |
| default: true | |
| type: boolean | |
| cleanup_images: | |
| description: "Enable old image cleanup" | |
| required: false | |
| default: true | |
| type: boolean | |
| concurrency: | |
| group: openstack-cleanup-${{ github.run_id }} | |
| cancel-in-progress: false | |
| jobs: | |
| cloud-resource-cleanup: | |
| runs-on: ubuntu-latest | |
| timeout-minutes: 30 | |
| steps: | |
| - name: Determine cleanup mode | |
| id: cleanup-mode | |
| run: | | |
| # Smart cleanup runs on 1st of month (cron) or when manually enabled | |
| cron_schedule="${{ github.event.schedule }}" | |
| manual_enable="${{ inputs.enable_smart_cleanup }}" | |
| if [[ "$cron_schedule" == "0 2 1 * *" ]] || [[ "$manual_enable" == "true" ]]; then | |
| echo "smart_cleanup=true" >> "$GITHUB_OUTPUT" | |
| echo "Smart cleanup enabled (monthly schedule or manual)" | |
| else | |
| echo "smart_cleanup=false" >> "$GITHUB_OUTPUT" | |
| echo "Regular cleanup (hourly schedule)" | |
| fi | |
| - name: Run OpenStack cleanup | |
| id: cleanup | |
| uses: askb/openstack-cron-action@main | |
| with: | |
| enable_debug: ${{ inputs.enable_debug || 'false' }} | |
| openstack_cloud: ${{ inputs.openstack_cloud || vars.OPENSTACK_CLOUD || 'vex' }} | |
| # Use individual OpenStack credentials | |
| openstack_auth_url: ${{ secrets.OPENSTACK_AUTH_URL }} | |
| openstack_username: ${{ secrets.OPENSTACK_USERNAME }} | |
| openstack_password: ${{ secrets.OPENSTACK_PASSWORD }} | |
| openstack_project_id: ${{ secrets.OPENSTACK_PROJECT_ID }} | |
| openstack_domain_name: ${{ secrets.OPENSTACK_DOMAIN_NAME }} | |
| openstack_region: ${{ secrets.OPENSTACK_REGION }} | |
| jenkins_urls: ${{ vars.JENKINS_URLS || '' }} | |
| cleanup_k8s_clusters: ${{ inputs.cleanup_k8s_clusters || 'true' }} | |
| cleanup_stacks: ${{ inputs.cleanup_stacks || 'true' }} | |
| cleanup_servers: ${{ inputs.cleanup_servers || 'true' }} | |
| cleanup_ports: ${{ inputs.cleanup_ports || 'true' }} | |
| cleanup_volumes: ${{ inputs.cleanup_volumes || 'true' }} | |
| protect_images: ${{ inputs.protect_images || 'true' }} | |
| cleanup_images: ${{ inputs.cleanup_images || 'true' }} | |
| cleanup_images_smart: ${{ steps.cleanup-mode.outputs.smart_cleanup }} | |
| image_cleanup_age: "180" | |
| python_version: "3.11" | |
| failure_notification_email: > | |
| ${{ vars.FAILURE_NOTIFICATION_EMAIL || '' }} | |
| failure_notification_prefix: > | |
| ${{ vars.NOTIFICATION_PREFIX || '[OpenStack Cleanup]' }} | |
| - name: Report cleanup summary | |
| if: always() | |
| run: | | |
| { | |
| echo "### OpenStack Cleanup Summary" | |
| echo "- **Cloud**: ${{ inputs.openstack_cloud || vars.OPENSTACK_CLOUD || 'vex' }}" | |
| echo "- **Status**: ${{ job.status }}" | |
| echo "- **Timestamp**: $(date -u '+%Y-%m-%d %H:%M:%S UTC')" | |
| } >> "$GITHUB_STEP_SUMMARY" | |
| - name: Send failure notification | |
| if: > | |
| failure() && | |
| steps.cleanup.conclusion == 'failure' && | |
| vars.FAILURE_NOTIFICATION_EMAIL != '' | |
| uses: dawidd6/action-send-mail@6063705cefe50cb915fc53bb06d4049cae2953b2 # v3.12.0 | |
| with: | |
| server_address: smtp.gmail.com | |
| server_port: 587 | |
| username: ${{ secrets.SMTP_USERNAME }} | |
| password: ${{ secrets.SMTP_PASSWORD }} | |
| subject: > | |
| ${{ vars.NOTIFICATION_PREFIX || '[OpenStack Cleanup]' }} | |
| ${{ github.repository }} - Build #${{ github.run_number }} - FAILED | |
| to: ${{ vars.FAILURE_NOTIFICATION_EMAIL }} | |
| from: GitHub Actions <[email protected]> | |
| body: | | |
| OpenStack Cleanup Job Failed | |
| Repository: ${{ github.repository }} | |
| Workflow: ${{ github.workflow }} | |
| Run Number: ${{ github.run_number }} | |
| Run ID: ${{ github.run_id }} | |
| Cloud: ${{ inputs.openstack_cloud || vars.OPENSTACK_CLOUD || 'vex' }} | |
| Please refer to the logs for details: | |
| ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }} | |
| Timestamp: ${{ github.event.head_commit.timestamp }} |