Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"scripts_version": "202610.08.1"
}
102 changes: 56 additions & 46 deletions parts/linux/cloud-init/artifacts/init-aks-cloud.sh
Original file line number Diff line number Diff line change
Expand Up @@ -422,13 +422,23 @@ function add_ms_keys {
function aptget_update {
echo "apt-get updating..."
echo "note: depending on how many sources have been added this may take a couple minutes..."
if apt-get update | grep -q "404 Not Found"; then
echo "ERROR: apt-get update failed to find all sources. Please validate the sources or remove bad sources from your sources and try again."
emit_event "AKS.CSE.customCloudRepoInit.aptgetUpdateFailed" "apt-get update returned 404 for one or more sources" "Error"
exit 1
else
echo "apt-get update complete!"
fi
local retries=10
local i
for i in $(seq 1 "$retries"); do
echo "Running apt-get update (attempt $i/$retries)"
if apt-get update; then
echo "apt-get update complete!"
return 0
fi

if [ "$i" -lt "$retries" ]; then
sleep 5
fi
done

echo "ERROR: apt-get update failed after $retries attempts" >&2
emit_event "AKS.CSE.customCloudRepoInit.aptgetUpdateFailed" "apt-get update failed after $retries attempts" "Error"
return 1
}

function init_ubuntu_pmc_repo_depot {
Expand Down Expand Up @@ -511,16 +521,22 @@ function dnf_makecache {
local dnf_makecache_output=/tmp/dnf-makecache.out
local i
for i in $(seq 1 $retries); do
! (dnf makecache -y 2>&1 | tee $dnf_makecache_output | grep -E "^([WE]:.*)|([eE]rr.*)$") && \
cat $dnf_makecache_output && break || \
cat $dnf_makecache_output
if [ $i -eq $retries ]; then
return 1
else
dnf makecache -y > "$dnf_makecache_output" 2>&1
cat "$dnf_makecache_output"

if ! grep -Eq "^([WE]:.*)|([eE]rr.*)$" "$dnf_makecache_output"; then
echo "Executed dnf makecache -y $i times"
return 0
fi

if [ "$i" -lt "$retries" ]; then
sleep 5
fi
done
echo "Executed dnf makecache -y $i times"

echo "ERROR: dnf_makecache failed after retries; Please validate the sources or remove bad sources from your sources and try again" >&2
emit_event "AKS.CSE.customCloudRepoInit.dnfMakecacheFailed" "dnf_makecache failed after retries" "Error"
return 1
}

# Determines the certificate endpoint mode based on location.
Expand Down Expand Up @@ -633,6 +649,32 @@ fi
# - init (default): full provisioning path
# - ca-refresh <location>: periodic refresh path; location is passed as arg to avoid env dependency
action=${1:-init}
if [ "$action" = "init" ]; then
rootRepoDepotEndpoint="$(echo "${REPO_DEPOT_ENDPOINT}" | sed 's/\/ubuntu//')"
if [ -z "$rootRepoDepotEndpoint" ]; then
echo "repo depot endpoint empty, skipping repodepot initialization"
else
if [ "$IS_UBUNTU" -eq 1 ]; then
ubuntuRel=$(lsb_release --release | awk '{print $2}')
ubuntuDist=$(lsb_release -c | awk '{print $2}')
init_ubuntu_main_repo_depot ${rootRepoDepotEndpoint}
init_ubuntu_pmc_repo_depot ${rootRepoDepotEndpoint}
echo "Running apt-get update"
aptget_update
elif [ "$IS_MARINER" -eq 1 ] || [ "$IS_AZURELINUX" -eq 1 ]; then
if [ "$IS_MARINER" -eq 1 ]; then
echo "Initializing Mariner repo depot settings..."
init_mariner_repo_depot ${rootRepoDepotEndpoint}
else
echo "Initializing Azure Linux repo depot settings..."
init_azurelinux_repo_depot ${rootRepoDepotEndpoint}
fi
echo "Running dnf_makecache"
dnf_makecache
fi
fi
fi

if [ "$action" = "ca-refresh" ] || [ "$install_ca_refresh_schedule" -eq 0 ]; then
exit 0
fi
Expand Down Expand Up @@ -688,38 +730,6 @@ EOF
systemctl enable --now azure-ca-refresh.timer
fi

if [ "$IS_UBUNTU" -eq 1 ]; then
rootRepoDepotEndpoint="$(echo "${REPO_DEPOT_ENDPOINT}" | sed 's/\/ubuntu//')"
if [ -n "$rootRepoDepotEndpoint" ]; then
cloud-init status --wait
ubuntuRel=$(lsb_release --release | awk '{print $2}')
ubuntuDist=$(lsb_release -c | awk '{print $2}')
init_ubuntu_main_repo_depot ${rootRepoDepotEndpoint}
init_ubuntu_pmc_repo_depot ${rootRepoDepotEndpoint}
echo "Running apt-get update"
aptget_update
else
echo "REPO_DEPOT_ENDPOINT empty, skipping Ubuntu RepoDepot initialization"
fi
elif [ "$IS_MARINER" -eq 1 ] || [ "$IS_AZURELINUX" -eq 1 ]; then
cloud-init status --wait

marinerRepoDepotEndpoint="$(echo "${REPO_DEPOT_ENDPOINT}" | sed 's/\/ubuntu//')"
if [ -z "$marinerRepoDepotEndpoint" ]; then
>&2 echo "repo depot endpoint empty while running custom-cloud init script"
else
if [ "$IS_MARINER" -eq 1 ]; then
echo "Initializing Mariner repo depot settings..."
init_mariner_repo_depot ${marinerRepoDepotEndpoint}
dnf_makecache || { echo "ERROR: dnf_makecache failed after retries; aborting custom cloud repo init (Mariner)"; emit_event "AKS.CSE.customCloudRepoInit.dnfMakecacheFailed" "dnf_makecache failed after retries (Mariner)" "Error"; exit 1; }
else
echo "Initializing Azure Linux repo depot settings..."
init_azurelinux_repo_depot ${marinerRepoDepotEndpoint}
dnf_makecache || { echo "ERROR: dnf_makecache failed after retries; aborting custom cloud repo init (Azure Linux)"; emit_event "AKS.CSE.customCloudRepoInit.dnfMakecacheFailed" "dnf_makecache failed after retries (Azure Linux)" "Error"; exit 1; }
fi
fi
fi

# Disable systemd-timesyncd and install chrony and uses local time source
# ACL has PTP clock config compiled into chronyd with no config file or sourcedir directives,
# so it uses only the local PTP clock and has no DHCP-injectable NTP sources.
Expand Down
Loading
Loading