Skip to content

Commit b938c10

Browse files
committed
feat: port over bootstrap latency improvements
1 parent d79cdc5 commit b938c10

13 files changed

Lines changed: 171 additions & 59 deletions

File tree

e2e/config/vhd.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,15 @@ var (
218218
OSDiskSizeGB: 60,
219219
}
220220

221+
VHDAzureLinuxV3Gen2Arm64 = &Image{
222+
Name: "azurelinuxv3gen2arm64",
223+
OS: OSAzureLinux,
224+
Arch: "arm64",
225+
Distro: datamodel.AKSAzureLinuxV3Arm64Gen2,
226+
Gallery: imageGalleryLinux,
227+
OSDiskSizeGB: 60,
228+
}
229+
221230
VHDACLGen2TL = &Image{
222231
Name: "aclgen2TL",
223232
OS: OSACL,

e2e/scenario_gpu_managed_experience_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,9 @@ func Test_DCGM_Exporter_Compatibility(t *testing.T) {
190190
t.Run(tc.name, func(t *testing.T) {
191191
RunScenario(t, &Scenario{
192192
Description: tc.description,
193+
Tags: Tags{
194+
GPU: true,
195+
},
193196
Config: Config{
194197
Cluster: ClusterKubenet,
195198
VHD: tc.vhd,

e2e/scenario_test.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,25 @@ func Test_Flatcar_ARM64(t *testing.T) {
106106
})
107107
}
108108

109+
func Test_AzureLinuxV3_ARM64(t *testing.T) {
110+
RunScenario(t, &Scenario{
111+
Description: "Tests that a node using a AzureLinuxV3 VHD on ARM64 architecture can be properly bootstrapped",
112+
Config: Config{
113+
Cluster: ClusterKubenet,
114+
VHD: config.VHDAzureLinuxV3Gen2Arm64,
115+
BootstrapConfigMutator: func(nbc *datamodel.NodeBootstrappingConfiguration) {
116+
nbc.AgentPoolProfile.VMSize = "Standard_D2pds_V5"
117+
nbc.IsARM64 = true
118+
},
119+
Validator: func(ctx context.Context, s *Scenario) {
120+
},
121+
VMConfigMutator: func(vmss *armcompute.VirtualMachineScaleSet) {
122+
vmss.SKU.Name = to.Ptr("Standard_D2pds_V5")
123+
},
124+
},
125+
})
126+
}
127+
109128
func Test_Flatcar_AzureCNI(t *testing.T) {
110129
RunScenario(t, &Scenario{
111130
Description: "Flatcar scenario on a cluster configured with Azure CNI",

parts/linux/cloud-init/artifacts/cse_config.sh

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -164,20 +164,16 @@ configureCustomCaCertificate() {
164164
done
165165
# blocks until svc is considered active, which will happen when ExecStart command terminates with code 0
166166
systemctl restart update_certs.service || exit $ERR_UPDATE_CA_CERTS
167-
# containerd has to be restarted after new certs are added to the trust store, otherwise they will not be used until restart happens
168-
systemctl restart containerd
169167
}
170168

171169
configureContainerdUlimits() {
172170
CONTAINERD_ULIMIT_DROP_IN_FILE_PATH="/etc/systemd/system/containerd.service.d/set_ulimits.conf"
171+
mkdir -p "$(dirname "${CONTAINERD_ULIMIT_DROP_IN_FILE_PATH}")"
173172
touch "${CONTAINERD_ULIMIT_DROP_IN_FILE_PATH}"
174173
chmod 0600 "${CONTAINERD_ULIMIT_DROP_IN_FILE_PATH}"
175174
tee "${CONTAINERD_ULIMIT_DROP_IN_FILE_PATH}" > /dev/null <<EOF
176175
$(echo "$CONTAINERD_ULIMITS" | tr ' ' '\n')
177176
EOF
178-
179-
systemctl daemon-reload
180-
systemctl restart containerd
181177
}
182178

183179
# file paths defined outside so configureAzureJson can be unit tested
@@ -383,8 +379,9 @@ net.ipv4.conf.all.forwarding = 1
383379
net.ipv6.conf.all.forwarding = 1
384380
net.bridge.bridge-nf-call-iptables = 1
385381
EOF
386-
retrycmd_if_failure 120 5 25 sysctl --system || exit $ERR_SYSCTL_RELOAD
387-
systemctlEnableAndStart containerd 30 || exit $ERR_SYSTEMCTL_START_FAIL
382+
# ensureSysctl occurs after this, we already call sysctl --system in ensureSysctl calling it here is a waste
383+
retrycmd_if_failure 120 5 25 sysctl -p /etc/sysctl.d/99-force-bridge-forward.conf || exit $ERR_SYSCTL_RELOAD
384+
systemctlEnableAndStartNoBlock containerd 30 || exit $ERR_SYSTEMCTL_START_FAIL
388385
}
389386

390387
configureContainerdRegistryHost() {
@@ -431,6 +428,7 @@ ensureTeleportd() {
431428
}
432429

433430
ensureArtifactStreaming() {
431+
waitForContainerdReady || exit $ERR_ARTIFACT_STREAMING_INSTALL
434432
retrycmd_if_failure 120 5 25 time systemctl --quiet enable --now acr-mirror overlaybd-tcmu overlaybd-snapshotter
435433
time /opt/acr/bin/acr-config --enable-containerd 'azurecr.io'
436434
}
@@ -573,6 +571,8 @@ ensurePodInfraContainerImage() {
573571
POD_INFRA_CONTAINER_IMAGE_DOWNLOAD_DIR="/opt/pod-infra-container-image/downloads"
574572
POD_INFRA_CONTAINER_IMAGE_TAR="/opt/pod-infra-container-image/pod-infra-container-image.tar"
575573

574+
waitForContainerdReady || exit $ERR_PULL_POD_INFRA_CONTAINER_IMAGE
575+
576576
pod_infra_container_image=$(get_sandbox_image)
577577

578578
if [ -z "${pod_infra_container_image}" ]; then
@@ -783,17 +783,22 @@ EOF
783783
logs_to_events "AKS.CSE.ensureKubelet.ensurePodInfraContainerImage" ensurePodInfraContainerImage
784784
fi
785785

786-
# start measure-tls-bootstrapping-latency.service without waiting for the main process to start, while ignoring any failures
787-
if ! systemctlEnableAndStartNoBlock measure-tls-bootstrapping-latency 30; then
788-
echo "failed to start measure-tls-bootstrapping-latency.service"
789-
fi
786+
TLS_BOOTSTRAPPING_START_TIME_FILEPATH="/opt/azure/containers/tls-bootstrap-start-time"
787+
date +"%F %T.%3N" > "${TLS_BOOTSTRAPPING_START_TIME_FILEPATH}"
790788

791789
# start kubelet.service without waiting for the main process to start, though check whether it has entered a failed state after enablement
792790
if ! systemctlEnableAndStartNoBlock kubelet 240; then
793791
# append kubelet status to CSE output to ensure we can see it
792+
rm -f "${TLS_BOOTSTRAPPING_START_TIME_FILEPATH}"
794793
journalctl -u kubelet.service --no-pager || true
795794
exit $ERR_KUBELET_START_FAIL
796795
fi
796+
797+
# start measure-tls-bootstrapping-latency.service without waiting for the main process to start, while ignoring any failures
798+
if ! systemctlEnableAndStartNoBlock measure-tls-bootstrapping-latency 30; then
799+
rm -f "${TLS_BOOTSTRAPPING_START_TIME_FILEPATH}"
800+
echo "failed to start measure-tls-bootstrapping-latency.service"
801+
fi
797802
}
798803

799804
ensureSnapshotUpdate() {
@@ -930,6 +935,7 @@ configAzurePolicyAddon() {
930935

931936
configGPUDrivers() {
932937
if [ "$OS" = "$UBUNTU_OS_NAME" ]; then
938+
waitForContainerdReady || exit $ERR_GPU_DRIVERS_START_FAIL
933939
mkdir -p /opt/{actions,gpu}
934940
ctr -n k8s.io image pull $NVIDIA_DRIVER_IMAGE:$NVIDIA_DRIVER_IMAGE_TAG
935941
retrycmd_if_failure 5 10 600 bash -c "$CTR_GPU_INSTALL_CMD $NVIDIA_DRIVER_IMAGE:$NVIDIA_DRIVER_IMAGE_TAG gpuinstall /entrypoint.sh install"

parts/linux/cloud-init/artifacts/cse_helpers.sh

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -509,19 +509,20 @@ systemctlEnableAndStart() {
509509
service=$1; timeout=$2
510510
systemctl_restart 100 5 $timeout $service
511511
RESTART_STATUS=$?
512-
systemctl status $service --no-pager -l > /var/log/azure/$service-status.log
513512
if [ $RESTART_STATUS -ne 0 ]; then
514513
echo "$service could not be started"
514+
systemctl status $service --no-pager -l > /var/log/azure/$service-status.log || true
515515
return 1
516516
fi
517517
if ! retrycmd_if_failure 120 5 25 systemctl enable $service; then
518518
echo "$service could not be enabled by systemctl"
519+
systemctl status $service --no-pager -l > /var/log/azure/$service-status.log || true
519520
return 1
520521
fi
521522
}
522523

523524
systemctlEnableAndStartNoBlock() {
524-
service=$1; timeout=$2; status_check_delay_seconds=${3:-"0"}
525+
service=$1; timeout=$2
525526

526527
systemctl_restart_no_block 100 5 $timeout $service
527528
RESTART_STATUS=$?
@@ -536,21 +537,37 @@ systemctlEnableAndStartNoBlock() {
536537
systemctl status $service --no-pager -l > /var/log/azure/$service-status.log || true
537538
return 1
538539
fi
540+
}
541+
542+
checkServiceHealth() {
543+
service=$1
544+
545+
state=$(systemctl show -p ActiveState --value "$service")
546+
547+
if [ "$state" = "active" ]; then
548+
return 0
549+
fi
539550

540-
# wait for the specified delay seconds before checking the service status to make sure
541-
# it hasn't gone into a failed state
542-
sleep $status_check_delay_seconds
551+
systemctl status "$service" --no-pager -l > "/var/log/azure/$service-status.log" || true
543552

544-
if systemctl is-failed $service; then
553+
if [ "$state" = "failed" ]; then
545554
echo "$service is in a failed state"
546-
systemctl status $service --no-pager -l > /var/log/azure/$service-status.log || true
547555
return 1
556+
elif [ "$state" = "activating" ]; then
557+
echo "$service is still activating, continuing anyway..."
548558
fi
559+
}
549560

550-
# systemctl status only exits with code 0 iff the service is "active",
551-
# thus we handle the "activating" case by checking for a non-zero exit code
552-
if ! systemctl status $service --no-pager -l > /var/log/azure/$service-status.log; then
553-
echo "$service is still activating, continuing anyway..."
561+
waitForContainerdReady() {
562+
local ret=0
563+
564+
echo "Waiting for containerd to become ready..."
565+
retrycmd_if_failure 60 0.1 1 bash -c 'ctr version >/dev/null 2>&1'
566+
ret=$?
567+
if [ "$ret" -ne 0 ]; then
568+
echo "containerd did not become ready"
569+
systemctl status containerd --no-pager -l > /var/log/azure/containerd-status.log || true
570+
return 1
554571
fi
555572
}
556573

parts/linux/cloud-init/artifacts/cse_install.sh

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -658,8 +658,11 @@ installKubeletKubectlFromURL() {
658658
fi
659659
fi
660660
fi
661-
install -m0755 "/opt/bin/kubelet-${KUBERNETES_VERSION}" /opt/bin/kubelet
662-
install -m0755 "/opt/bin/kubectl-${KUBERNETES_VERSION}" /opt/bin/kubectl
661+
662+
mv "/opt/bin/kubelet-${KUBERNETES_VERSION}" /opt/bin/kubelet
663+
mv "/opt/bin/kubectl-${KUBERNETES_VERSION}" /opt/bin/kubectl
664+
665+
chmod a+x /opt/bin/kubelet /opt/bin/kubectl
663666

664667
rm -rf /opt/bin/kubelet-* /opt/bin/kubectl-* /home/hyperkube-downloads &
665668
}
@@ -726,8 +729,9 @@ labelContainerImage() {
726729
}
727730

728731
retagMCRImagesForChina() {
732+
waitForContainerdReady || exit $ERR_CTR_OPERATION_ERROR
729733
# shellcheck disable=SC2016
730-
allMCRImages=($(ctr --namespace k8s.io images list | grep '^mcr.microsoft.com/' | awk '{print $1}'))
734+
allMCRImages=($(ctr --namespace k8s.io images list | grep '^mcr.microsoft.com/' | awk '{print $1}'))
731735
if [ -z "${allMCRImages}" ]; then
732736
echo "failed to find mcr images for retag"
733737
return

parts/linux/cloud-init/artifacts/cse_main.sh

Lines changed: 31 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -152,9 +152,13 @@ function basePrep {
152152
echo "Golden image; skipping dependencies installation"
153153
fi
154154

155-
# Container runtime already installed on Azure Linux OS Guard
156-
if ! isAzureLinuxOSGuard "$OS" "$OS_VARIANT"; then
155+
# Container runtime already installed on Azure Linux OS Guard; an explicit containerd override can bypass FULL_INSTALL_REQUIRED for other Linux distros
156+
if isAzureLinuxOSGuard "$OS" "$OS_VARIANT"; then
157+
echo "Skipping installContainerRuntime because containerd is already available"
158+
elif [ "$FULL_INSTALL_REQUIRED" = "true" ] || [ -n "${CONTAINERD_PACKAGE_URL}" ]; then
157159
logs_to_events "AKS.CSE.installContainerRuntime" installContainerRuntime
160+
else
161+
echo "Skipping installContainerRuntime because containerd is already available"
158162
fi
159163
if [ "${TELEPORT_ENABLED}" = "true" ]; then
160164
logs_to_events "AKS.CSE.installTeleportdPlugin" installTeleportdPlugin
@@ -174,6 +178,9 @@ function basePrep {
174178
SHOULD_ENFORCE_KUBE_PMC_INSTALL=$(should_enforce_kube_pmc_install)
175179
logs_to_events "AKS.CSE.configureKubeletAndKubectl" configureKubeletAndKubectl
176180

181+
# pre-warm kubelet by checking its version.
182+
nohup /bin/sh -c '/opt/bin/kubelet --version >/dev/null 2>&1' >/dev/null 2>&1 &
183+
177184
createKubeManifestDir
178185

179186
if [ "${HAS_CUSTOM_SEARCH_DOMAIN}" = "true" ]; then
@@ -198,6 +205,10 @@ function basePrep {
198205
logs_to_events "AKS.CSE.configureSystemdUseDomains" configureSystemdUseDomains
199206
fi
200207

208+
if [ "${SHOULD_CONFIG_CONTAINERD_ULIMITS}" = "true" ]; then
209+
logs_to_events "AKS.CSE.setContainerdUlimits" configureContainerdUlimits
210+
fi
211+
201212
# containerd should not be configured until cni has been configured first
202213
logs_to_events "AKS.CSE.ensureContainerd" ensureContainerd
203214

@@ -272,14 +283,6 @@ EOF
272283

273284
logs_to_events "AKS.CSE.ensureSysctl" ensureSysctl || exit $ERR_SYSCTL_RELOAD
274285

275-
if [ "${SHOULD_CONFIG_CONTAINERD_ULIMITS}" = "true" ]; then
276-
logs_to_events "AKS.CSE.setContainerdUlimits" configureContainerdUlimits
277-
fi
278-
279-
if [ "${ENSURE_NO_DUPE_PROMISCUOUS_BRIDGE}" = "true" ]; then
280-
logs_to_events "AKS.CSE.ensureNoDupOnPromiscuBridge" ensureNoDupOnPromiscuBridge
281-
fi
282-
283286
if ! isAzureLinuxOSGuard "$OS" "$OS_VARIANT"; then
284287
if [ "$OS" = "$UBUNTU_OS_NAME" ] || isMarinerOrAzureLinux "$OS"; then
285288
logs_to_events "AKS.CSE.ubuntuSnapshotUpdate" ensureSnapshotUpdate
@@ -298,10 +301,6 @@ EOF
298301
logs_to_events "AKS.CSE.ensureContainerd.ensureArtifactStreaming" ensureArtifactStreaming || exit $ERR_ARTIFACT_STREAMING_INSTALL
299302
fi
300303

301-
if [ "${SHOULD_ENABLE_LOCALDNS}" = "true" ]; then
302-
logs_to_events "AKS.CSE.enableLocalDNS" enableLocalDNS || exit $ERR_LOCALDNS_FAIL
303-
fi
304-
305304
if [ "${ID}" != "mariner" ] && [ "${ID}" != "azurelinux" ]; then
306305
echo "Recreating man-db auto-update flag file and kicking off man-db update process at $(date)"
307306
createManDbAutoUpdateFlagFile
@@ -355,11 +354,6 @@ function nodePrep {
355354
# By default, never reboot new nodes.
356355
REBOOTREQUIRED=false
357356

358-
# Clean up GPU drivers if not a GPU node or if skipping driver install
359-
if [ "${GPU_NODE}" != "true" ] || [ "${skip_nvidia_driver_install}" = "true" ]; then
360-
logs_to_events "AKS.CSE.cleanUpGPUDrivers" cleanUpGPUDrivers
361-
fi
362-
363357
# Install and configure GPU drivers if this is a GPU node
364358
if [ "${GPU_NODE}" = "true" ] && [ "${skip_nvidia_driver_install}" != "true" ]; then
365359
echo $(date),$(hostname), "Start configuring GPU drivers"
@@ -488,10 +482,28 @@ function nodePrep {
488482
exit $VALIDATION_ERR
489483
fi
490484

485+
checkServiceHealth containerd || exit $ERR_SYSTEMCTL_START_FAIL
486+
if [ "${ENABLE_SECURE_TLS_BOOTSTRAPPING}" = "true" ]; then
487+
checkServiceHealth secure-tls-bootstrap || exit $ERR_SYSTEMCTL_START_FAIL
488+
fi
489+
491490
logs_to_events "AKS.CSE.ensureKubelet" ensureKubelet
492491

492+
if [ "${ENSURE_NO_DUPE_PROMISCUOUS_BRIDGE}" = "true" ]; then
493+
logs_to_events "AKS.CSE.ensureNoDupOnPromiscuBridge" ensureNoDupOnPromiscuBridge
494+
fi
495+
496+
if [ "${SHOULD_ENABLE_LOCALDNS}" = "true" ]; then
497+
logs_to_events "AKS.CSE.enableLocalDNS" enableLocalDNS || exit $ERR_LOCALDNS_FAIL
498+
fi
499+
493500
logs_to_events "AKS.CSE.configureNodeExporter" configureNodeExporter
494501

502+
# Clean up GPU drivers if not a GPU node or if skipping driver install
503+
if [ "${GPU_NODE}" != "true" ] || [ "${skip_nvidia_driver_install}" = "true" ]; then
504+
logs_to_events "AKS.CSE.cleanUpGPUDrivers" cleanUpGPUDrivers
505+
fi
506+
495507
if $REBOOTREQUIRED; then
496508
echo 'reboot required, rebooting node in 1 minute'
497509
/bin/bash -c "shutdown -r 1 &"

parts/linux/cloud-init/artifacts/kubelet.service

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ ExecStartPre=-/sbin/ebtables -t nat --list
2121
ExecStartPre=-/sbin/iptables -t nat --numeric --list
2222

2323
ExecStartPre=/bin/bash /opt/azure/containers/validate-kubelet-credentials.sh
24+
ExecStartPre=/bin/sh -c 'until [ -S /run/containerd/containerd.sock ]; do sleep 0.1; done'
2425

2526
ExecStart=/opt/bin/kubelet \
2627
--enable-server \

0 commit comments

Comments
 (0)