forked from kubevirt/project-infra
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclear-bazel-cache.sh
executable file
·71 lines (59 loc) · 2.46 KB
/
clear-bazel-cache.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/bin/bash
#
# This file is part of the KubeVirt project
#
# 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.
#
# Copyright 2022 Red Hat, Inc.
#
#
set -euxo pipefail
function usage() {
cat <<EOF
usage: $0
Clears the bazel cache by rescaling the service and deleting the data
Needs to recreate the greenhouse service, thus it is required to be run from project-infra repo root directory.
EOF
}
function rescale_greenhouse_deployment() {
kubectl scale deployment -n kubevirt-prow greenhouse --replicas=0
kubectl rollout status -w deployment -n kubevirt-prow greenhouse
wait_for_running_pods_number 0
kubectl scale deployment -n kubevirt-prow greenhouse --replicas=1
kubectl rollout status -w deployment -n kubevirt-prow greenhouse
wait_for_running_pods_number 1
}
function remove_greenhouse_data() {
greenhouse_pod_name=$(kubectl get pods --no-headers -n kubevirt-prow -l app=greenhouse --field-selector=status.phase=Running | head -1 | awk '{print $1}')
kubectl exec "$greenhouse_pod_name" -n kubevirt-prow -- rm -rf /data/*
}
function wait_for_running_pods_number() {
local running_pods_number="$1"
while [[ $(kubectl get pods --no-headers -n kubevirt-prow -l app=greenhouse --field-selector=status.phase=Running | wc -l) -ne "$running_pods_number" ]]; do
echo "number of running pods is $(kubectl get pods --no-headers -n kubevirt-prow -l app=greenhouse --field-selector=status.phase=Running | wc -l), desired $running_pods_number"
sleep 3
done
}
function main() {
if [[ ! -f "$(pwd)/github/ci/prow-deploy/kustom/components/greenhouse/base/resources/service.yaml" ]]; then
usage
echo "service file for greenhouse not found in $(pwd)!"
exit 1
fi
kubectl delete svc -n kubevirt-prow bazel-cache
rescale_greenhouse_deployment
remove_greenhouse_data
rescale_greenhouse_deployment
kubectl apply -f github/ci/prow-deploy/kustom/components/greenhouse/base/resources/service.yaml
}
main "$@"