Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix e2e-infra-cleanup workflow #4177

Merged
merged 3 commits into from
Nov 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions .github/workflows/e2e-infra-cleanup.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,16 @@ jobs:
- name: Get automation workspaces
id: get-workspaces
run: |
mapfile -t WORKSPACES < <(terraform workspace list | grep -o 'automation-\w*')
# automation workspace name is in the format automation-<id/sha>-<timestamp>
mapfile -t WORKSPACES < <(terraform workspace list | grep -o 'automation-.*')
declare -a EXPIRED_WORKSPACES
for workspace in "${WORKSPACES[@]}"; do
COMPLETION=$(date -d "$(TF_WORKSPACE="${workspace}" terraform output -no-color -raw completion_timestamp)" +%s) || continue
COMPLETION=$(echo "$workspace" | grep -o '[^-]*$' | grep -o '[0-9]*$')
if [ -z "$COMPLETION" ]; then
echo "Failed to parse completion date from workspace $workspace, adding to list of expired workspaces"
EXPIRED_WORKSPACES+=("${workspace}")
continue
fi
[ $(($(date +%s) - COMPLETION)) -gt $((60 * 60 * CLEANUP_INTERVAL_HOURS)) ] && EXPIRED_WORKSPACES+=("${workspace}")
done
echo "workspaces=$(printf '%s\n' "${EXPIRED_WORKSPACES[@]}" | head -c -1 | jq -R . | jq -sc .)" >> "$GITHUB_OUTPUT"
Expand Down
27 changes: 23 additions & 4 deletions .github/workflows/regression.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,28 @@ env:
AWS_ACCESS_KEY_ID: ${{ secrets.E2E_TESTIM_AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.E2E_TESTIM_AWS_SECRET_ACCESS_KEY }}
TF_VAR_testim_token: ${{ secrets.TESTIM_ACCESS_TOKEN }}
WORKSPACE: automation-${{ github.event.inputs.id || inputs.id }}

jobs:
get-workspace-name:
runs-on: ubuntu-latest
outputs:
name: ${{ steps.workspace.outputs.name }}
env:
WORKSPACE_PREFIX: automation-${{ github.event.inputs.id || inputs.id }}
steps:
- name: Set the workspace name as output
id: workspace
run: |
CURRENT_TIMESTAMP=$(date +%s)
echo "name=${{ env.WORKSPACE_PREFIX }}-${CURRENT_TIMESTAMP}" >> "$GITHUB_OUTPUT"

jumpbox:
needs: get-workspace-name
runs-on: ubuntu-20.04
container:
image: hashicorp/terraform:1.0.11
env:
WORKSPACE: ${{ needs.get-workspace-name.outputs.name }}
steps:
- name: Checkout
uses: actions/checkout@v4
Expand Down Expand Up @@ -116,10 +131,12 @@ jobs:
SLACK_WEBHOOK_URL: ${{ secrets.KOTS_BUILD_STATUS_SLACK_WEBHOOK_URL }}

tests:
needs: jumpbox
needs: [get-workspace-name, jumpbox]
runs-on: ubuntu-20.04
container:
image: hashicorp/terraform:1.0.11
env:
WORKSPACE: ${{ needs.get-workspace-name.outputs.name }}
strategy:
fail-fast: false
matrix:
Expand Down Expand Up @@ -263,13 +280,15 @@ jobs:
SLACK_WEBHOOK_URL: ${{ secrets.KOTS_BUILD_STATUS_SLACK_WEBHOOK_URL }}
MATRIX_CONTEXT: ${{ toJson(matrix) }}
cleanup:
needs: tests
needs: [get-workspace-name, tests]
runs-on: ubuntu-20.04
env:
WORKSPACE: ${{ needs.get-workspace-name.outputs.name }}
steps:
- name: Trigger workspace cleanup
uses: peter-evans/repository-dispatch@v2
with:
token: ${{ secrets.E2E_GH_PAT }}
repository: replicatedhq/kots
event-type: e2e-workspace-cleanup
client-payload: '{"workspace": "automation-${{ github.event.inputs.id || inputs.id }}"}'
client-payload: '{"workspace": "${{ env.WORKSPACE }}"}'
Loading