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
This commit is contained in:
parent
b9ea53d277
commit
b3533b8522
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user