Remove calls to scripts in debug script

This change removes the calls to scripts and instead adds
their functionality directly into the debug script. This
removes the possibility of errors due to calls to a
relative path.

Change-Id: Ie64cbf1f1d4f88251c8da5fbabceb113fd9caf6e
This commit is contained in:
MegHeisler 2019-11-01 11:03:41 -05:00 committed by Sreejith Punnapuzha
parent 679751c13c
commit d324e8b6a0
3 changed files with 84 additions and 126 deletions

View File

@ -1,50 +0,0 @@
#!/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 "%s" ${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}/objects/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 "$@"' _ {}

View File

@ -30,9 +30,92 @@ export CALICO_DIR="${BASE_DIR}/calico"
mkdir -p "${BASE_DIR}"
export OBJECT_TYPE="${OBJECT_TYPE:="pods"}"
export CLUSTER_TYPE="${CLUSTER_TYPE:="namespace"}"
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 %s ${OBJECT_TYPE} | xargs -d ',' -I {} -P1 -n1 bash -c "echo ${NAMESPACE} $*" _ {}
}
export -f list_namespaced_objects
function name_namespaced_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_namespaced_objects
function get_namespaced_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_namespaced_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_namespaced_objects "$@"' _ {} | \
xargs -r -n 1 -P ${PARALLELISM_FACTOR} -I {} bash -c 'get_namespaced_objects "$@"' _ {}
function list_cluster_objects () {
printf namespace | xargs -d ',' -I {} -P1 -n1 bash -c "echo $*" _ {}
}
function name_cluster_objects () {
export OBJECT=($1)
kubectl get "${OBJECT[@]}" -o name | xargs -L1 -I {} -P1 -n1 bash -c "echo ${OBJECT[@]} ${1#*/}" _ {}
}
export -f name_cluster_objects
function get_cluster_objects () {
input=($1)
export OBJECT=${input[0]}
export NAME=${input[1]#*/}
echo "${OBJECT[@]}/${NAME}"
export BASE_DIR=${BASE_DIR:="/tmp"}
DIR="${BASE_DIR}/objects/cluster/${OBJECT[@]}"
mkdir -p "${DIR}"
kubectl get "${OBJECT[@]}" "${NAME}" -o yaml > "${DIR}/${NAME}.yaml"
kubectl describe "${OBJECT[@S]}" "${NAME}" > "${DIR}/${NAME}.txt"
}
export -f get_cluster_objects
list_cluster_objects | \
xargs -r -n 1 -P ${PARALLELISM_FACTOR} -I {} bash -c 'name_cluster_objects "$@"' _ {} | \
xargs -r -n 1 -P ${PARALLELISM_FACTOR} -I {} bash -c 'get_cluster_objects "$@"' _ {}
function get_releases () {
helm list --all --short
}
@ -56,9 +139,6 @@ 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"
./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"
cat /var/log/syslog > "${BASE_DIR}/syslog"

View File

@ -1,72 +0,0 @@
#!/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 "%s" "${OBJECT_TYPE}" | xargs -d ',' -I {} -P1 -n1 bash -c "echo ${NAMESPACE} ${1#*/}" _ {}
}
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} ${1#*/}" _ {}
}
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 "$@"' _ {}