Skip to content

Commit 85d4a02

Browse files
authored
CLOUDP-342878 - Add --remove-destination to cp (#407)
# Summary Adding the `--remove-destination` flag to `cp` in `setup-agent-files.sh` will prevent the agent container from getting stuck whenever the agent or the utilities container is restarted. If the utilities container is restarted, then the pid of the utilities marker will change. This means that the symlink for the probes are pointing to the filesystem of the old pid, therefore a dangling symlink. When the agent container is restarted, `cp` will not be able to overwrite the symlink without this flag. This change will require re-releasing all agent images. ## Proof of Work Before the change <img width="1488" height="64" alt="image" src="https://github.com/user-attachments/assets/8cc664b9-491a-445b-b71c-2f9b89fa844a" /> After the change. The containers are ready even if they were restarted <img width="1444" height="83" alt="image" src="https://github.com/user-attachments/assets/26f4857a-9f6e-4eca-9e74-82acd5d9f145" /> ## Checklist - [x] Have you linked a jira ticket and/or is the ticket in the title? - [x] Have you checked whether your jira ticket required DOCSP changes? - [x] Have you added changelog file? - use `skip-changelog` label if not needed - refer to [Changelog files and Release Notes](https://github.com/mongodb/mongodb-kubernetes/blob/master/CONTRIBUTING.md#changelog-files-and-release-notes) section in CONTRIBUTING.md for more details
1 parent 632e21a commit 85d4a02

File tree

2 files changed

+15
-18
lines changed

2 files changed

+15
-18
lines changed

docker/mongodb-agent/setup-agent-files.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ SCRIPTS_DIR="/opt/scripts"
88
# readiness always returns failure
99
setup_dummy_probes() {
1010
echo "Setting up dummy probe scripts..."
11-
cp /usr/local/bin/dummy-probe.sh "$SCRIPTS_DIR/probe.sh"
12-
cp /usr/local/bin/dummy-readinessprobe "$SCRIPTS_DIR/readinessprobe"
11+
cp --remove-destination /usr/local/bin/dummy-probe.sh "$SCRIPTS_DIR/probe.sh"
12+
cp --remove-destination /usr/local/bin/dummy-readinessprobe "$SCRIPTS_DIR/readinessprobe"
1313
echo "Dummy probe scripts ready"
1414
}
1515

scripts/evergreen/e2e/dump_diagnostic_information.sh

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -126,29 +126,26 @@ dump_pod_logs() {
126126
kubectl cp "${namespace}/${pod}:/var/log/mongodb-mms-automation/automation-agent.log" "logs/${prefix}${pod}-agent.log" &> /dev/null
127127
kubectl cp "${namespace}/${pod}:/var/log/mongodb-mms-automation/monitoring-agent-verbose.log" "logs/${prefix}${pod}-monitoring-agent-verbose.log" &> /dev/null
128128
kubectl cp "${namespace}/${pod}:/var/log/mongodb-mms-automation/monitoring-agent.log" "logs/${prefix}${pod}-monitoring-agent.log" &> /dev/null
129-
kubectl logs -n "${namespace}" "${pod}" -c "mongodb-agent-monitoring" > "logs/${prefix}${pod}-monitoring-agent-stdout.log" || true
130-
kubectl logs -n "${namespace}" "${pod}" -c "mongod" > "logs/${prefix}${pod}-mongod-container.log" || true
131-
kubectl logs -n "${namespace}" "${pod}" -c "mongodb-agent" > "logs/${prefix}${pod}-mongodb-agent-container.log" || true
132129
kubectl cp "${namespace}/${pod}:/var/log/mongodb-mms-automation/mongodb.log" "logs/${prefix}${pod}-mongodb.log" &> /dev/null || true
133130

134131
# 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
135132
kubectl logs -n "${namespace}" "${pod}" | jq -c -r 'select( .logType == "agent-launcher-script") | .contents' 2> /dev/null > "logs/${prefix}${pod}-launcher.log"
136-
else
137-
# for all other pods we want each log per container from kubectl
138-
for container in $(kubectl get pods -n "${namespace}" "${pod}" -o jsonpath='{.spec.containers[*].name}'); do
139-
echo "Writing log file for pod ${pod} - container ${container} to logs/${pod}-${container}.log"
140-
kubectl logs -n "${namespace}" "${pod}" -c "${container}" > "logs/${pod}-${container}.log"
133+
fi
141134

142-
# Check if the container has restarted by examining its restart count
143-
restartCount=$(kubectl get pod -n "${namespace}" "${pod}" -o jsonpath="{.status.containerStatuses[?(@.name=='${container}')].restartCount}")
135+
for container in $(kubectl get pods -n "${namespace}" "${pod}" -o jsonpath='{.spec.containers[*].name}'); do
136+
echo "Writing log file for pod ${pod} - container ${container} to logs/${pod}-${container}.log"
137+
kubectl logs -n "${namespace}" "${pod}" -c "${container}" > "logs/${pod}-${container}.log"
144138

145-
if [ "${restartCount}" -gt 0 ]; then
146-
echo "Writing log file for restarted ${pod} - container ${container} to logs/${pod}-${container}-previous.log"
147-
kubectl logs --previous -n "${namespace}" "${pod}" -c "${container}" > "logs/${pod}-${container}-previous.log" || true
148-
fi
139+
# Check if the container has restarted by examining its restart count
140+
restartCount=$(kubectl get pod -n "${namespace}" "${pod}" -o jsonpath="{.status.containerStatuses[?(@.name=='${container}')].restartCount}")
141+
142+
if [ "${restartCount}" -gt 0 ]; then
143+
echo "Writing log file for restarted ${pod} - container ${container} to logs/${pod}-${container}-previous.log"
144+
kubectl logs --previous -n "${namespace}" "${pod}" -c "${container}" > "logs/${pod}-${container}-previous.log" || true
145+
fi
146+
147+
done
149148

150-
done
151-
fi
152149

153150
if kubectl exec "${pod}" -n "${namespace}" -- ls /var/log/mongodb-mms-automation/automation-agent-stderr.log &>/dev/null; then
154151
kubectl cp "${namespace}/${pod}:/var/log/mongodb-mms-automation/automation-agent-stderr.log" "logs/${prefix}${pod}-agent-stderr.log" &> /dev/null

0 commit comments

Comments
 (0)