From 75f0d4f19be297800b36006539ae68cee79bd967 Mon Sep 17 00:00:00 2001 From: Dan Voiculeasa Date: Fri, 13 Sep 2019 10:19:03 -0400 Subject: [PATCH] Enhance collect tool with k8s orchestration information Add a script to collect information about container orchestration. Get k8s orchestration information. Get helm information. Get chart overrides from /opt/platform/helm_charts. Dump etcd database as json. Story: 2006536 Task: 36596 Change-Id: Ib622e8a77616c77434e760c38578b8e363992201 Signed-off-by: Dan Voiculeasa --- tools/collector/centos/build_srpm.data | 2 +- tools/collector/centos/collector.spec | 1 + .../scripts/collect_containerization.sh | 82 +++++++++++++++++++ 3 files changed, 84 insertions(+), 1 deletion(-) create mode 100755 tools/collector/scripts/collect_containerization.sh diff --git a/tools/collector/centos/build_srpm.data b/tools/collector/centos/build_srpm.data index abb9f2e2..6226a273 100644 --- a/tools/collector/centos/build_srpm.data +++ b/tools/collector/centos/build_srpm.data @@ -1,2 +1,2 @@ SRC_DIR="scripts" -TIS_PATCH_VER=30 +TIS_PATCH_VER=31 diff --git a/tools/collector/centos/collector.spec b/tools/collector/centos/collector.spec index 4de41526..a7c02e44 100644 --- a/tools/collector/centos/collector.spec +++ b/tools/collector/centos/collector.spec @@ -47,6 +47,7 @@ install -m 755 collect_coredump.sh %{buildroot}%{_sysconfdir}/collect.d/collect_ install -m 755 collect_crash.sh %{buildroot}%{_sysconfdir}/collect.d/collect_crash install -m 755 collect_ima.sh %{buildroot}%{_sysconfdir}/collect.d/collect_ima install -m 755 collect_fm.sh %{buildroot}%{_sysconfdir}/collect.d/collect_fm +install -m 755 collect_containerization.sh %{buildroot}%{_sysconfdir}/collect.d/collect_containerization install -m 755 etc.exclude %{buildroot}%{_sysconfdir}/collect/etc.exclude install -m 755 run.exclude %{buildroot}%{_sysconfdir}/collect/run.exclude diff --git a/tools/collector/scripts/collect_containerization.sh b/tools/collector/scripts/collect_containerization.sh new file mode 100755 index 00000000..d2e5a924 --- /dev/null +++ b/tools/collector/scripts/collect_containerization.sh @@ -0,0 +1,82 @@ +#! /bin/bash +# +# Copyright (c) 2019 Wind River Systems, Inc. +# +# SPDX-License-Identifier: Apache-2.0 +# + + +# Loads Up Utilities and Commands Variables + +source /usr/local/sbin/collect_parms +source /usr/local/sbin/collect_utils + +SERVICE="containerization" +LOGFILE="${extradir}/${SERVICE}.info" +HELM_DIR="${extradir}/helm" +ETCD_DB_FILE="${extradir}/etcd_database.json" +KUBE_CONFIG_FILE="/etc/kubernetes/admin.conf" +KUBE_CONFIG="--kubeconfig ${KUBE_CONFIG_FILE}" +echo "${hostname}: Containerization Info ...: ${LOGFILE}" + +############################################################################### +# All nodes +############################################################################### +mkdir -p ${HELM_DIR} +source_openrc_if_needed + +CMD="docker image ls -a" +delimiter ${LOGFILE} "${CMD}" +${CMD} 2>>${COLLECT_ERROR_LOG} >>${LOGFILE} + +CMD="docker container ps -a" +delimiter ${LOGFILE} "${CMD}" +${CMD} 2>>${COLLECT_ERROR_LOG} >>${LOGFILE} + +############################################################################### +# Active Controller +############################################################################### +if [ "$nodetype" = "controller" -a "${ACTIVE}" = true ] ; then + + declare -a KUBE_CMDS=( + "kubectl ${KUBE_CONFIG} version" + "kubectl ${KUBE_CONFIG} api-resources --verbs=list --namespaced -o name | xargs -n 1 kubectl ${KUBE_CONFIG} get --show-kind --ignore-not-found --all-namespaces" + "kubectl ${KUBE_CONFIG} api-resources --verbs=list --namespaced -o name | xargs -n 1 kubectl ${KUBE_CONFIG} get --show-kind --ignore-not-found --all-namespaces -o yaml" + "kubectl ${KUBE_CONFIG} get pvc --all-namespaces" + "kubectl ${KUBE_CONFIG} get pvc --all-namespaces -o yaml" + "kubectl ${KUBE_CONFIG} get pv --all-namespaces" + "kubectl ${KUBE_CONFIG} get pv --all-namespaces -o yaml" + "kubectl ${KUBE_CONFIG} get events --all-namespaces --sort-by='.metadata.creationTimestamp' -o go-template='{{range .items}}{{printf \"%s %s\t%s\t%s\t%s\t%s\n\" .firstTimestamp .involvedObject.name .involvedObject.kind .message .reason .type}}{{end}}'" + ) + + for CMD in "${KUBE_CMDS[@]}" ; do + delimiter ${LOGFILE} "${CMD}" + eval ${CMD} 2>>${COLLECT_ERROR_LOG} >>${LOGFILE} + done + + CMD="helm ${KUBE_CONFIG} version" + delimiter ${LOGFILE} "${CMD}" + ${CMD} 2>>${COLLECT_ERROR_LOG} >>${LOGFILE} + + CMD="helm ${KUBE_CONFIG} list -a" + delimiter ${LOGFILE} "${CMD}" + APPLIST=$(${CMD} 2>>${COLLECT_ERROR_LOG} | tee -a ${LOGFILE}) + APPLIST=$(echo "${APPLIST}" | awk '{if (NR!=1) {print}}') + while read -r app; do + APPNAME=$(echo ${app} | awk '{print $1}') + APPREVISION=$(echo ${app} | awk '{print $2}') + helm ${KUBE_CONFIG} status ${APPNAME} > ${HELM_DIR}/${APPNAME}.status + helm ${KUBE_CONFIG} get values ${APPNAME} --revision ${APPREVISION} \ + > ${HELM_DIR}/${APPNAME}.v${APPREVISION} + done <<< "${APPLIST}" + + CMD="cp -r /opt/platform/helm_charts ${HELM_DIR}/" + delimiter ${LOGFILE} "${CMD}" + ${CMD} 2>>${COLLECT_ERROR_LOG} + + CMD="curl -L http://localhost:2379/v2/keys/?recursive=true -o ${ETCD_DB_FILE}" + delimiter ${LOGFILE} "${CMD}" + ${CMD} 2>>${COLLECT_ERROR_LOG} +fi + +exit 0