fix: repair Pimox registry pull config
This commit is contained in:
parent
9f87a1ee93
commit
e8109e25a2
|
|
@ -4240,6 +4240,10 @@ apps_registry_endpoint() {
|
|||
printf '%s\n' "${TF_VAR_registry_endpoint}"
|
||||
return 0
|
||||
fi
|
||||
if [[ -n "${LAB_REGISTRY_ENDPOINT:-}" ]]; then
|
||||
printf '%s\n' "${LAB_REGISTRY_ENDPOINT}"
|
||||
return 0
|
||||
fi
|
||||
|
||||
demos_registry_endpoint
|
||||
}
|
||||
|
|
@ -7070,6 +7074,10 @@ ensure_pimox_containerd_registry_refresh() {
|
|||
echo "LAB_PIMOX_REGISTRY_REFRESH_CONTAINERD must be true or false." >&2
|
||||
exit 1
|
||||
fi
|
||||
if [[ "${registry_endpoint}" != *:* || ! "${registry_endpoint}" =~ ^[A-Za-z0-9_.:-]+$ ]]; then
|
||||
echo "Registry endpoint '${registry_endpoint}' must be a simple host:port value for remote containerd configuration." >&2
|
||||
exit 1
|
||||
fi
|
||||
if [[ -n "${cp_host}" ]]; then
|
||||
node_entries+=("${cp_host}"$'\t'"${cp_user}"$'\t'"${cp_node}"$'\t'"${cp_key}")
|
||||
fi
|
||||
|
|
@ -7087,21 +7095,130 @@ ensure_pimox_containerd_registry_refresh() {
|
|||
for node_entry in "${node_entries[@]}"; do
|
||||
IFS=$'\t' read -r node_host node_user node_name node_key_path <<<"${node_entry}"
|
||||
echo "Refreshing containerd local-registry config on ${node_name} (${node_user}@${node_host})..."
|
||||
ssh -i "${node_key_path}" -o BatchMode=yes -o ConnectTimeout=10 -o IdentitiesOnly=yes -o StrictHostKeyChecking=accept-new "${node_user}@${node_host}" "set -eu
|
||||
sudo mkdir -p '/etc/containerd/certs.d/${registry_endpoint}'
|
||||
sudo tee '/etc/containerd/certs.d/${registry_endpoint}/hosts.toml' >/dev/null <<'REGISTRY_HOSTS_EOF'
|
||||
server = \"http://${registry_endpoint}\"
|
||||
ssh -i "${node_key_path}" -o BatchMode=yes -o ConnectTimeout=10 -o IdentitiesOnly=yes -o StrictHostKeyChecking=accept-new "${node_user}@${node_host}" \
|
||||
"REGISTRY_ENDPOINT='${registry_endpoint}' bash -s" <<'PIMOX_CONTAINERD_EOF'
|
||||
set -eu
|
||||
|
||||
[host.\"http://${registry_endpoint}\"]
|
||||
capabilities = [\"pull\", \"resolve\", \"push\"]
|
||||
registry_endpoint="${REGISTRY_ENDPOINT:?}"
|
||||
changed=0
|
||||
|
||||
containerd_config_version() {
|
||||
awk -F= '
|
||||
/^[[:space:]]*version[[:space:]]*=/ {
|
||||
gsub(/[[:space:]]/, "", $2)
|
||||
print $2
|
||||
exit
|
||||
}
|
||||
' /etc/containerd/config.toml
|
||||
}
|
||||
|
||||
ensure_containerd_registry_config_path() {
|
||||
plugin="$1"
|
||||
append_section="$2"
|
||||
|
||||
sudo awk -v plugin="$plugin" -v append_section="$append_section" '
|
||||
function is_table(line) {
|
||||
return line ~ /^[[:space:]]*\[/
|
||||
}
|
||||
function is_target_registry(line) {
|
||||
return is_table(line) &&
|
||||
index(line, plugin) > 0 &&
|
||||
line ~ /[.]registry[[:space:]]*\]/
|
||||
}
|
||||
BEGIN {
|
||||
in_target = 0
|
||||
found = 0
|
||||
wrote = 0
|
||||
}
|
||||
is_target_registry($0) {
|
||||
if (in_target && !wrote) {
|
||||
print " config_path = \"/etc/containerd/certs.d\""
|
||||
}
|
||||
in_target = 1
|
||||
wrote = 0
|
||||
found = 1
|
||||
print
|
||||
next
|
||||
}
|
||||
in_target && is_table($0) {
|
||||
if (!wrote) {
|
||||
print " config_path = \"/etc/containerd/certs.d\""
|
||||
}
|
||||
in_target = 0
|
||||
wrote = 0
|
||||
}
|
||||
in_target && $0 ~ /^[[:space:]]*config_path[[:space:]]*=/ {
|
||||
print " config_path = \"/etc/containerd/certs.d\""
|
||||
wrote = 1
|
||||
next
|
||||
}
|
||||
{ print }
|
||||
END {
|
||||
if (in_target && !wrote) {
|
||||
print " config_path = \"/etc/containerd/certs.d\""
|
||||
}
|
||||
if (!found) {
|
||||
print ""
|
||||
print append_section
|
||||
print " config_path = \"/etc/containerd/certs.d\""
|
||||
}
|
||||
}
|
||||
' /etc/containerd/config.toml | sudo tee /etc/containerd/config.toml.homelab >/dev/null
|
||||
|
||||
if ! sudo cmp -s /etc/containerd/config.toml.homelab /etc/containerd/config.toml; then
|
||||
sudo mv /etc/containerd/config.toml.homelab /etc/containerd/config.toml
|
||||
changed=1
|
||||
else
|
||||
sudo rm -f /etc/containerd/config.toml.homelab
|
||||
fi
|
||||
}
|
||||
|
||||
sudo mkdir -p /etc/containerd "/etc/containerd/certs.d/${registry_endpoint}"
|
||||
if ! sudo test -s /etc/containerd/config.toml; then
|
||||
sudo containerd config default | sudo tee /etc/containerd/config.toml >/dev/null
|
||||
changed=1
|
||||
fi
|
||||
|
||||
hosts_tmp="$(mktemp)"
|
||||
cat >"${hosts_tmp}" <<REGISTRY_HOSTS_EOF
|
||||
server = "http://${registry_endpoint}"
|
||||
|
||||
[host."http://${registry_endpoint}"]
|
||||
capabilities = ["pull", "resolve", "push"]
|
||||
skip_verify = true
|
||||
REGISTRY_HOSTS_EOF
|
||||
if ! sudo grep -R 'config_path = \"/etc/containerd/certs.d\"' /etc/containerd/config.toml >/dev/null 2>&1; then
|
||||
echo 'WARNING: /etc/containerd/config.toml does not explicitly reference /etc/containerd/certs.d; kubelet may still try HTTPS.' >&2
|
||||
|
||||
if ! sudo test -f "/etc/containerd/certs.d/${registry_endpoint}/hosts.toml" ||
|
||||
! sudo cmp -s "${hosts_tmp}" "/etc/containerd/certs.d/${registry_endpoint}/hosts.toml"; then
|
||||
sudo cp "${hosts_tmp}" "/etc/containerd/certs.d/${registry_endpoint}/hosts.toml"
|
||||
changed=1
|
||||
fi
|
||||
sudo systemctl restart containerd
|
||||
sudo systemctl restart kubelet
|
||||
"
|
||||
rm -f "${hosts_tmp}"
|
||||
|
||||
if ! sudo grep -Eq 'config_path[[:space:]]*=[[:space:]]*"/etc/containerd/certs.d"' /etc/containerd/config.toml; then
|
||||
config_version="$(containerd_config_version)"
|
||||
if [ "${config_version}" = "3" ]; then
|
||||
ensure_containerd_registry_config_path "io.containerd.cri.v1.images" '[plugins."io.containerd.cri.v1.images".registry]'
|
||||
else
|
||||
ensure_containerd_registry_config_path "io.containerd.grpc.v1.cri" '[plugins."io.containerd.grpc.v1.cri".registry]'
|
||||
fi
|
||||
fi
|
||||
|
||||
sudo tee /etc/crictl.yaml >/dev/null <<'CRICTL_EOF'
|
||||
runtime-endpoint: unix:///run/containerd/containerd.sock
|
||||
image-endpoint: unix:///run/containerd/containerd.sock
|
||||
timeout: 10
|
||||
debug: false
|
||||
CRICTL_EOF
|
||||
|
||||
sudo containerd config dump >/dev/null
|
||||
if [ "${changed}" = "1" ]; then
|
||||
sudo systemctl restart containerd
|
||||
sudo systemctl restart kubelet
|
||||
else
|
||||
echo "containerd local-registry config already current for ${registry_endpoint}"
|
||||
fi
|
||||
PIMOX_CONTAINERD_EOF
|
||||
done
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue