-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
EL-1621 delete old helm deployments (#307)
- Loading branch information
Showing
2 changed files
with
117 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
name: "Delete UAT deployment" | ||
description: 'Deletes a UAT deployment with a name that matches the merged or closed branch' | ||
inputs: | ||
k8s_cluster: | ||
description: "Kubernetes cluster name" | ||
required: true | ||
k8s_cluster_cert: | ||
description: "Kubernetes cluster certificate" | ||
required: true | ||
k8s_namespace: | ||
description: "Kubernetes cluster namespace" | ||
required: true | ||
k8s_token: | ||
description: "Kubernetes authentication token" | ||
required: true | ||
branch_name: | ||
description: "Optional branch name - inferred if not given" | ||
required: false | ||
outputs: | ||
branch-name: | ||
description: "Extracted branch name" | ||
value: ${{ steps.extract_branch.outputs.branch }} | ||
release-name: | ||
description: "Extracted release name" | ||
value: ${{ steps.extract_release.outputs.release }} | ||
delete-message: | ||
description: "Extracted delete message" | ||
value: ${{ steps.delete_release.outputs.message }} | ||
|
||
runs: | ||
using: "composite" | ||
steps: | ||
- name: Extract branch name | ||
id: extract_branch | ||
shell: bash | ||
env: | ||
BRANCH_NAME: ${{ inputs.branch_name || 'not_given' }} | ||
run: | | ||
if [ $BRANCH_NAME == "not_given" ] | ||
then | ||
if [ $GITHUB_EVENT_NAME == "pull_request" ] | ||
then | ||
branch=$GITHUB_HEAD_REF | ||
else | ||
branch=${GITHUB_REF#refs/heads/} | ||
fi | ||
else | ||
branch=$BRANCH_NAME | ||
fi | ||
echo "branch=$branch" >> $GITHUB_OUTPUT | ||
- name: Extract release name | ||
id: extract_release | ||
shell: bash | ||
run: | | ||
branch=${{ steps.extract_branch.outputs.branch }} | ||
truncated_branch=$(echo $branch | tr '[:upper:]' '[:lower:]' | sed 's:^\w*\/::' | tr -s ' _/[]().' '-' | cut -c1-18 | sed 's/-$//') | ||
echo "release=$truncated_branch" >> $GITHUB_OUTPUT | ||
- name: Authenticate to the cluster | ||
id: authenticate_to_cluster | ||
shell: bash | ||
env: | ||
K8S_CLUSTER: ${{ inputs.k8s_cluster }} | ||
K8S_CLUSTER_CERT: ${{ inputs.k8s_cluster_cert }} | ||
K8S_NAMESPACE: ${{ inputs.k8s_namespace }} | ||
K8S_TOKEN: ${{ inputs.k8s_token }} | ||
run: | | ||
echo "${K8S_CLUSTER_CERT}" > ./ca.crt | ||
kubectl config set-cluster ${K8S_CLUSTER} --certificate-authority=./ca.crt --server=https://${K8S_CLUSTER} | ||
kubectl config set-credentials circleci --token=${K8S_TOKEN} | ||
kubectl config set-context ${K8S_CLUSTER} --cluster=${K8S_CLUSTER} --user=circleci --namespace=${K8S_NAMESPACE} | ||
kubectl config use-context ${K8S_CLUSTER} | ||
- name: Delete UAT release | ||
id: delete_release | ||
shell: bash | ||
run: | | ||
release_name=${{ steps.extract_release.outputs.release }} | ||
found=$(helm list --all | grep $release_name || [[ $? == 1 ]]) | ||
if [[ ! -z "$found" ]] | ||
then | ||
helm delete $release_name | ||
kubectl delete pvc data-$release_name-postgresql-0 | ||
echo "message=\"Deleted UAT release ${release_name}\"" >> $GITHUB_OUTPUT | ||
else | ||
echo "message=\"UAT release, ${release_name}, not found\"" >> $GITHUB_OUTPUT | ||
fi |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
name: Delete UAT release | ||
|
||
# This is a GitHub action because Circle:CI doesn't see PR closed events | ||
# but they are available to actions | ||
on: | ||
# pull_request_target runs even when PRs have conflicts - pull_request does not | ||
# here we just want to tidy up regardless of the state of the PR. | ||
pull_request_target: | ||
types: | ||
- closed | ||
|
||
jobs: | ||
delete_uat_job: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Delete from UAT namespace | ||
id: delete_uat | ||
uses: ./.github/actions/delete-uat-release | ||
with: | ||
k8s_cluster: ${{ secrets.AUTOGENERATED_FALA_STAGING_K8S_CLUSTER_NAME }} | ||
k8s_cluster_cert: ${{ secrets.AUTOGENERATED_FALA_STAGING_K8S_CLUSTER_CERT }} | ||
k8s_namespace: ${{ secrets.AUTOGENERATED_FALA_STAGING_K8S_NAMESPACE }} | ||
k8s_token: ${{ secrets.AUTOGENERATED_FALA_STAGING_K8S_TOKEN }} | ||
- name: Result | ||
shell: bash | ||
run: echo ${{ steps.delete_uat.outputs.delete-message }}\ |