ci: tear-down PR dev cluster and children #1
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
| name: PR Workflow | |
| on: | |
| pull_request: | |
| types: | |
| - synchronize | |
| - closed | |
| defaults: | |
| run: | |
| working-directory: go/src/github.com/stackrox/infra | |
| concurrency: pr-${{ github.ref }} | |
| env: | |
| CLUSTER_NAME: infra-pr-${{ github.event.pull_request.number }} | |
| GH_TOKEN: ${{ secrets.RHACS_BOT_GITHUB_TOKEN }} | |
| jobs: | |
| destroy: | |
| runs-on: ubuntu-latest | |
| env: | |
| KUBECONFIG: /tmp/kubeconfig | |
| INFRA_TOKEN: ${{ secrets.INFRA_TOKEN }} | |
| INFRACTL: bin/infractl -k -e localhost:8443 | |
| USE_GKE_GCLOUD_AUTH_PLUGIN: "True" | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| ref: ${{ github.event.pull_request.head.sha }} | |
| path: go/src/github.com/stackrox/infra | |
| - name: Download production infractl | |
| uses: stackrox/actions/infra/install-infractl@v1 | |
| - name: Download artifacts | |
| run: | | |
| ~/.local/bin/infractl artifacts "$CLUSTER_NAME" -d /tmp/ >> "$GITHUB_STEP_SUMMARY" | |
| kubectl get nodes -o wide || true | |
| - name: Download branch infractl | |
| run: | | |
| kubectl -n infra port-forward svc/infra-server-service 8443:8443 > /dev/null 2>&1 & | |
| sleep 10 | |
| kubectl -n infra logs -l app=infra-server --tail=-1 | |
| make pull-infractl-from-dev-server | |
| kill %1 | |
| - name: Destroy created clusters still running | |
| run: | | |
| kubectl -n infra port-forward svc/infra-server-service 8443:8443 > /dev/null 2>&1 & | |
| sleep 10 | |
| $INFRACTL version | |
| echo 'For 30 minutes, list and delete child clusters that are not failed.' | |
| for I in {1..30}; do | |
| if [[ $($INFRACTL list --all --expired --status='READY,CREATING,DESTROYING' | tee >(cat >&2) | wc -l) -gt 0 ]]; then | |
| echo 'Active clusters found. Deleting ...' | |
| else | |
| echo 'No active clusters found.' | |
| break | |
| fi | |
| # shellcheck disable=SC2086 | |
| $INFRACTL list --all --expired --status='READY,FAILED,CREATING' | grep '^[^ ]' \ | |
| | xargs -I{} $INFRACTL delete {} | |
| echo "(sleep 1 minute then check again. try $I/30)" | |
| sleep 60 | |
| done | |
| kill %1 | |
| - name: Destroy PR dev cluster | |
| run: | | |
| ~/.local/bin/infractl delete "$CLUSTER_NAME" | |