forked from VirtusLab/jenkins-operator
-
-
Notifications
You must be signed in to change notification settings - Fork 245
feat(backup): improve temporary file handling and cleanup #1154
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
Draft
dir01
wants to merge
1
commit into
jenkinsci:master
Choose a base branch
from
dir01:fix/backup-pvc-garbage-tmp-cleanup
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
Empty file.
Empty file.
Empty file.
Empty file.
1 change: 1 addition & 0 deletions
1
backup/pvc/e2e/stale_tmp_dir_cleanup/jenkins_home/jobs/some-job/builds/1/build.xml
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| build.xml |
1 change: 1 addition & 0 deletions
1
backup/pvc/e2e/stale_tmp_dir_cleanup/jenkins_home/jobs/some-job/builds/1/log
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| build logs |
Empty file.
1 change: 1 addition & 0 deletions
1
backup/pvc/e2e/stale_tmp_dir_cleanup/jenkins_home/jobs/some-job/nextBuildNumber
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| 2 |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
| #!/bin/bash | ||
| set -eo pipefail | ||
|
|
||
| echo "Running stale_tmp_dir_cleanup e2e test..." | ||
|
|
||
| [[ "${DEBUG}" ]] && set -x | ||
|
|
||
| # set current working directory to the directory of the script | ||
| cd "$(dirname "$0")" | ||
|
|
||
| docker_image=$1 | ||
|
|
||
| if ! docker inspect ${docker_image} &> /dev/null; then | ||
| echo "Image '${docker_image}' does not exists" | ||
| false | ||
| fi | ||
|
|
||
| JENKINS_HOME="$(pwd)/jenkins_home" | ||
| BACKUP_DIR="$(pwd)/backup" | ||
| mkdir -p ${BACKUP_DIR} | ||
|
|
||
| # Create stale directories that should be cleaned up | ||
| mkdir -p ${BACKUP_DIR}/tmp.stale1 | ||
| mkdir -p ${BACKUP_DIR}/tmp.stale2 | ||
| touch ${BACKUP_DIR}/tmp.stale1/somefile | ||
|
|
||
| # Create directories that should NOT be cleaned up | ||
| mkdir -p ${BACKUP_DIR}/other_dir | ||
| mkdir -p ${BACKUP_DIR}/tmp_but_no_dot | ||
| mkdir -p ${BACKUP_DIR}/tmp | ||
| touch ${BACKUP_DIR}/other_dir/keepme | ||
|
|
||
| # Create an instance of the container under testing | ||
| cid="$(docker run -e BACKUP_CLEANUP_INTERVAL=1 -e JENKINS_HOME=${JENKINS_HOME} -v ${JENKINS_HOME}:${JENKINS_HOME}:ro -e BACKUP_DIR=${BACKUP_DIR} -v ${BACKUP_DIR}:${BACKUP_DIR}:rw -d ${docker_image})" | ||
| echo "Docker container ID '${cid}'" | ||
|
|
||
| # Remove test directory and container afterwards | ||
| trap "docker rm -vf $cid > /dev/null;rm -rf ${BACKUP_DIR}" EXIT | ||
|
|
||
| backup_number=1 | ||
| docker exec ${cid} /home/user/bin/backup.sh ${backup_number} | ||
|
|
||
| # Check cleanup results | ||
| if [ -d "${BACKUP_DIR}/tmp.stale1" ]; then | ||
| echo "FAIL: Stale directory tmp.stale1 was not removed" | ||
| exit 1 | ||
| fi | ||
|
|
||
| if [ -d "${BACKUP_DIR}/tmp.stale2" ]; then | ||
| echo "FAIL: Stale directory tmp.stale2 was not removed" | ||
| exit 1 | ||
| fi | ||
|
|
||
| if [ ! -d "${BACKUP_DIR}/other_dir" ]; then | ||
| echo "FAIL: Directory other_dir was incorrectly removed" | ||
| exit 1 | ||
| fi | ||
|
|
||
| if [ ! -d "${BACKUP_DIR}/tmp_but_no_dot" ]; then | ||
| echo "FAIL: Directory tmp_but_no_dot was incorrectly removed" | ||
| exit 1 | ||
| fi | ||
|
|
||
| if [ ! -d "${BACKUP_DIR}/tmp" ]; then | ||
| echo "FAIL: Directory tmp was incorrectly removed" | ||
| exit 1 | ||
| fi | ||
|
|
||
| # Verify backup success | ||
| backup_file="${BACKUP_DIR}/${backup_number}.tar.zstd" | ||
| [[ ! -f ${backup_file} ]] && echo "Backup file ${backup_file} not found" && exit 1; | ||
|
|
||
| # Verify no unexpected tmp directories remain | ||
| remaining_tmp=$(find "${BACKUP_DIR}" -maxdepth 1 -name "tmp.*") | ||
| if [ ! -z "$remaining_tmp" ]; then | ||
| echo "FAIL: Unexpected tmp directories remaining: $remaining_tmp" | ||
| exit 1 | ||
| fi | ||
|
|
||
| echo "Stale temporary directories cleaned up successfully" | ||
| echo PASS |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it safe to assume that? I mean, trap file protects us against concurrent runs with the same number, but is it possible that another backup with a lower or higher number runs concurrently?