Skip to content

Commit 517d2ab

Browse files
authored
feat: add mooncake mcr containerd config host - linux (#7342)
1 parent 6cf9d3d commit 517d2ab

File tree

67 files changed

+247
-118
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+247
-118
lines changed

e2e/aks_model.go

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,14 +219,29 @@ func getFirewall(ctx context.Context, location, firewallSubnetID, publicIPID str
219219
TargetFqdns: []*string{to.Ptr(blobStorageFqdn)},
220220
}
221221

222+
// needed for Mock Azure China Cloud tests
223+
mooncakeMAR := "mcr.azure.cn"
224+
mooncakeMARData := "*.data.mcr.azure.cn"
225+
mooncakeMARRule := armnetwork.AzureFirewallApplicationRule{
226+
Name: to.Ptr("mooncake-mar-fqdn"),
227+
SourceAddresses: []*string{to.Ptr("*")},
228+
Protocols: []*armnetwork.AzureFirewallApplicationRuleProtocol{
229+
{
230+
ProtocolType: to.Ptr(armnetwork.AzureFirewallApplicationRuleProtocolTypeHTTPS),
231+
Port: to.Ptr[int32](443),
232+
},
233+
},
234+
TargetFqdns: []*string{to.Ptr(mooncakeMAR), to.Ptr(mooncakeMARData)},
235+
}
236+
222237
appRuleCollection := armnetwork.AzureFirewallApplicationRuleCollection{
223238
Name: to.Ptr("aksfwar"),
224239
Properties: &armnetwork.AzureFirewallApplicationRuleCollectionPropertiesFormat{
225240
Priority: to.Ptr[int32](100),
226241
Action: &armnetwork.AzureFirewallRCAction{
227242
Type: to.Ptr(armnetwork.AzureFirewallRCActionTypeAllow),
228243
},
229-
Rules: []*armnetwork.AzureFirewallApplicationRule{&aksAppRule, &blobStorageAppRule},
244+
Rules: []*armnetwork.AzureFirewallApplicationRule{&aksAppRule, &blobStorageAppRule, &mooncakeMARRule},
230245
},
231246
}
232247

e2e/kube.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -471,6 +471,9 @@ func getClusterSubnetID(ctx context.Context, mcResourceGroupName string) (string
471471

472472
func podHTTPServerLinux(s *Scenario) *corev1.Pod {
473473
image := "mcr.microsoft.com/cbl-mariner/busybox:2.0"
474+
if s.Tags.MockAzureChinaCloud {
475+
image = "mcr.azk8s.cn/cbl-mariner/busybox:2.0"
476+
}
474477
return &corev1.Pod{
475478
ObjectMeta: metav1.ObjectMeta{
476479
Name: fmt.Sprintf("%s-test-pod", s.Runtime.VM.KubeName),

e2e/scenario_test.go

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1846,6 +1846,61 @@ func Test_Ubuntu2404Gen2(t *testing.T) {
18461846
})
18471847
}
18481848

1849+
func Test_Ubuntu2404Gen2_McrChinaCloud_Scriptless(t *testing.T) {
1850+
RunScenario(t, &Scenario{
1851+
Tags: Tags{
1852+
MockAzureChinaCloud: true,
1853+
Scriptless: true,
1854+
},
1855+
Description: "Tests that a node using the Ubuntu 2404 VHD can be properly bootstrapped with containerd v2",
1856+
Config: Config{
1857+
Cluster: ClusterKubenet,
1858+
VHD: config.VHDUbuntu2404Gen2Containerd,
1859+
AKSNodeConfigMutator: func(config *aksnodeconfigv1.Configuration) {
1860+
},
1861+
VMConfigMutator: func(vmss *armcompute.VirtualMachineScaleSet) {
1862+
if vmss.Tags == nil {
1863+
vmss.Tags = map[string]*string{}
1864+
}
1865+
vmss.Tags["E2EMockAzureChinaCloud"] = to.Ptr("true")
1866+
},
1867+
Validator: func(ctx context.Context, s *Scenario) {
1868+
ValidateDirectoryContent(ctx, s, "/etc/containerd/certs.d/mcr.azk8s.cn", []string{"hosts.toml"})
1869+
},
1870+
},
1871+
})
1872+
}
1873+
1874+
func Test_Ubuntu2404Gen2_McrChinaCloud(t *testing.T) {
1875+
RunScenario(t, &Scenario{
1876+
Tags: Tags{
1877+
MockAzureChinaCloud: true,
1878+
},
1879+
Description: "Tests that a node using the Ubuntu 2404 VHD can be properly bootstrapped with containerd v2",
1880+
Config: Config{
1881+
Cluster: ClusterKubenet,
1882+
VHD: config.VHDUbuntu2404Gen2Containerd,
1883+
BootstrapConfigMutator: func(nbc *datamodel.NodeBootstrappingConfiguration) {
1884+
},
1885+
VMConfigMutator: func(vmss *armcompute.VirtualMachineScaleSet) {
1886+
if vmss.Tags == nil {
1887+
vmss.Tags = map[string]*string{}
1888+
}
1889+
vmss.Tags["E2EMockAzureChinaCloud"] = to.Ptr("true")
1890+
},
1891+
Validator: func(ctx context.Context, s *Scenario) {
1892+
containerdVersions := components.GetExpectedPackageVersions("containerd", "ubuntu", "r2404")
1893+
runcVersions := components.GetExpectedPackageVersions("runc", "ubuntu", "r2404")
1894+
ValidateContainerd2Properties(ctx, s, containerdVersions)
1895+
ValidateRuncVersion(ctx, s, runcVersions)
1896+
ValidateContainerRuntimePlugins(ctx, s)
1897+
ValidateSSHServiceEnabled(ctx, s)
1898+
ValidateDirectoryContent(ctx, s, "/etc/containerd/certs.d/mcr.azk8s.cn", []string{"hosts.toml"})
1899+
},
1900+
},
1901+
})
1902+
}
1903+
18491904
func Test_Ubuntu2204_SecureTLSBootstrapping_BootstrapToken_Fallback(t *testing.T) {
18501905
RunScenario(t, &Scenario{
18511906
Description: "Tests that a node using an Ubuntu 2204 Gen2 VHD can be properly bootstrapped even if secure TLS bootstrapping fails",

e2e/types.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ type Tags struct {
3333
KubeletCustomConfig bool
3434
Scriptless bool
3535
VHDCaching bool
36+
MockAzureChinaCloud bool
3637
}
3738

3839
// MatchesFilters checks if the Tags struct matches all given filters.

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

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,8 +355,12 @@ EOF
355355
echo "${CONTAINERD_CONFIG_CONTENT}" | base64 -d > /etc/containerd/config.toml || exit $ERR_FILE_WATCH_TIMEOUT
356356
fi
357357

358+
export -f e2e_mock_azure_china_cloud
359+
E2EMockAzureChinaCloud=$(retrycmd_silent 10 1 10 bash -cx e2e_mock_azure_china_cloud)
358360
if [ -n "${BOOTSTRAP_PROFILE_CONTAINER_REGISTRY_SERVER}" ]; then
359361
logs_to_events "AKS.CSE.ensureContainerd.configureContainerdRegistryHost" configureContainerdRegistryHost
362+
elif [ "${TARGET_CLOUD}" = "AzureChinaCloud" ] || [ "${E2EMockAzureChinaCloud}" = "true" ]; then
363+
logs_to_events "AKS.CSE.ensureContainerd.configureContainerdLegacyMooncakeMcrHost" configureContainerdLegacyMooncakeMcrHost
360364
fi
361365

362366
tee "/etc/sysctl.d/99-force-bridge-forward.conf" > /dev/null <<EOF
@@ -384,6 +388,24 @@ configureContainerdRegistryHost() {
384388
EOF
385389
}
386390

391+
# this function craetes containerd host config to map mcr.azk8s.cn host to mcr.azure.cn
392+
# containerd will resolve mcr.azk8s.cn as mcr.azure.cn and pull the image. If failed, it will fallback to mcr.azk8s.cn
393+
# https://github.com/containerd/containerd/blob/main/docs/hosts.md#registry-configuration---examples
394+
# TODO(xinhl): remove when aks rp fully deprecates mcr.azk8s.cn
395+
configureContainerdLegacyMooncakeMcrHost() {
396+
LEGACY_MCR_REPOSITORY_BASE="mcr.azk8s.cn"
397+
CONTAINERD_CONFIG_REGISTRY_HOST_MCR="/etc/containerd/certs.d/${LEGACY_MCR_REPOSITORY_BASE}/hosts.toml"
398+
mkdir -p "$(dirname "${CONTAINERD_CONFIG_REGISTRY_HOST_MCR}")"
399+
touch "${CONTAINERD_CONFIG_REGISTRY_HOST_MCR}"
400+
chmod 0644 "${CONTAINERD_CONFIG_REGISTRY_HOST_MCR}"
401+
402+
TARGET_MCR_REPOSITORY_BASE="mcr.azure.cn"
403+
tee "${CONTAINERD_CONFIG_REGISTRY_HOST_MCR}" > /dev/null <<EOF
404+
[host."https://${TARGET_MCR_REPOSITORY_BASE}"]
405+
capabilities = ["pull", "resolve"]
406+
EOF
407+
}
408+
387409
ensureNoDupOnPromiscuBridge() {
388410
systemctlEnableAndStart ensure-no-dup 30 || exit $ERR_SYSTEMCTL_START_FAIL
389411
}

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -687,6 +687,17 @@ should_enforce_kube_pmc_install() {
687687
echo "${should_enforce,,}"
688688
}
689689

690+
e2e_mock_azure_china_cloud() {
691+
set -x
692+
body=$(curl -fsSL -H "Metadata: true" --noproxy "*" "http://169.254.169.254/metadata/instance?api-version=2021-02-01")
693+
ret=$?
694+
if [ "$ret" -ne 0 ]; then
695+
return $ret
696+
fi
697+
should_enforce=$(echo "$body" | jq -r '.compute.tagsList[] | select(.name == "E2EMockAzureChinaCloud") | .value')
698+
echo "${should_enforce,,}"
699+
}
700+
690701
enableManagedGPUExperience() {
691702
set -x
692703
body=$(curl -fsSL -H "Metadata: true" --noproxy "*" "http://169.254.169.254/metadata/instance?api-version=2021-02-01")

0 commit comments

Comments
 (0)