-
Notifications
You must be signed in to change notification settings - Fork 108
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This change moves the cleanup of clusters into a dedicated Github Actions workflow executed when a PR is completed (either through a merge or by being closed), allowing failed end-to-end test runs to be inspected. The actual cleanup is carried out by a small script that we bundle with the runner image (as that one already comes with doctl). It depends on clusters having been tagged with a branch identifier, for which we leverage the cluster name suffix already employed to guarantee unique cluster names.
- Loading branch information
Timo Reimann
committed
Sep 24, 2020
1 parent
565c9da
commit c086f6c
Showing
5 changed files
with
75 additions
and
2 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,25 @@ | ||
name: cleanup-clusters | ||
|
||
env: | ||
DOCKER_ORG: digitalocean | ||
|
||
on: | ||
pull_request: | ||
types: [closed] | ||
|
||
jobs: | ||
cleanup-clusters: | ||
name: Clean up clusters from the PR | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: cleanup | ||
env: | ||
DIGITALOCEAN_ACCESS_TOKEN: ${{ secrets.CSIDigitalOceanAccessToken }} | ||
BRANCH: ${{ github.head_ref }} | ||
run: | | ||
set -eu | ||
# Variable definitions and runner image must match things in test.yaml. | ||
BRANCH="$(echo -n ${BRANCH} | tr -c '[:alnum:]._-' '-')" | ||
TAG_IDENTIFIER="$(echo -n ${BRANCH} | sha256sum | cut -c1-7)" | ||
docker run --rm -e DIGITALOCEAN_ACCESS_TOKEN --entrypoint /cleanup-clusters.sh ${DOCKER_ORG}/k8s-e2e-test-runner:${BRANCH}-latest "branch-identifier:${TAG_IDENTIFIER}" |
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
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
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,45 @@ | ||
#!/usr/bin/env bash | ||
|
||
# Copyright 2020 DigitalOcean | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
### Delete clusters that match a given DO tag along with all managed volumes that | ||
### may still exist. | ||
|
||
set -o errexit | ||
set -o nounset | ||
|
||
if ! type doctl > /dev/null 2>&1; then | ||
echo "doctl is missing" >&2 | ||
exit 1 | ||
fi | ||
|
||
if [[ $# -ne 1 ]]; then | ||
echo "usage: $(basename "$0") <identifying cluster tag>" >&2 | ||
exit 1 | ||
fi | ||
|
||
readonly CLUSTER_TAG="$1" | ||
|
||
echo "Cleaning up clusters based on cluster tag: ${CLUSTER_TAG}" | ||
|
||
while read -r cluster_uuid; do | ||
if doctl kubernetes cluster get "${cluster_uuid}" --no-header --format Tags | grep -q "${CLUSTER_TAG}"; then | ||
echo "Deleting cluster ${cluster_uuid}" | ||
doctl kubernetes cluster delete -f "${cluster_uuid}" | ||
echo "Deleting volumes for cluster ${cluster_uuid}" | ||
doctl compute volume list --no-header --format ID,Tags | grep "k8s:${cluster_uuid}" | awk '{print $1}' | xargs -n 1 doctl compute volume delete -f | ||
fi | ||
done < <(doctl kubernetes cluster list --no-header --format ID) # --format field "Tags" does not work on the "list" command | ||
echo "Done." |
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