From 9ec57b029038d61270d22a3458031f8242df00e1 Mon Sep 17 00:00:00 2001 From: MegHeisler Date: Wed, 24 Jul 2019 15:27:42 -0500 Subject: [PATCH] Add scripts to get cluster and namespaces objects This adds scripts that gather cluster object information and namespaces object information. These scripts then create a folder and both yaml and txt files for each object Change-Id: Ia22caef4503451e637b20e1d62c4bd50aedfece2 --- .../airship_gate/bin/cluster-objects.sh | 50 +++++++++++++ .../airship_gate/bin/debug-report-lite.sh | 36 ++-------- .../airship_gate/bin/namespace-objects.sh | 72 +++++++++++++++++++ 3 files changed, 127 insertions(+), 31 deletions(-) create mode 100755 tools/multi_nodes_gate/airship_gate/bin/cluster-objects.sh create mode 100755 tools/multi_nodes_gate/airship_gate/bin/namespace-objects.sh diff --git a/tools/multi_nodes_gate/airship_gate/bin/cluster-objects.sh b/tools/multi_nodes_gate/airship_gate/bin/cluster-objects.sh new file mode 100755 index 00000000..3bd869ce --- /dev/null +++ b/tools/multi_nodes_gate/airship_gate/bin/cluster-objects.sh @@ -0,0 +1,50 @@ +#!/usr/bin/env bash +# Copyright 2017 The Openstack-Helm Authors. +# Copyright 2019 AT&T Intellectual Property. All other rights reserved. +# +# 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. + +set -e + +export CLUSTER_TYPE="${CLUSTER_TYPE:="node,clusterrole,clusterrolebinding,storageclass,namespace"}" +export PARALLELISM_FACTOR="${PARALLELISM_FACTOR:=2}" + +function list_objects () { + printf ${CLUSTER_TYPE} | xargs -d ',' -I {} -P1 -n1 bash -c 'echo "$@"' _ {} +} + +export -f list_objects + +function name_objects () { + export OBJECT=$1 + kubectl get ${OBJECT} -o name | xargs -L1 -I {} -P1 -n1 bash -c 'echo "${OBJECT} ${1#*/}"' _ {} +} + +export -f name_objects + +function get_objects () { + input=($1) + export OBJECT=${input[0]} + export NAME=${input[1]#*/} + echo "${OBJECT}/${NAME}" + export BASE_DIR="${BASE_DIR:="/tmp"}" + DIR="${BASE_DIR}/ojects/cluster/${OBJECT}" + mkdir -p ${DIR} + kubectl get ${OBJECT} ${NAME} -o yaml > "${DIR}/${NAME}.yaml" + kubectl describe ${OBJECT} ${NAME} > "${DIR}/${NAME}.txt" +} + +export -f get_objects +list_objects | \ +xargs -r -n 1 -P ${PARALLELISM_FACTOR} -I {} bash -c 'name_objects "$@"' _ {} | \ +xargs -r -n 1 -P ${PARALLELISM_FACTOR} -I {} bash -c 'get_objects "$@"' _ {} diff --git a/tools/multi_nodes_gate/airship_gate/bin/debug-report-lite.sh b/tools/multi_nodes_gate/airship_gate/bin/debug-report-lite.sh index 804372bb..b3d81210 100755 --- a/tools/multi_nodes_gate/airship_gate/bin/debug-report-lite.sh +++ b/tools/multi_nodes_gate/airship_gate/bin/debug-report-lite.sh @@ -29,33 +29,9 @@ export CALICO_DIR="${BASE_DIR}/calico" mkdir -p "${BASE_DIR}" -PARALLELISM_FACTOR=2 - -function get_namespaces () { - kubectl get namespaces -o name | awk -F '/' '{ print $NF }' -} - -function get_pods () { - NAMESPACE=$1 - kubectl get pods -n "${NAMESPACE}" -o name --show-all | awk -F '/' '{ print $NF }' | xargs -L1 -P 1 -I {} echo "${NAMESPACE}" {} -} -export -f get_pods - -function get_pod_logs () { - NAMESPACE=${1% *} - POD=${1#* } - INIT_CONTAINERS=$(kubectl get pod "${POD}" -n "${NAMESPACE}" -o json | jq -r '.spec.initContainers[]?.name') - CONTAINERS=$(kubectl get pod "${POD}" -n "${NAMESPACE}" -o json | jq -r '.spec.containers[].name') - POD_DIR="${BASE_DIR}/pod-logs/${NAMESPACE}/${POD}" - mkdir -p "${POD_DIR}" - for CONTAINER in ${INIT_CONTAINERS} ${CONTAINERS}; do - echo "get_pod_logs() [${NAMESPACE}] ${POD} ${CONTAINER}" - kubectl logs "${POD}" -n "${NAMESPACE}" -c "${CONTAINER}" > "${POD_DIR}/${CONTAINER}.txt" - done -} - - -export -f get_pod_logs +export OBJECT_TYPE="${OBJECT_TYPE:="pods"}" +export CLUSTER_TYPE="${CLUSTER_TYPE:="namespace"}" +export PARALLELISM_FACTOR="${PARALLELISM_FACTOR:=2}" function get_releases () { helm list --all --short @@ -80,9 +56,8 @@ kubectl get --all-namespaces -o wide pods > "${BASE_DIR}/pods.txt" kubectl get pods --all-namespaces -o yaml > "${BASE_DIR}/pods_long.yaml" kubectl describe pods --all-namespaces > "${BASE_DIR}/pods_describe.txt" -get_namespaces | \ - xargs -r -n 1 -P "${PARALLELISM_FACTOR}" -I {} bash -c 'get_pods "$@"' _ {} | \ - xargs -r -n 2 -P "${PARALLELISM_FACTOR}" -I {} bash -c 'get_pod_logs "$@"' _ {} +./tools/multi_nodes_gate/airship_gate/bin/namespace-objects.sh +./tools/multi_nodes_gate/airship_gate/bin/cluster-objects.sh iptables-save > "${BASE_DIR}/iptables" @@ -104,4 +79,3 @@ if which calicoctl; then fi tar zcf "${SUBDIR_NAME}.tgz" -C "${TEMP_DIR}" "${SUBDIR_NAME}" - diff --git a/tools/multi_nodes_gate/airship_gate/bin/namespace-objects.sh b/tools/multi_nodes_gate/airship_gate/bin/namespace-objects.sh new file mode 100755 index 00000000..a22a7068 --- /dev/null +++ b/tools/multi_nodes_gate/airship_gate/bin/namespace-objects.sh @@ -0,0 +1,72 @@ +#!/usr/bin/env bash +# Copyright 2017 The Openstack-Helm Authors. +# Copyright 2019 AT&T Intellectual Property. All other rights reserved. +# +# 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. + +set -e + +export OBJECT_TYPE="${OBJECT_TYPE:="configmaps,cronjobs,daemonsets,deployment,endpoints,ingresses,jobs,networkpolicies,pods,podsecuritypolicies,persistentvolumeclaims,rolebindings,roles,secrets,serviceaccounts,services,statefulsets"}" +export PARALLELISM_FACTOR="${PARALLELISM_FACTOR:=2}" + +function get_namespaces () { + kubectl get namespaces -o name | awk -F '/' '{ print $NF }' +} + +function list_namespaced_objects () { + export NAMESPACE=$1 + printf ${OBJECT_TYPE} | xargs -d ',' -I {} -P1 -n1 bash -c 'echo "${NAMESPACE} $@"' _ {} +} + +export -f list_namespaced_objects + +function name_objects () { + input=($1) + export NAMESPACE=${input[0]} + export OBJECT=${input[1]} + kubectl get -n ${NAMESPACE} ${OBJECT} -o name | xargs -L1 -I {} -P1 -n1 bash -c 'echo "${NAMESPACE} ${OBJECT} $@"' _ {} +} + +export -f name_objects + +function get_objects () { + input=($1) + export NAMESPACE=${input[0]} + export OBJECT=${input[1]} + export NAME=${input[2]#*/} + echo "${NAMESPACE}/${OBJECT}/${NAME}" + export BASE_DIR="${BASE_DIR:="/tmp"}" + DIR="${BASE_DIR}/namespaces/${NAMESPACE}/${OBJECT}" + mkdir -p ${DIR} + kubectl get -n ${NAMESPACE} ${OBJECT} ${NAME} -o yaml > "${DIR}/${NAME}.yaml" + kubectl describe -n ${NAMESPACE} ${OBJECT} ${NAME} > "${DIR}/${NAME}.txt" + + LOG_DIR="${BASE_DIR}/pod-logs" + mkdir -p ${LOG_DIR} + + if [ ${OBJECT_TYPE} = "pods" ]; then + POD_DIR="${LOG_DIR}/${NAME}" + mkdir -p ${POD_DIR} + CONTAINERS=$(kubectl get pod "${NAME}" -n "${NAMESPACE}" -o json | jq -r '.spec.containers[].name') + for CONTAINER in ${CONTAINERS}; do + kubectl logs -n ${NAMESPACE} ${NAME} -c ${CONTAINER} > "${POD_DIR}/${CONTAINER}.txt" + done + fi +} + +export -f get_objects + +get_namespaces | \ +xargs -r -n 1 -P ${PARALLELISM_FACTOR} -I {} bash -c 'list_namespaced_objects "$@"' _ {} | \ +xargs -r -n 1 -P ${PARALLELISM_FACTOR} -I {} bash -c 'name_objects "$@"' _ {} | \ +xargs -r -n 1 -P ${PARALLELISM_FACTOR} -I {} bash -c 'get_objects "$@"' _ {}