Fix kubectl exec: specify container explicitly to avoid selection messages
This commit is contained in:
parent
6ce7116c4b
commit
3a2f9d4677
@ -723,12 +723,26 @@ spec:
|
||||
fi
|
||||
|
||||
# Helper function to run MySQL commands via kubectl exec
|
||||
# Using -c to specify container explicitly to avoid kubectl container selection messages
|
||||
MYSQL_CONTAINER=$(kubectl get pod -n "$NAMESPACE" "$MYSQL_POD" -o jsonpath='{.spec.containers[0].name}' 2>/dev/null)
|
||||
echo "MySQL container name: $MYSQL_CONTAINER"
|
||||
|
||||
run_mysql() {
|
||||
local result
|
||||
result=$(kubectl exec -n "$NAMESPACE" "$MYSQL_POD" -- mysql -u "$MYSQL_USER" -p"$MYSQL_PWD" "$MYSQL_DB" -sN -e "$1" 2>&1) || {
|
||||
local exit_code
|
||||
# Run kubectl exec with explicit container, redirect kubectl stderr to /dev/null
|
||||
# but capture MySQL output (including MySQL warnings on stderr)
|
||||
result=$(kubectl exec -n "$NAMESPACE" "$MYSQL_POD" -c "$MYSQL_CONTAINER" -- \
|
||||
mysql -u "$MYSQL_USER" -p"$MYSQL_PWD" "$MYSQL_DB" -sN -e "$1" 2>&1)
|
||||
exit_code=$?
|
||||
|
||||
# Filter out MySQL password warning
|
||||
result=$(echo "$result" | grep -v "Using a password on the command line interface can be insecure")
|
||||
|
||||
if [ $exit_code -ne 0 ]; then
|
||||
echo " MySQL error: $result" >&2
|
||||
return 1
|
||||
}
|
||||
fi
|
||||
echo "$result"
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user