mirror of
https://github.com/dredx/prole.git
synced 2026-09-23 11:03:59 +00:00
Enhance image import handling for k3s nodes and improve readiness checks:
- Use `scp` to transfer image tar files to remote nodes before importing, ensuring reliability for large images. - Clean up temporary files on remote nodes post-import or in case of failure. - Extend readiness probe to support HTTP alongside HTTPS endpoints.
This commit is contained in:
parent
51ba00f0e7
commit
c2e97ab550
@ -1383,6 +1383,7 @@ _docker_build_knoe_db_image() {
|
||||
# Respects optional PROLE_SSH_KEY (path to private key) and K3S_SSH_USER env vars.
|
||||
_import_image_to_k3s_nodes() {
|
||||
local image="$1"
|
||||
local plain_image="${image##*/}"
|
||||
local ssh_user="${K3S_SSH_USER:-${ANSIBLE_USER:-ansible}}"
|
||||
local ssh_key_args=()
|
||||
# Auto-detect the SSH key: explicit override → ~/.ssh/id_ed25519_ansible (ansible user key)
|
||||
@ -1427,13 +1428,22 @@ _import_image_to_k3s_nodes() {
|
||||
continue
|
||||
fi
|
||||
echo " Importing '$image' to k3s node '$node' ..."
|
||||
if ssh -o StrictHostKeyChecking=no -o BatchMode=yes -o ConnectTimeout=30 \
|
||||
# Copy the tar to the remote node first, then import from file.
|
||||
# Piping via stdin can silently fail on large images over SSH.
|
||||
local _remote_tar="/tmp/prole-img-import-$$.tar"
|
||||
if scp -o StrictHostKeyChecking=no -o BatchMode=yes -o ConnectTimeout=30 \
|
||||
"${ssh_key_args[@]}" "$tar_file" "${ssh_user}@${node}:${_remote_tar}" >/dev/null 2>&1 \
|
||||
&& ssh -o StrictHostKeyChecking=no -o BatchMode=yes -o ConnectTimeout=60 \
|
||||
-o ServerAliveInterval=30 -o ServerAliveCountMax=10 \
|
||||
"${ssh_key_args[@]}" "${ssh_user}@${node}" \
|
||||
"sudo k3s ctr images import -" < "$tar_file" >/dev/null 2>&1; then
|
||||
"sudo k3s ctr images import '${_remote_tar}' && rm -f '${_remote_tar}'" >/dev/null 2>&1; then
|
||||
echo " ✓ Image imported on node '$node'."
|
||||
imported=$((imported + 1))
|
||||
else
|
||||
# Clean up remote tar on failure (best-effort).
|
||||
ssh -o StrictHostKeyChecking=no -o BatchMode=yes -o ConnectTimeout=5 \
|
||||
"${ssh_key_args[@]}" "${ssh_user}@${node}" \
|
||||
"rm -f '${_remote_tar}'" >/dev/null 2>&1 || true
|
||||
echo " WARN: Failed to import image on node '$node'; skipping." >&2
|
||||
fi
|
||||
done
|
||||
@ -1492,7 +1502,8 @@ _push_to_k3s_registry() {
|
||||
local ready=0
|
||||
if command -v curl >/dev/null 2>&1; then
|
||||
for _i in {1..40}; do
|
||||
if curl -k -fsS -m 1 "https://127.0.0.1:${pf_port}/v2/" >/dev/null 2>&1; then
|
||||
if curl -k -fsS -m 1 "https://127.0.0.1:${pf_port}/v2/" >/dev/null 2>&1 \
|
||||
|| curl -fsS -m 1 "http://127.0.0.1:${pf_port}/v2/" >/dev/null 2>&1; then
|
||||
ready=1
|
||||
break
|
||||
fi
|
||||
|
||||
@ -1288,7 +1288,8 @@ _push_to_k3s_registry() {
|
||||
local ready=0
|
||||
if command -v curl >/dev/null 2>&1; then
|
||||
for _i in {1..40}; do
|
||||
if curl -k -fsS -m 1 "https://127.0.0.1:${pf_port}/v2/" >/dev/null 2>&1; then
|
||||
if curl -k -fsS -m 1 "https://127.0.0.1:${pf_port}/v2/" >/dev/null 2>&1 \
|
||||
|| curl -fsS -m 1 "http://127.0.0.1:${pf_port}/v2/" >/dev/null 2>&1; then
|
||||
ready=1
|
||||
break
|
||||
fi
|
||||
|
||||
Loading…
Reference in New Issue
Block a user