Skip to content

Commit ce73154

Browse files
authored
Swarming: Avoids mounting volume (#5213)
## Overview Swarming, as well as K8S has issues when trying to mount this volume to the container. ```bash mount /mnt/scratch0 -o remount,exec,suid,dev ``` So we added a validation to not mount when we are either in K8S or in swarming. Note: Uses SWARMING_BOT env var as its the one we [already use in the swarming request](https://github.com/google/clusterfuzz/blob/master/src/clusterfuzz/_internal/swarming/__init__.py#L134) ## Tests performed I created a custom bash script to test this: ```bash is_truthy() { [[ "$1" =~ ^([Tt]rue|1)$ ]] } should_mount() { if is_truthy "$IS_K8S_ENV" || is_truthy "$SWARMING_BOT"; then return 1 fi return 0 } test_mount() { unset IS_K8S_ENV SWARMING_BOT [[ "$1" != "unset" ]] && export IS_K8S_ENV=$1 [[ "$2" != "unset" ]] && export SWARMING_BOT=$2 printf "IS_K8S_ENV=%-5s | SWARMING_BOT=%-5s =>" "$1" "$2" if should_mount; then echo " [MOUNT EXECUTED]"; else echo " [MOUNT SKIPPED]"; fi } ' ``` Against multiple inputs: ```bash echo "=== DRY RUN OUTPUT USING is_truthy() ===" test_mount "unset" "unset" test_mount "1" "unset" test_mount "true" "unset" test_mount "false" "unset" test_mount "False" "unset" test_mount "0" "unset" test_mount "unset" "True" test_mount "unset" "1" test_mount "unset" "false" test_mount "false" "false" ``` And got this results: ```bash === DRY RUN OUTPUT USING is_truthy() === IS_K8S_ENV=unset | SWARMING_BOT=unset => [MOUNT EXECUTED] IS_K8S_ENV=1 | SWARMING_BOT=unset => [MOUNT SKIPPED] IS_K8S_ENV=true | SWARMING_BOT=unset => [MOUNT SKIPPED] IS_K8S_ENV=false | SWARMING_BOT=unset => [MOUNT EXECUTED] IS_K8S_ENV=False | SWARMING_BOT=unset => [MOUNT EXECUTED] IS_K8S_ENV=0 | SWARMING_BOT=unset => [MOUNT EXECUTED] IS_K8S_ENV=unset | SWARMING_BOT=True => [MOUNT SKIPPED] IS_K8S_ENV=unset | SWARMING_BOT=1 => [MOUNT SKIPPED] IS_K8S_ENV=unset | SWARMING_BOT=false => [MOUNT EXECUTED] IS_K8S_ENV=false | SWARMING_BOT=false => [MOUNT EXECUTED] ```
1 parent 2a97787 commit ce73154

1 file changed

Lines changed: 15 additions & 3 deletions

File tree

docker/base/setup_common.sh

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,22 @@ then
3333
export PREEMPTIBLE=True
3434
fi
3535

36+
is_truthy() {
37+
[[ "$1" =~ ^([Tt]rue|1)$ ]]
38+
}
39+
3640
# Make sure mounted volume doesn't have noexec,nosuid,nodev
37-
# Running this in k8s environment will cause mounting errors
38-
if [[ -z "$IS_K8S_ENV" ]]
39-
then
41+
# Running this in k8s or swarming environment will cause mounting errors
42+
should_mount() {
43+
# Skip if running in Kubernetes or as a Swarming Job
44+
if is_truthy "$IS_K8S_ENV" || is_truthy "$SWARMING_BOT"; then
45+
return 1
46+
fi
47+
48+
return 0
49+
}
50+
51+
if should_mount; then
4052
mount /mnt/scratch0 -o remount,exec,suid,dev
4153
fi
4254

0 commit comments

Comments
 (0)