From b3533b8522ac67f581837a1a5033d3b9777e9e89 Mon Sep 17 00:00:00 2001 From: Smruti Soumitra Khuntia Date: Tue, 20 Aug 2019 16:43:45 +0530 Subject: [PATCH] Enabling debug-report.sh to configure pods log duration. Currently, when debug-report.sh collects logs for the deployment, it's tmp directory eats up massive storage space if pod logs are collected for more than two hours of duration. This fix will provide a new shell variable "LOG_DURATION" that gives flexibilty to configure log duration of pods to restrict space crunch on the node while report creation. Default value is set to 0s, means collect all logs. To enable the collection of all logs irrespective of duration, LOG_ DURATION should be set to 0s. LOG_DURATION can be in seconds(s), minutes(m) or hours(h). Change-Id: Ia80f37baca90f421cd0f543fc3a66e039df45323 --- .../templates/roles/common/usr/local/bin/debug-report.sh | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/promenade/templates/roles/common/usr/local/bin/debug-report.sh b/promenade/templates/roles/common/usr/local/bin/debug-report.sh index cc6e4857..1e36ad27 100755 --- a/promenade/templates/roles/common/usr/local/bin/debug-report.sh +++ b/promenade/templates/roles/common/usr/local/bin/debug-report.sh @@ -5,6 +5,10 @@ set -ux SUBDIR_NAME=debug-$(hostname) BASETEMP=${BASETEMP:-"/var/tmp"} NAMESPACE_PATTERN=${NAMESPACE_PATTERN:-'.*'} +# NOTE: Duration of newer pods logs that need to be fetched. Defaults to all logs. +# Passing value 0s will fetch all logs. +LOG_DURATION=${LOG_DURATION:-"0s"} +export LOG_DURATION # NOTE(mark-burnett): This should add calicoctl to the path. export PATH=${PATH}:/opt/cni/bin @@ -36,9 +40,10 @@ function get_pod_logs () { 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}" + SINCE="${LOG_DURATION}" mkdir -p "${POD_DIR}" for CONTAINER in ${INIT_CONTAINERS} ${CONTAINERS}; do - kubectl logs "${POD}" -n "${NAMESPACE}" -c "${CONTAINER}" > "${POD_DIR}/${CONTAINER}.txt" + kubectl logs "${POD}" -n "${NAMESPACE}" -c "${CONTAINER}" --since="${SINCE}" > "${POD_DIR}/${CONTAINER}.txt" done } export -f get_pod_logs