diff --git a/docker/mongodb-agent/setup-agent-files.sh b/docker/mongodb-agent/setup-agent-files.sh index 6a1b8a007..df9371a54 100755 --- a/docker/mongodb-agent/setup-agent-files.sh +++ b/docker/mongodb-agent/setup-agent-files.sh @@ -8,8 +8,8 @@ SCRIPTS_DIR="/opt/scripts" # readiness always returns failure setup_dummy_probes() { echo "Setting up dummy probe scripts..." - cp /usr/local/bin/dummy-probe.sh "$SCRIPTS_DIR/probe.sh" - cp /usr/local/bin/dummy-readinessprobe "$SCRIPTS_DIR/readinessprobe" + cp --remove-destination /usr/local/bin/dummy-probe.sh "$SCRIPTS_DIR/probe.sh" + cp --remove-destination /usr/local/bin/dummy-readinessprobe "$SCRIPTS_DIR/readinessprobe" echo "Dummy probe scripts ready" } diff --git a/scripts/evergreen/e2e/dump_diagnostic_information.sh b/scripts/evergreen/e2e/dump_diagnostic_information.sh index f4ea7b986..5b889621a 100755 --- a/scripts/evergreen/e2e/dump_diagnostic_information.sh +++ b/scripts/evergreen/e2e/dump_diagnostic_information.sh @@ -126,29 +126,26 @@ dump_pod_logs() { kubectl cp "${namespace}/${pod}:/var/log/mongodb-mms-automation/automation-agent.log" "logs/${prefix}${pod}-agent.log" &> /dev/null kubectl cp "${namespace}/${pod}:/var/log/mongodb-mms-automation/monitoring-agent-verbose.log" "logs/${prefix}${pod}-monitoring-agent-verbose.log" &> /dev/null kubectl cp "${namespace}/${pod}:/var/log/mongodb-mms-automation/monitoring-agent.log" "logs/${prefix}${pod}-monitoring-agent.log" &> /dev/null - kubectl logs -n "${namespace}" "${pod}" -c "mongodb-agent-monitoring" > "logs/${prefix}${pod}-monitoring-agent-stdout.log" || true - kubectl logs -n "${namespace}" "${pod}" -c "mongod" > "logs/${prefix}${pod}-mongod-container.log" || true - kubectl logs -n "${namespace}" "${pod}" -c "mongodb-agent" > "logs/${prefix}${pod}-mongodb-agent-container.log" || true kubectl cp "${namespace}/${pod}:/var/log/mongodb-mms-automation/mongodb.log" "logs/${prefix}${pod}-mongodb.log" &> /dev/null || true # note that this file may get empty if the logs have already grew too much - seems it's better to have it explicitly empty then just omit kubectl logs -n "${namespace}" "${pod}" | jq -c -r 'select( .logType == "agent-launcher-script") | .contents' 2> /dev/null > "logs/${prefix}${pod}-launcher.log" - else - # for all other pods we want each log per container from kubectl - for container in $(kubectl get pods -n "${namespace}" "${pod}" -o jsonpath='{.spec.containers[*].name}'); do - echo "Writing log file for pod ${pod} - container ${container} to logs/${pod}-${container}.log" - kubectl logs -n "${namespace}" "${pod}" -c "${container}" > "logs/${pod}-${container}.log" + fi - # Check if the container has restarted by examining its restart count - restartCount=$(kubectl get pod -n "${namespace}" "${pod}" -o jsonpath="{.status.containerStatuses[?(@.name=='${container}')].restartCount}") + for container in $(kubectl get pods -n "${namespace}" "${pod}" -o jsonpath='{.spec.containers[*].name}'); do + echo "Writing log file for pod ${pod} - container ${container} to logs/${pod}-${container}.log" + kubectl logs -n "${namespace}" "${pod}" -c "${container}" > "logs/${pod}-${container}.log" - if [ "${restartCount}" -gt 0 ]; then - echo "Writing log file for restarted ${pod} - container ${container} to logs/${pod}-${container}-previous.log" - kubectl logs --previous -n "${namespace}" "${pod}" -c "${container}" > "logs/${pod}-${container}-previous.log" || true - fi + # Check if the container has restarted by examining its restart count + restartCount=$(kubectl get pod -n "${namespace}" "${pod}" -o jsonpath="{.status.containerStatuses[?(@.name=='${container}')].restartCount}") + + if [ "${restartCount}" -gt 0 ]; then + echo "Writing log file for restarted ${pod} - container ${container} to logs/${pod}-${container}-previous.log" + kubectl logs --previous -n "${namespace}" "${pod}" -c "${container}" > "logs/${pod}-${container}-previous.log" || true + fi + + done - done - fi if kubectl exec "${pod}" -n "${namespace}" -- ls /var/log/mongodb-mms-automation/automation-agent-stderr.log &>/dev/null; then kubectl cp "${namespace}/${pod}:/var/log/mongodb-mms-automation/automation-agent-stderr.log" "logs/${prefix}${pod}-agent-stderr.log" &> /dev/null