Skip to content

Commit a19d958

Browse files
author
Ashish Ranjan
committed
Adds support to run ceph commands from must-gather pod
This commit adds support to run ceph-commands from must-gather pod which removes the dependency of toolbox pod from must-gather. Signed-off-by: Ashish Ranjan <[email protected]>
1 parent 8cb694f commit a19d958

File tree

6 files changed

+95
-24
lines changed

6 files changed

+95
-24
lines changed

hack/latest-csv-checksum.md5

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0166608856098a960a4e84e5214c978c
1+
d8545861e1bf12354a6b531126f18d71

must-gather/Centos-Base.repo

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[centos]
2+
name=CentOS-7
3+
baseurl=http://ftp.heanet.ie/pub/centos/7/os/x86_64/
4+
enabled=1
5+
gpgcheck=1
6+
gpgkey=http://ftp.heanet.ie/pub/centos/7/os/x86_64/RPM-GPG-KEY-CentOS-7

must-gather/Dockerfile

+31-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,39 @@
11
FROM quay.io/openshift/origin-must-gather:latest
22

3+
RUN sed -i 's/enabled=1/enabled=0/g' /etc/yum/pluginconf.d/subscription-manager.conf \
4+
&& cat /etc/yum/pluginconf.d/subscription-manager.conf \
5+
&& sed -i 's/enabled=1/enabled=0/g' /etc/yum/pluginconf.d/ovl.conf && cat /etc/yum/pluginconf.d/ovl.conf \
6+
&& sed -i 's/enabled=1/enabled=0/g' /etc/yum/pluginconf.d/product-id.conf && cat /etc/yum/pluginconf.d/product-id.conf \
7+
&& sed -i 's/enabled=1/enabled=0/g' /etc/yum/pluginconf.d/search-disabled-repos.conf && cat /etc/yum/pluginconf.d/search-disabled-repos.conf \
8+
&& rm -rf /etc/yum.repos.d/*
9+
10+
COPY Centos-Base.repo /etc/yum.repos.d/
11+
12+
RUN rpm --import 'https://download.ceph.com/keys/release.asc'
13+
14+
RUN yum install -y https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
15+
16+
RUN su -c 'rpm -Uvh https://download.ceph.com/rpm-luminous/el7/noarch/ceph-release-1-0.el7.noarch.rpm'
17+
18+
RUN yum install -y \
19+
http://mirror.centos.org/centos/7/extras/x86_64/Packages/python-werkzeug-0.9.1-2.el7.noarch.rpm \
20+
http://mirror.centos.org/centos/7/extras/x86_64/Packages/python-itsdangerous-0.23-2.el7.noarch.rpm \
21+
http://mirror.centos.org/centos/7/os/x86_64/Packages/audit-libs-python-2.8.5-4.el7.x86_64.rpm \
22+
http://mirror.centos.org/centos/7/os/x86_64/Packages/cryptsetup-2.0.3-5.el7.x86_64.rpm \
23+
http://download-ib01.fedoraproject.org/pub/epel/7/x86_64/Packages/l/libbabeltrace-1.2.4-3.el7.x86_64.rpm \
24+
http://download-ib01.fedoraproject.org/pub/epel/7/x86_64/Packages/l/leveldb-1.12.0-11.el7.x86_64.rpm \
25+
http://mirror.centos.org/centos/7/extras/x86_64/Packages/python-flask-0.10.1-4.el7.noarch.rpm \
26+
http://mirror.centos.org/centos/7/os/x86_64/Packages/device-mapper-event-1.02.158-2.el7.x86_64.rpm \
27+
http://download-ib01.fedoraproject.org/pub/epel/7/x86_64/Packages/l/lttng-ust-2.4.1-4.el7.x86_64.rpm \
28+
ceph
29+
330
# Save original gather script
431
RUN mv /usr/bin/gather /usr/bin/gather_original
532

633
# copy all collection scripts to /usr/bin
734
COPY collection-scripts/* /usr/bin/
835

9-
ENTRYPOINT /usr/bin/gather
36+
RUN mkdir /templates
37+
COPY templates /templates
38+
39+
ENTRYPOINT /usr/bin/gather

must-gather/collection-scripts/gather_ceph_resources

+51-22
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,34 @@ if [[ ${BASE_COLLECTION_PATH} == "" ]]; then
88
fi
99

1010
CEPH_COLLLECTION_PATH="${BASE_COLLECTION_PATH}/ceph"
11+
CEPH_MON_SECRET_NAME="rook-ceph-mon"
12+
CEPH_MON_CONFIGMAP_NAME="rook-ceph-mon-endpoints"
13+
KEYRING_FILE="/etc/ceph/keyring"
14+
CEPH_CONFIG_FILE="/etc/ceph/ceph.conf"
15+
CEPH_CONFIG_TEMPLATE="/templates/ceph.conf.template"
16+
CEPH_KEYRING_TEMPLATE="/templates/keyring.template"
17+
18+
generate_config() {
19+
namespace=$1
20+
# Check if the mon secrets exists
21+
secretName=`oc get secrets -n $namespace $CEPH_MON_SECRET_NAME -o jsonpath="{.metadata.name}"`
22+
if [ -z ${secretName} ]; then
23+
echo 1
24+
fi
25+
adminKey=`oc get secrets -n $namespace $CEPH_MON_SECRET_NAME -o jsonpath="{.data.admin-secret}" | base64 --decode`
26+
configMapName=`oc get configmap -n $namespace $CEPH_MON_CONFIGMAP_NAME -o jsonpath="{.metadata.name}"`
27+
if [ -z ${configMapName} ]; then
28+
echo 1
29+
fi
30+
monEndPoints=`oc get configmap -n $namespace $CEPH_MON_CONFIGMAP_NAME -o jsonpath="{.data.data}"`
31+
monEndPoints=`echo ${monEndPoints} | sed "s/[a-z]\+=//g" | sed "s/rook-ceph-mon[0-9]\+=//g"`
32+
33+
# creating admin keyring
34+
cat ${CEPH_KEYRING_TEMPLATE} | sed "s/REPLACE_WITH_KEYRING/${adminKey}/g" > ${KEYRING_FILE}
35+
cat ${CEPH_CONFIG_TEMPLATE} | sed "s/REPLACE_WITH_MON_ENDPOINTS/${monEndPoints}/g" | sed "s/REPLACE_WITH_KEYRING_PATH/${KEYRING_FILE//\//\\/}/g" > ${CEPH_CONFIG_FILE}
36+
37+
echo 0
38+
}
1139

1240
# Ceph resources
1341
ceph_resources=()
@@ -50,29 +78,30 @@ done
5078
# Inspecting the namespace where ceph-cluster is installed
5179
for ns in $(oc get cephcluster --all-namespaces --no-headers | awk '{print $1}'); do
5280
openshift-must-gather --base-dir=${CEPH_COLLLECTION_PATH} inspect ns/${ns}
81+
if [ $(generate_config ${ns}) -eq 1 ]; then
82+
continue
83+
fi
84+
COMMAND_OUTPUT_DIR=${CEPH_COLLLECTION_PATH}/namespaces/${ns}/must_gather_commands
85+
COMMAND_JSON_OUTPUT_DIR=${CEPH_COLLLECTION_PATH}/namespaces/${ns}/must_gather_commands/json_output
86+
mkdir -p ${COMMAND_OUTPUT_DIR}
87+
mkdir -p ${COMMAND_JSON_OUTPUT_DIR}
88+
for ((i = 0; i < ${#ceph_commands[@]}; i++)); do
89+
printf "collecting command output for: %s\n" "${ceph_commands[$i]}"
90+
COMMAND_OUTPUT_FILE=${COMMAND_OUTPUT_DIR}/${ceph_commands[$i]// /_}
91+
${ceph_commands[$i]} --connect-timeout=15 >> ${COMMAND_OUTPUT_FILE}
92+
JSON_COMMAND_OUTPUT_FILE=${COMMAND_JSON_OUTPUT_DIR}/${ceph_commands[$i]// /_}_--format_json-pretty
93+
${ceph_commands[$i]} --connect-timeout=15 --format json-pretty >> ${JSON_COMMAND_OUTPUT_FILE}
94+
done
5395

54-
# Running ceph commands in the toolbox
55-
toolbox_pod_name=`oc get po -n ${ns} -l app=rook-ceph-tools -o jsonpath='{.items[*].metadata.name}'`
56-
if [ ! -z ${toolbox_pod_name} ]; then
57-
toolbox_pod_status=`oc get po -n ${ns} -l app=rook-ceph-tools -o jsonpath='{.items[*].status.phase}'`
58-
if [ "$toolbox_pod_status" != "Running" ]; then
59-
exit 0;
60-
fi
61-
COMMAND_OUTPUT_DIR=${CEPH_COLLLECTION_PATH}/namespaces/${ns}/must_gather_commands
62-
COMMAND_JSON_OUTPUT_DIR=${CEPH_COLLLECTION_PATH}/namespaces/${ns}/must_gather_commands/json_output
63-
mkdir -p ${COMMAND_OUTPUT_DIR}
64-
mkdir -p ${COMMAND_JSON_OUTPUT_DIR}
65-
for ((i = 0; i < ${#ceph_commands[@]}; i++)); do
66-
printf "collecting command output for: %s\n" "${ceph_commands[$i]}"
67-
COMMAND_OUTPUT_FILE=${COMMAND_OUTPUT_DIR}/${ceph_commands[$i]// /_}
68-
oc -n ${ns} exec ${toolbox_pod_name} -- ${ceph_commands[$i]} >> ${COMMAND_OUTPUT_FILE}
69-
JSON_COMMAND_OUTPUT_FILE=${COMMAND_JSON_OUTPUT_DIR}/${ceph_commands[$i]// /_}_--format_json-pretty
70-
oc -n ${ns} exec ${toolbox_pod_name} -- ${ceph_commands[$i]} --format json-pretty >> ${JSON_COMMAND_OUTPUT_FILE}
71-
done
72-
for ((i = 0; i < ${#ceph_volume_commands[@]}; i++)); do
73-
printf "collecting command output for: %s\n" "${ceph_volume_commands[$i]}"
96+
for ((i = 0; i < ${#ceph_volume_commands[@]}; i++)); do
97+
printf "collecting command output for: %s\n" "${ceph_volume_commands[$i]}"
98+
for osdPod in $(oc get pods -n ${ns} -l app=rook-ceph-osd --no-headers | awk '{print $1}'); do
99+
pod_status=`oc get po ${osdPod} -n ${ns} -o jsonpath='{.status.phase}'`
100+
if [ "${pod_status}" != "Running" ]; then
101+
continue
102+
fi
74103
COMMAND_OUTPUT_FILE=${COMMAND_OUTPUT_DIR}/${ceph_volume_commands[$i]// /_}
75-
oc -n ${ns} exec ${toolbox_pod_name} -- ${ceph_volume_commands[$i]} >> ${COMMAND_OUTPUT_FILE}
104+
oc -n ${ns} exec ${osdPod} -- ${ceph_volume_commands[$i]} >> ${COMMAND_OUTPUT_FILE}
76105
done
77-
fi
106+
done
78107
done
+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[global]
2+
mon_host = REPLACE_WITH_MON_ENDPOINTS
3+
[client.admin]
4+
keyring = REPLACE_WITH_KEYRING_PATH
+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[client.admin]
2+
key = REPLACE_WITH_KEYRING

0 commit comments

Comments
 (0)