This repository has been archived by the owner on Mar 7, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathrun-mustgather.sh
executable file
·230 lines (196 loc) · 6.15 KB
/
run-mustgather.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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
#!/bin/bash
set -e
kube=kubectl
openShift=oc
thing=$kube
namespace=
type=
imagePrefix=ibmcom/
#dev mode vars
devMode=false
dockerUserName=
dockerPassword=
dockerEmail=
function usage {
cat << EOF
Usage:
./run-mustgather.sh [options]
Options:
--namespace <n>
The namespace of the IBM Blockchain instance. If you don't provide this, the tool will only gather a subset of information
--type <t>
The type of environment your cluster is running in. Possible values are "kb" or "oc". Defaults to Kubernetes
EOF
}
function setEnvironmentType {
if [ -n "$type" ] ; then
if [ "$type" == "kb" ] ; then
thing=$kube
elif [ "$type" == "oc" ] ; then
thing=$openShift
else
echo "type argument was not valid. Values can be kb or oc"
usage
exit 1
fi
fi
}
function processArgs {
if [ "$devMode" == true ] ; then
if [ -z "$dockerUserName" ] ; then
echo "dockerUserName arguement must be set in dev mode"
usage
exit 1
fi
if [ -z "$dockerPassword" ] ; then
echo "dockerPassword arguement must be set in dev mode"
usage
exit 1
fi
if [ -z "$dockerEmail" ] ; then
echo "dockerEmail arguement must be set in dev mode"
usage
exit 1
fi
fi
setEnvironmentType
}
while [ "$1" != "" ]; do
case $1 in
-d | --devMode )
devMode=true
;;
-u | --dockerUserName )
shift
dockerUserName="$1"
imagePrefix="$dockerUserName/"
echo "$imagePrefix"
;;
-p | --dockerPassword )
shift
dockerPassword="$1"
;;
-e | --dockerEmail )
shift
dockerEmail="$1"
;;
-n | --namespace )
shift
namespace="$1"
;;
-t | --type )
shift
type="$1"
;;
-h | --help )
usage
exit
;;
* )
echo "Unknown argument $1"
usage
exit 1
;;
esac
shift
done
processArgs
if [ "$devMode" == true ] ; then
echo "$(date) Running in dev mode"
fi
echo "$(date) Check if mustgather namespace exists"
if ! $thing get namespace mustgather ; then
echo "$(date) Creating mustgather name space"
$thing create namespace mustgather
fi
if [ "$devMode" == true ] ; then
echo "$(date) Check if secret exists"
if $thing get secret mustgathersecret -n mustgather ; then
$thing delete secret mustgathersecret -n mustgather
fi
echo "$(date) Creating secret"
$thing create secret docker-registry mustgathersecret --docker-server=https://index.docker.io/v2/ --docker-username="$dockerUserName" --docker-password="$dockerPassword" --docker-email="$dockerEmail" -n mustgather
fi
echo "$(date) Creating yaml role file"
cat >./mustgather_role.yaml <<EOL
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: "mustgather:reader"
rules:
- apiGroups: ["ibp.com"]
resources: ["ibpconsoles","ibpcas","ibppeers","ibporderers"]
verbs: ["get", "list", "watch"]
- apiGroups: [""]
resources: ["configmaps","pods","pods/log","services","persistentvolumeclaims","namespaces","routes","secrets","nodes"]
verbs: ["get", "list", "watch"]
- apiGroups: ["apps"]
resources: ["deployments","replicasets","services"]
verbs: ["get", "list", "watch"]
- apiGroups: ["extensions"]
resources: ["ingresses"]
verbs: ["get", "list", "watch"]
- apiGroups: [""]
resources: ["routes"]
verbs: ["get", "list", "watch"]
- apiGroups: [""]
resources: ["secrets"]
verbs: ["get", "list", "watch"]
- apiGroups: ["storage.k8s.io"]
resources: ["storageclasses"]
verbs: ["get", "list", "watch"]
- apiGroups: ["config.openshift.io"]
resources: ["clusterversions"]
verbs: ["get", "list", "watch"]
- apiGroups: ["route.openshift.io"]
resources: ["routes"]
verbs: ["get", "list", "watch"]
EOL
echo "$(date) Check if mustgather:reader cluster role exists"
if $thing get clusterrole mustgather:reader -n mustgather ; then
echo "$(date) Deleting cluster role"
$thing delete clusterrole mustgather:reader
fi
echo "$(date) Creating mustgather:reader cluster role"
$thing apply -f mustgather_role.yaml
echo "$(date) Check if mustgather-view cluster role binding exists"
if $thing get clusterrolebinding mustgather-view -n mustgather ; then
echo "$(date) Deleting cluster role binding"
$thing delete clusterrolebinding mustgather-view
fi
echo "$(date) Creating mustgather-view role binding"
$thing create clusterrolebinding mustgather-view --clusterrole=mustgather:reader --serviceaccount=mustgather:default
echo "$(date) Creating yaml file for new pod"
cat >./mustgather.yaml <<EOL
apiVersion: v1
kind: Pod
metadata:
name: mustgather
spec:
containers:
- name: mustgather
image: ${imagePrefix}ibp-mustgather
command: ["/bin/bash", "-ec", "while :; do echo '.'; sleep 5 ; done"]
imagePullSecrets:
- name: mustgathersecret
EOL
echo "$(date) Check if pod mustgather exists"
if $thing get pod mustgather -n mustgather ; then
echo "$(date) pod must gather exists so deleting pod"
$thing delete pod mustgather -n mustgather
fi
echo "$(date) Creating pod mustgather"
$thing apply -f mustgather.yaml -n mustgather
echo "$(date) Wating for pod must gather to be created (this can take up to 10 minutes)"
$thing wait -n mustgather --for=condition=Ready pod/mustgather --timeout=1200s
timestamp=$(date +"%m%d%Y%H%M")
echo "$(date) Running must gather tool"
if [ -z "$namespace" ] ; then
$thing exec mustgather -n mustgather -- ibp-mustgather --noserver -f mustgather
else
$thing exec mustgather -n mustgather -- ibp-mustgather -n "$namespace" --noserver
fi
echo "$(date) Retrieving archive file"
$thing cp mustgather/mustgather:/tmp/mustgather.tar.gz ./mustgather-"$timestamp".tar.gz
echo "$(date) Archive file retrieved and is located at ./mustgather-$timestamp.tar.gz"
echo "$(date) Finished"