k8s.io/perf-tests/clusterloader2@v0.0.0-20240304094227-64bdb12da87e/clean-up-old-snapshots-boskos.sh (about) 1 #!/usr/bin/env bash 2 3 # Copyright 2022 The Kubernetes Authors. 4 # 5 # Licensed under the Apache License, Version 2.0 (the "License"); 6 # you may not use this file except in compliance with the License. 7 # You may obtain a copy of the License at 8 # 9 # http://www.apache.org/licenses/LICENSE-2.0 10 # 11 # Unless required by applicable law or agreed to in writing, software 12 # distributed under the License is distributed on an "AS IS" BASIS, 13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 # See the License for the specific language governing permissions and 15 # limitations under the License. 16 17 set -o errexit 18 set -o nounset 19 set -o pipefail 20 21 SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) 22 23 print-usage-and-exit() { 24 >&2 echo "Usage:" 25 >&2 echo " $0 delete|list <comma-sep-prefixes> <days-old> <comma-sep-boskos-pools> <boskos-resources-file>" 26 >&2 echo "Example:" 27 >&2 echo " $0 list ci-e2e-scalability,ci-e2e-kubemark 30 scalability-project ./boskos-resources.yaml" 28 exit "$1" 29 } 30 31 main() { 32 if [ "$#" -ne 5 ]; then 33 >&2 echo "Wrong number of parameters, expected 5, got $#" 34 print-usage-and-exit 1 35 fi 36 37 command=$1 38 prefixes=$2 39 days_old=$3 40 boskos_pools=$4 41 boskos_file=$5 42 43 if ! [[ "$boskos_pools" =~ ^[a-z0-9,-]+$ ]]; then 44 >&2 echo "Illegal characters in projects parameter: $boskos_pools" 45 print-usage-and-exit 2 46 fi 47 48 if ! [[ -f "$boskos_file" ]]; then 49 >&2 echo "$boskos_file file does not exist" 50 print-usage-and-exit 3 51 fi 52 53 projects=() 54 55 IFS=',' read -ra boskos_pools_arr <<< "$boskos_pools" 56 for boskos_pool in "${boskos_pools_arr[@]}"; do 57 readarray boskos_projects < \ 58 <(yq ".resources.[] | select (.type == \"$boskos_pool\") | .names.[]" "$boskos_file") 59 if [ ${#boskos_projects[@]} -eq 0 ]; then 60 >&2 echo "Could not find any project under boskos pool $boskos_pool" 61 exit 4 62 fi 63 64 for project in "${boskos_projects[@]}"; do 65 projects+=("$(echo -e "$project" | tr -d '[:space:]')") 66 done 67 done 68 69 projects_str=$(IFS=','; echo "${projects[*]}") 70 71 ( 72 set -o xtrace 73 "$SCRIPT_DIR/clean-up-old-snapshots.sh" \ 74 "$command" "$projects_str" "$prefixes" "$days_old" 75 ) 76 } 77 78 main "$@"