Skip to content
Open
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
26 changes: 26 additions & 0 deletions staging/cse/windows/configfunc.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,32 @@ providers:
apiVersion: credentialprovider.kubelet.k8s.io/v1
args:
- $azureConfigFile
"@
}
elseif (![string]::IsNullOrEmpty($global:BootstrapProfileContainerRegistryServer)) {
$mcrRegistry = if ((Test-Path variable:global:MCRRepositoryBase) -and
-not [string]::IsNullOrEmpty($global:MCRRepositoryBase)) {
([string]$global:MCRRepositoryBase).TrimEnd("/")
}
else {
"mcr.microsoft.com"
}
$credentialProviderConfig = @"
apiVersion: kubelet.config.k8s.io/v1
kind: CredentialProviderConfig
providers:
- name: acr-credential-provider
matchImages:
- "*.azurecr.io"
- "*.azurecr.cn"
- "*.azurecr.de"
- "*.azurecr.us"
- "${mcrRegistry}"
defaultCacheDuration: "10m"
apiVersion: credentialprovider.kubelet.k8s.io/v1
args:
- $azureConfigFile
- --registry-mirror=${mcrRegistry}:{$global:BootstrapProfileContainerRegistryServer}
"@
Comment thread
fseldow marked this conversation as resolved.
}
$credentialProviderConfig | Out-File -encoding ASCII -filepath "$CredentialProviderConfPATH"
Expand Down
55 changes: 55 additions & 0 deletions staging/cse/windows/configfunc.tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,61 @@ Describe 'Config-CredentialProvider' {
$normalizedActual | Should -Be $normalizedExpected
}
}
Context 'BootstrapProfileContainerRegistryServer is set with default MCR' {
BeforeEach {
$global:BootstrapProfileContainerRegistryServer = "myregistry.azurecr.io"
# Ensure MCRRepositoryBase is not set so it falls back to mcr.microsoft.com
Remove-Variable -Name MCRRepositoryBase -Scope Global -ErrorAction SilentlyContinue
}
AfterEach {
$global:BootstrapProfileContainerRegistryServer = $null
}
It "should include mcr.microsoft.com in matchImages and registry-mirror arg" {
$expectedCredentialProviderConfig = Read-Format-Yaml ([Io.path]::Combine($credentialProviderConfigDir, "BootstrapProfileContainerRegistryServerDefault.config.yaml"))
Config-CredentialProvider -KubeDir $credentialProviderConfigDir -CredentialProviderConfPath $CredentialProviderConfPATH -CustomCloudContainerRegistryDNSSuffix ""
$acutalCredentialProviderConfig = Read-Format-Yaml $CredentialProviderConfPATH

$normalizedExpected = $expectedCredentialProviderConfig.Trim().Replace("`r`n", "`n")
$normalizedActual = $acutalCredentialProviderConfig.Trim().Replace("`r`n", "`n")
$normalizedActual | Should -Be $normalizedExpected
}
}
Comment on lines +156 to +174
Context 'BootstrapProfileContainerRegistryServer is set with custom MCRRepositoryBase' {
BeforeEach {
$global:BootstrapProfileContainerRegistryServer = "myregistry.azurecr.io"
$global:MCRRepositoryBase = "custom.mcr.contoso.com"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Low / Test Coverage — This value has no trailing slash, so the .TrimEnd("/") you added in configfunc.ps1 never runs in the tests. Set it to custom.mcr.contoso.com/ and keep the fixture without the slash, so the test proves the trim works.

}
AfterEach {
$global:BootstrapProfileContainerRegistryServer = $null
$global:MCRRepositoryBase = $null
}
It "should use custom MCRRepositoryBase in matchImages and registry-mirror arg" {
$expectedCredentialProviderConfig = Read-Format-Yaml ([Io.path]::Combine($credentialProviderConfigDir, "BootstrapProfileContainerRegistryServerCustomMCR.config.yaml"))
Config-CredentialProvider -KubeDir $credentialProviderConfigDir -CredentialProviderConfPath $CredentialProviderConfPATH -CustomCloudContainerRegistryDNSSuffix ""
$acutalCredentialProviderConfig = Read-Format-Yaml $CredentialProviderConfPATH

$normalizedExpected = $expectedCredentialProviderConfig.Trim().Replace("`r`n", "`n")
$normalizedActual = $acutalCredentialProviderConfig.Trim().Replace("`r`n", "`n")
$normalizedActual | Should -Be $normalizedExpected
}
}
Context 'CustomCloudContainerRegistryDNSSuffix takes precedence over BootstrapProfileContainerRegistryServer' {
BeforeEach {
$global:BootstrapProfileContainerRegistryServer = "myregistry.azurecr.io"
}
AfterEach {
$global:BootstrapProfileContainerRegistryServer = $null
}
It "should use CustomCloud config and not include registry-mirror when both are set" {
$expectedCredentialProviderConfig = Read-Format-Yaml ([Io.path]::Combine($credentialProviderConfigDir, "CustomCloudContainerRegistryDNSSuffixNotEmpty.config.yaml"))
Config-CredentialProvider -KubeDir $credentialProviderConfigDir -CredentialProviderConfPath $CredentialProviderConfPATH -CustomCloudContainerRegistryDNSSuffix ".azurecr.microsoft.fakecloud"
$acutalCredentialProviderConfig = Read-Format-Yaml $CredentialProviderConfPATH

$normalizedExpected = $expectedCredentialProviderConfig.Trim().Replace("`r`n", "`n")
$normalizedActual = $acutalCredentialProviderConfig.Trim().Replace("`r`n", "`n")
$normalizedActual | Should -Be $normalizedExpected
}
}
}

Describe 'Validate-CredentialProviderConfigFlags' {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
apiVersion: kubelet.config.k8s.io/v1
kind: CredentialProviderConfig
providers:
- name: acr-credential-provider
matchImages:
- "*.azurecr.io"
- "*.azurecr.cn"
- "*.azurecr.de"
- "*.azurecr.us"
- "custom.mcr.contoso.com"
defaultCacheDuration: "10m"
apiVersion: credentialprovider.kubelet.k8s.io/v1
args:
- staging\cse\windows\credentialProvider.tests.suites\azure.json
- --registry-mirror=custom.mcr.contoso.com:myregistry.azurecr.io
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
apiVersion: kubelet.config.k8s.io/v1
kind: CredentialProviderConfig
providers:
- name: acr-credential-provider
matchImages:
- "*.azurecr.io"
- "*.azurecr.cn"
- "*.azurecr.de"
- "*.azurecr.us"
- "mcr.microsoft.com"
defaultCacheDuration: "10m"
apiVersion: credentialprovider.kubelet.k8s.io/v1
args:
- staging\cse\windows\credentialProvider.tests.suites\azure.json
- --registry-mirror=mcr.microsoft.com:myregistry.azurecr.io
Loading