@@ -139,6 +139,8 @@ ERR_SECURE_TLS_BOOTSTRAP_START_FAILURE=220 # Error starting the secure TLS boots
139139ERR_CLOUD_INIT_FAILED=223 # Error indicating that cloud-init returned exit code 1 in cse_cmd.sh
140140ERR_NVIDIA_DRIVER_INSTALL=224 # Error determining if nvidia driver install should be skipped
141141
142+ ERR_PULL_POD_INFRA_CONTAINER_IMAGE=225 # Error pulling pause image
143+
142144# For both Ubuntu and Mariner, /etc/*-release should exist.
143145# For unit tests, the OS and OS_VERSION will be set in the unit test script.
144146# So whether it's if or else actually doesn't matter to our unit test.
@@ -337,6 +339,28 @@ retrycmd_get_tarball_from_registry_with_oras() {
337339 done
338340}
339341
342+ retrycmd_cp_oci_layout_with_oras () {
343+ retries=$1 ; wait_sleep=$2 ; path=$3 ; tag=$4 ; url=$5
344+ mkdir -p " $path "
345+ echo " ${retries} retries"
346+ for i in $( seq 1 $retries ) ; do
347+ if [ " $i " -eq " $retries " ]; then
348+ echo " Failed to oras cp $url to $path :$tag after $retries attempts"
349+ return $ERR_PULL_POD_INFRA_CONTAINER_IMAGE
350+ else
351+ if [ " $i " -gt 1 ]; then
352+ sleep $wait_sleep
353+ fi
354+ timeout 120 oras cp " $url " " $path :$tag " --to-oci-layout --from-registry-config ${ORAS_REGISTRY_CONFIG_FILE} > $ORAS_OUTPUT 2>&1
355+ if [ " $? " -ne 0 ]; then
356+ cat $ORAS_OUTPUT
357+ else
358+ return 0
359+ fi
360+ fi
361+ done
362+ }
363+
340364retrycmd_get_aad_access_token () {
341365 retries=$1 ; wait_sleep=$2 ; url=$3
342366 for i in $( seq 1 $retries ) ; do
@@ -1104,4 +1128,46 @@ extract_tarball() {
11041128 esac
11051129}
11061130
1131+ function get_sandbox_image(){
1132+ sandbox_image=$( get_sandbox_image_from_containerd_config " /etc/containerd/config.toml" )
1133+ if [ -z " $sandbox_image " ]; then
1134+ sandbox_image=$( extract_value_from_kubelet_flags " $KUBELET_FLAGS " " pod-infra-container-image" )
1135+ fi
1136+
1137+ echo $sandbox_image
1138+ }
1139+
1140+ function extract_value_from_kubelet_flags(){
1141+ local kubelet_flags=$1
1142+ local key=$2
1143+
1144+ key=" ${key# --} "
1145+ value=$( echo " $kubelet_flags " | sed -n " s/.*--${key} =\([^ ]*\).*/\1/p" )
1146+ echo " $value "
1147+ }
1148+
1149+ function get_sandbox_image_from_containerd_config() {
1150+ local config_file=$1
1151+ local sandbox_image=" "
1152+
1153+ if [ ! -f " $config_file " ]; then
1154+ echo " "
1155+ return
1156+ fi
1157+
1158+ # Extract sandbox_image value from the CRI plugin section
1159+ # The sandbox_image is typically under [plugins."io.containerd.grpc.v1.cri"]
1160+ sandbox_image=$( awk ' /sandbox_image/ && /=/ {
1161+ # Remove quotes and spaces
1162+ gsub(/[" ]/, "", $3)
1163+ print $3
1164+ }' FS=' =' " $config_file " )
1165+
1166+ # Alternative method if the above doesn't work
1167+ if [ -z " $sandbox_image " ]; then
1168+ sandbox_image=$( grep -E ' ^\s*sandbox_image\s*=' " $config_file " | sed ' s/.*sandbox_image\s*=\s*"\([^"]*\)".*/\1/' )
1169+ fi
1170+
1171+ echo " $sandbox_image "
1172+ }
11071173# HELPERSEOF
0 commit comments