2022-07-13 08:04:46 -04:00
|
|
|
name: Constellation destroy
|
2022-05-03 05:15:53 -04:00
|
|
|
description: "Destroy a running Constellation cluster."
|
2022-10-27 10:57:54 -04:00
|
|
|
|
2022-11-09 04:28:34 -05:00
|
|
|
inputs:
|
|
|
|
kubeconfig:
|
|
|
|
description: "The kubeconfig for the cluster."
|
|
|
|
required: true
|
2023-12-15 04:37:29 -05:00
|
|
|
clusterCreation:
|
2024-02-01 09:05:07 -05:00
|
|
|
description: "How the infrastructure for the e2e test was created. One of [cli, terraform]."
|
2023-12-15 04:37:29 -05:00
|
|
|
default: "cli"
|
2023-11-14 07:25:52 -05:00
|
|
|
gcpClusterDeleteServiceAccount:
|
|
|
|
description: "Service account with permissions to delete a Constellation cluster on GCP."
|
|
|
|
required: true
|
|
|
|
azureClusterDeleteCredentials:
|
|
|
|
description: "Azure credentials authorized to delete a Constellation cluster."
|
|
|
|
required: true
|
|
|
|
cloudProvider:
|
|
|
|
description: "Either 'aws', 'azure' or 'gcp'."
|
|
|
|
required: true
|
2022-11-09 04:28:34 -05:00
|
|
|
|
2022-05-03 05:15:53 -04:00
|
|
|
runs:
|
2022-10-27 10:57:54 -04:00
|
|
|
using: "composite"
|
2022-05-03 05:15:53 -04:00
|
|
|
steps:
|
2022-11-09 04:28:34 -05:00
|
|
|
- name: Delete persistent volumes
|
|
|
|
if: inputs.kubeconfig != ''
|
2022-10-27 10:57:54 -04:00
|
|
|
shell: bash
|
2024-03-19 09:53:58 -04:00
|
|
|
continue-on-error: true
|
2022-11-09 04:28:34 -05:00
|
|
|
env:
|
|
|
|
KUBECONFIG: ${{ inputs.kubeconfig }}
|
|
|
|
PV_DELETION_TIMEOUT: "120" # 2 minutes timeout for pv deletion
|
2022-10-27 10:57:54 -04:00
|
|
|
run: |
|
|
|
|
ELAPSED=0
|
|
|
|
echo "::group::Wait for PV deletion"
|
2022-11-09 04:28:34 -05:00
|
|
|
|
|
|
|
# Scrap namespaces that contain PVCs
|
|
|
|
for namespace in `kubectl get namespace --no-headers=true -o custom-columns=":metadata.name"`; do
|
2022-12-09 05:51:38 -05:00
|
|
|
if [[ `kubectl get pvc -n $namespace --no-headers=true -o custom-columns=":metadata.name" | wc -l` -gt 0 ]]; then
|
2024-03-19 09:53:58 -04:00
|
|
|
if [[ "${namespace}" == "default" ]]; then
|
|
|
|
kubectl delete all --all --namespace "default" --wait
|
|
|
|
continue
|
|
|
|
fi
|
|
|
|
if [[ "${namespace}" == "kube-system" ]]; then
|
|
|
|
kubectl delete pvc --all --namespace "kube-system" --wait
|
|
|
|
continue
|
|
|
|
fi
|
2022-11-09 04:28:34 -05:00
|
|
|
kubectl delete namespace $namespace --wait
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
2022-12-09 05:51:38 -05:00
|
|
|
until [[ "$(kubectl get pv -o json | jq '.items | length')" == "0" ]] || [[ $ELAPSED -gt $PV_DELETION_TIMEOUT ]];
|
2022-10-27 10:57:54 -04:00
|
|
|
do
|
2022-11-09 04:28:34 -05:00
|
|
|
echo $(kubectl get pv -o json | jq '.items | length') PV remaining..
|
|
|
|
sleep 1
|
|
|
|
ELAPSED=$((ELAPSED+1))
|
2022-10-27 10:57:54 -04:00
|
|
|
done
|
2022-12-09 05:51:38 -05:00
|
|
|
if [[ $ELAPSED -gt $PV_DELETION_TIMEOUT ]]; then
|
2022-11-09 04:28:34 -05:00
|
|
|
echo "Timed out waiting for PV deletion.."
|
|
|
|
exit 1
|
2022-10-27 10:57:54 -04:00
|
|
|
fi
|
|
|
|
echo "::endgroup::"
|
|
|
|
|
2023-11-14 07:25:52 -05:00
|
|
|
- name: Login to GCP (Cluster service account)
|
|
|
|
if: inputs.cloudProvider == 'gcp'
|
|
|
|
uses: ./.github/actions/login_gcp
|
|
|
|
with:
|
|
|
|
service_account: ${{ inputs.gcpClusterDeleteServiceAccount }}
|
|
|
|
|
|
|
|
- name: Login to AWS (Cluster role)
|
|
|
|
if: inputs.cloudProvider == 'aws'
|
2024-02-21 09:29:06 -05:00
|
|
|
uses: aws-actions/configure-aws-credentials@e3dd6a429d7300a6a4c196c26e071d42e0343502 # v4.0.2
|
2023-11-14 07:25:52 -05:00
|
|
|
with:
|
|
|
|
role-to-assume: arn:aws:iam::795746500882:role/GithubActionsE2ECluster
|
|
|
|
aws-region: eu-central-1
|
|
|
|
# extend token expiry to 6 hours to ensure constellation can terminate
|
|
|
|
role-duration-seconds: 21600
|
|
|
|
|
|
|
|
- name: Login to Azure (Cluster service principal)
|
|
|
|
if: inputs.cloudProvider == 'azure'
|
|
|
|
uses: ./.github/actions/login_azure
|
|
|
|
with:
|
|
|
|
azure_credentials: ${{ inputs.azureClusterDeleteCredentials }}
|
|
|
|
|
2022-10-27 10:57:54 -04:00
|
|
|
- name: Constellation terminate
|
|
|
|
shell: bash
|
2023-04-28 05:25:45 -04:00
|
|
|
run: |
|
2023-08-16 05:34:58 -04:00
|
|
|
constellation terminate --yes --tf-log=DEBUG
|