Skip to content

Commit fd71499

Browse files
authored
Fix the issue of service principal. (#13458)
Co-authored-by: wyunchi-ms <[email protected]>
1 parent 4aa08c0 commit fd71499

File tree

5 files changed

+1982
-1
lines changed

5 files changed

+1982
-1
lines changed

src/Aks/Aks.Test/ScenarioTests/KubernetesTests.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,13 @@ public void TestAzureKubernetes()
3131
TestController.NewInstance.RunPowerShellTest(_logger, "Test-NewAzAks");
3232
}
3333

34+
[Fact]
35+
[Trait(Category.AcceptanceType, Category.CheckIn)]
36+
public void TestNewAzureKubernetesByServicePrincipal()
37+
{
38+
TestController.NewInstance.RunPowerShellTest(_logger, "Test-NewAzAksByServicePrincipal");
39+
}
40+
3441
[Fact]
3542
[Trait(Category.AcceptanceType, Category.CheckIn)]
3643
public void TestAzureKubernetesAddons()

src/Aks/Aks.Test/ScenarioTests/KubernetesTests.ps1

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,37 @@ function Test-NewAzAks
146146
}
147147
}
148148

149+
function Test-NewAzAksByServicePrincipal
150+
{
151+
# Setup
152+
$resourceGroupName = Get-RandomResourceGroupName
153+
$kubeClusterName = Get-RandomClusterName
154+
$location = "eastus"
155+
156+
$ServicePrincipalId = '618a2a3a-9d44-415a-b0ce-9729253a4ba9'
157+
$Secret = '5E41A57vC_ODdiFb5ji-a9~C~Mp3gKt7D~'
158+
$secStringPassword = ConvertTo-SecureString $Secret -AsPlainText -Force
159+
$credObject = New-Object System.Management.Automation.PSCredential($ServicePrincipalId,$secStringPassword)
160+
161+
try
162+
{
163+
New-AzResourceGroup -Name $resourceGroupName -Location $location
164+
165+
166+
New-AzAksCluster -ResourceGroupName $resourceGroupName -Name $kubeClusterName `
167+
-ServicePrincipalIdAndSecret $credObject
168+
$cluster = Get-AzAksCluster -ResourceGroupName $resourceGroupName -Name $kubeClusterName
169+
Assert-AreEqual $ServicePrincipalId $cluster.ServicePrincipalProfile.ClientId
170+
171+
$cluster | Import-AzAksCredential -Force
172+
$cluster | Remove-AzAksCluster -Force
173+
}
174+
finally
175+
{
176+
Remove-AzResourceGroup -Name $resourceGroupName -Force
177+
}
178+
}
179+
149180
function Test-NewAzAksAddons
150181
{
151182
# Setup

0 commit comments

Comments
 (0)