forked from kubernetes/test-infra
-
Notifications
You must be signed in to change notification settings - Fork 0
/
clear.sh
executable file
·134 lines (112 loc) · 3.28 KB
/
clear.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
#!/usr/bin/env bash
# Copyright 2021 The Kubernetes Authors.
#
# 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 Kubernetes resources in the test cluster. This script guarantees that
# these operations are only executed against the test cluster, and so is safer
# than running kubectl directly (because your default context might be set to a
# production instance).
set -o errexit
set -o nounset
set -o pipefail
SCRIPT_ROOT="$(cd "$(dirname "$0")" && pwd)"
source "${SCRIPT_ROOT}"/lib.sh
function usage() {
>&2 cat <<EOF
Delete Kubernetes resources in the test cluster.
Usage: $0 [options]
Examples:
# Delete ProwJob CRs and test pods.
$0 -all
# Delete all ProwJob CRs.
$0 -prowjobs
# Delete all test pods.
$0 -test-pods
Options:
-all:
Alias for -test-pods -prowjobs -components.
-components:
Delete all Prow components (deployments). This brings down the Prow
components (pods) such that they are not restarted by Kubernetes (which
would happen if you deleted just their pods).
-test-data:
Alias for -test-pods -prowjobs.
-prowjobs:
Delete all ProwJob CRs.
-test-pods:
Delete all test pods.
-help:
Display this help message.
EOF
}
function main() {
declare -a delete_args
if ! (($#)); then
echo >&2 "teardown: missing flag: must provide one of -all, -prowjobs, or -test-pods"
return 1
fi
for arg in "$@"; do
case "${arg}" in
-all)
delete_args+=(-prowjobs)
delete_args+=(-test-pods)
delete_args+=(-components)
;;
-prowjobs)
delete_args+=("${arg}")
;;
-test-pods)
delete_args+=("${arg}")
;;
-components)
delete_args+=("${arg}")
;;
-test-data)
delete_args+=(-prowjobs)
delete_args+=(-test-pods)
;;
-help)
usage
return
;;
--*)
echo >&2 "cannot use flags with two leading dashes ('--...'), use single dashes instead ('-...')"
return 1
;;
esac
done
if [[ -n "${delete_args[*]}" ]]; then
if [[ " ${delete_args[*]} " =~ " -prowjobs " ]]; then
delete_prowjobs
fi
if [[ " ${delete_args[*]} " =~ " -test-pods " ]]; then
delete_test_pods
fi
if [[ " ${delete_args[*]} " =~ " -components " ]]; then
delete_components
fi
fi
}
function delete_components() {
log "KIND cluster: deleting all Prow components (deployments)"
do_kubectl delete deployments.apps --all
}
function delete_test_pods() {
log "KIND cluster: deleting all pods in the test-pods namespace"
do_kubectl --namespace=test-pods delete pods --all
}
function delete_prowjobs() {
log "KIND cluster: deleting all ProwJobs in the default namespace"
do_kubectl delete prowjobs.prow.k8s.io --all
}
main "$@"