Skip to content

Commit 4127fdd

Browse files
committed
update Az.AksArc tests and fix commands
1 parent 7d37d0d commit 4127fdd

File tree

73 files changed

+13881
-3508
lines changed

Some content is hidden

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

73 files changed

+13881
-3508
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the Apache License, Version 2.0 (the ""License"");
3+
// you may not use this file except in compliance with the License.
4+
// You may obtain a copy of the License at
5+
// http://www.apache.org/licenses/LICENSE-2.0
6+
// Unless required by applicable law or agreed to in writing, software
7+
// distributed under the License is distributed on an ""AS IS"" BASIS,
8+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
9+
// See the License for the specific language governing permissions and
10+
// limitations under the License.
11+
// Code generated by Microsoft (R) AutoRest Code Generator.Changes may cause incorrect behavior and will be lost if the code
12+
// is regenerated.
13+
14+
using System;
15+
using System.Reflection;
16+
using System.Runtime.CompilerServices;
17+
using System.Runtime.InteropServices;
18+
19+
[assembly: System.Reflection.AssemblyCompanyAttribute("Microsoft")]
20+
[assembly: System.Reflection.AssemblyCopyrightAttribute("Copyright © Microsoft")]
21+
[assembly: System.Reflection.AssemblyProductAttribute("Microsoft Azure PowerShell")]
22+
[assembly: System.Reflection.AssemblyTitleAttribute("Microsoft Azure PowerShell - AksArc")]
23+
[assembly: System.Reflection.AssemblyFileVersionAttribute("0.1.4")]
24+
[assembly: System.Reflection.AssemblyVersionAttribute("0.1.4")]
25+
[assembly: System.Runtime.InteropServices.ComVisibleAttribute(false)]
26+
[assembly: System.CLSCompliantAttribute(false)]

src/AksArc/AksArc.Autorest/README.md

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -176,19 +176,6 @@ directive:
176176
subject: KubernetesVersion
177177
remove: true
178178

179-
# Rename parameters
180-
- where:
181-
subject: VirtualNetwork
182-
parameter-name: ExtendedLocationName
183-
set:
184-
parameter-name: CustomLocationID
185-
186-
- where:
187-
subject: VirtualNetwork
188-
parameter-name: ExtendedLocationName
189-
set:
190-
parameter-name: CustomLocationID
191-
192179
# Clusters
193180
- where:
194181
parameter-name: ControlPlaneEndpointHostIP

src/AksArc/AksArc.Autorest/custom/Az.AksArc.custom.psm1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
# region Generated
22
# Load the private module dll
3-
$null = Import-Module -PassThru -Name (Join-Path $PSScriptRoot '..\bin\Az.AksArc.private.dll')
3+
$null = Import-Module -PassThru -Name (Join-Path $PSScriptRoot '../bin/Az.AksArc.private.dll')
44

55
# Load the internal module
6-
$internalModulePath = Join-Path $PSScriptRoot '..\internal\Az.AksArc.internal.psm1'
6+
$internalModulePath = Join-Path $PSScriptRoot '../internal/Az.AksArc.internal.psm1'
77
if(Test-Path $internalModulePath) {
88
$null = Import-Module -Name $internalModulePath
99
}

src/AksArc/AksArc.Autorest/custom/Get-AzAksArcNodepool.ps1

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -74,12 +74,6 @@ param(
7474
# Parameter for the name of the agent pool in the provisioned cluster.
7575
${Name},
7676

77-
[Parameter(ParameterSetName='GetViaIdentity', Mandatory, ValueFromPipeline)]
78-
[Microsoft.Azure.PowerShell.Cmdlets.AksArc.Category('Path')]
79-
[Microsoft.Azure.PowerShell.Cmdlets.AksArc.Models.IAksArcIdentity]
80-
# Identity Parameter
81-
${InputObject},
82-
8377
[Parameter(DontShow)]
8478
[Microsoft.Azure.PowerShell.Cmdlets.AksArc.Category('Runtime')]
8579
[System.Management.Automation.SwitchParameter]
@@ -121,11 +115,14 @@ param(
121115
)
122116

123117
process {
124-
$Scope = GetConnectedClusterResourceURI -SubscriptionId $SubscriptionId -ResourceGroupName $ResourceGroupName -ClusterName $ClusterName
118+
$scope = GetConnectedClusterResourceURI `
119+
-SubscriptionId $SubscriptionId `
120+
-ResourceGroupName $ResourceGroupName `
121+
-ClusterName $ClusterName
125122
$null = $PSBoundParameters.Remove("SubscriptionId")
126123
$null = $PSBoundParameters.Remove("ResourceGroupName")
127124
$null = $PSBoundParameters.Remove("ClusterName")
128-
$null = $PSBoundParameters.Add("ConnectedClusterResourceUri", $Scope)
125+
$null = $PSBoundParameters.Add("ConnectedClusterResourceUri", $scope)
129126
Az.AksArc.internal\Get-AzAksArcNodepool @PSBoundParameters
130-
}
127+
}
131128
}

src/AksArc/AksArc.Autorest/custom/Invoke-AzAksArcClusterUpgrade.ps1

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ function Invoke-AzAksArcClusterUpgrade {
5555
[Parameter(ParameterSetName='Upgrade', Mandatory)]
5656
[Microsoft.Azure.PowerShell.Cmdlets.AksArc.Category('Body')]
5757
[System.String]
58-
# The version of Kubernetes in use by the provisioned cluster.
58+
# Kubernetes version to upgrade to. If not provided, the cluster will be upgraded to the latest supported version.
5959
${KubernetesVersion},
6060

6161
[Parameter()]
@@ -118,24 +118,21 @@ function Invoke-AzAksArcClusterUpgrade {
118118
$null = $PSBoundParameters.Add("ConnectedClusterResourceUri", $Scope)
119119

120120
# Upgrade Provisioned Cluster
121+
$Upgrades = Get-AzAksArcClusterUpgrade -ClusterName $ClusterName -ResourceGroupName $ResourceGroupName -SubscriptionId $SubscriptionId
121122
if ($PSBoundParameters.ContainsKey("KubernetesVersion"))
122123
{
123-
$Upgrades = Get-AzAksArcClusterUpgrade -ClusterName $ClusterName -ResourceGroupName $ResourceGroupName -SubscriptionId $SubscriptionId
124124
if (!($upgrades.ControlPlaneProfileUpgrade.KubernetesVersion -contains $KubernetesVersion)) {
125125
throw "Kubernetes Version $KubernetesVersion is not a valid upgradable version."
126126
}
127127
} else {
128-
$Upgrades = Get-AzAksArcClusterUpgrade -ClusterName $ClusterName -ResourceGroupName $ResourceGroupName -SubscriptionId $SubscriptionId
129-
$UpgradeListLength = $upgrades.ControlPlaneProfileUpgrade.KubernetesVersion.Length
130-
if ($UpgradeListLength -eq 0) {
128+
if ($upgrades.ControlPlaneProfileUpgrade.KubernetesVersion.Length -eq 0) {
131129
Write-Error "Already on latest kubernetes version."
132130
return
133131
}
134-
$LatestUpgrade = $upgrades.ControlPlaneProfileUpgrade[$UpgradeListLength-1].KubernetesVersion
135-
132+
$LatestUpgrade = $upgrades.ControlPlaneProfileUpgrade[-1].KubernetesVersion
136133
$null = $PSBoundParameters.Add("KubernetesVersion", $LatestUpgrade)
137134
}
138135

139136
Az.AksArc.internal\Update-AzAksArcCluster @PSBoundParameters
140137
}
141-
}
138+
}

src/AksArc/AksArc.Autorest/custom/New-AzAksArcCluster.ps1

Lines changed: 86 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -75,13 +75,6 @@ function New-AzAksArcCluster {
7575
[System.String]
7676
# ARM Id of the extended location.
7777
${CustomLocationName},
78-
79-
[Parameter(Mandatory)]
80-
[Microsoft.Azure.PowerShell.Cmdlets.AksArc.Category('Body')]
81-
[System.String]
82-
# List of ARM resource Ids (maximum 1) for the infrastructure network object e.g.
83-
# /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.AzureStackHCI/logicalNetworks/{logicalNetworkName}
84-
${VnetId},
8578

8679
[Parameter()]
8780
[Microsoft.Azure.PowerShell.Cmdlets.AksArc.Category('Body')]
@@ -92,15 +85,21 @@ function New-AzAksArcCluster {
9285
[Parameter()]
9386
[Microsoft.Azure.PowerShell.Cmdlets.AksArc.Category('Body')]
9487
[System.String]
95-
# Location
9688
${Location},
9789

9890
[Parameter()]
9991
[AllowEmptyCollection()]
10092
[Microsoft.Azure.PowerShell.Cmdlets.AksArc.Category('Body')]
10193
[System.String[]]
10294
${AdminGroupObjectID},
103-
95+
96+
[Parameter(ParameterSetName='CreateExpanded')]
97+
[Microsoft.Azure.PowerShell.Cmdlets.AksArc.Category('Body')]
98+
[System.String]
99+
# List of ARM resource Ids (maximum 1) for the infrastructure network object e.g.
100+
# /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.AzureStackHCI/logicalNetworks/{logicalNetworkName}
101+
${VnetId},
102+
104103
[Parameter(ParameterSetName='CreateExpanded')]
105104
[Microsoft.Azure.PowerShell.Cmdlets.AksArc.Category('Body')]
106105
[System.String]
@@ -126,7 +125,7 @@ function New-AzAksArcCluster {
126125
# The version of Kubernetes in use by the provisioned cluster.
127126
${KubernetesVersion},
128127

129-
[Parameter()]
128+
[Parameter(ParameterSetName='CreateExpanded')]
130129
[Microsoft.Azure.PowerShell.Cmdlets.AksArc.Category('Body')]
131130
[System.Management.Automation.SwitchParameter]
132131
# Indicates whether Azure Hybrid Benefit is opted in.
@@ -190,12 +189,9 @@ function New-AzAksArcCluster {
190189
[Parameter(ParameterSetName='AutoScaling', Mandatory)]
191190
[Microsoft.Azure.PowerShell.Cmdlets.AksArc.Category('Body')]
192191
[System.Management.Automation.SwitchParameter]
193-
# Indicates whether to enable NFS CSI Driver.
194-
# The default value is true.
195192
${EnableAutoScaling},
196193

197194
[Parameter(ParameterSetName='CreateExpanded')]
198-
[Parameter(ParameterSetName='AutoScaling', Mandatory)]
199195
[Microsoft.Azure.PowerShell.Cmdlets.AksArc.Category('Path')]
200196
[System.Int32]
201197
${MaxPod},
@@ -410,36 +406,10 @@ function New-AzAksArcCluster {
410406
)
411407

412408
process {
413-
$Scope = GetConnectedClusterResourceURI -SubscriptionId $SubscriptionId -ResourceGroupName $ResourceGroupName -ClusterName $ClusterName
414-
$null = $PSBoundParameters.Remove("SubscriptionId")
415-
$null = $PSBoundParameters.Remove("ResourceGroupName")
416-
$null = $PSBoundParameters.Remove("ClusterName")
417-
$null = $PSBoundParameters.Add("ConnectedClusterResourceUri", $Scope)
418-
419-
# Network Validations
420-
# Logical Network
421-
if (($PSBoundParameters.ContainsKey('ControlPlaneIP')) -And ($VnetId -match $logicalNetworkArmIDRegex)) {
422-
$response = Invoke-AzRestMethod -Path "$VnetId/?api-version=2024-01-01" -Method GET
423-
if ($response.StatusCode -eq 200) {
424-
$lnet = ($response.Content | ConvertFrom-Json)
425-
$err = ValidateLogicalNetwork -lnet $lnet -ControlPlaneIP $ControlPlaneIP
426-
if ($err) {
427-
throw $err
428-
}
429-
} else {
430-
throw "Logical network with ID $VnetId not found."
431-
}
432-
}
433-
434-
# Edit parameters
435-
$null = $PSBoundParameters.Add("InfraNetworkProfileVnetSubnetId", @($VnetId))
436-
$null = $PSBoundParameters.Add("ExtendedLocationType", "CustomLocation")
437-
$null = $PSBoundParameters.Add("NetworkProfileNetworkPolicy", "calico")
438-
$null = $PSBoundParameters.Remove("Location")
439-
$null = $PSBoundParameters.Remove("VnetId")
440-
441-
$CustomLocationID = ConvertCustomLocationNameToID -CustomLocationName $CustomLocationName -SubscriptionId $SubscriptionId -ResourceGroupName $ResourceGroupName
442-
$null = $PSBoundParameters.Add("ExtendedLocationName", $CustomLocationID)
409+
# Get custom location resource ID.
410+
$CustomLocationID = ConvertCustomLocationNameToID -CustomLocationName $CustomLocationName `
411+
-SubscriptionId $SubscriptionId `
412+
-ResourceGroupName $ResourceGroupName
443413
$null = $PSBoundParameters.Remove("CustomLocationName")
444414

445415
# Create connected cluster parent resource
@@ -450,56 +420,82 @@ function New-AzAksArcCluster {
450420
} elseif ($Location -ne $cllocation) {
451421
throw "Location parameter must be equal to custom location's location $cllocation"
452422
}
453-
454-
CreateConnectedCluster -SubscriptionId $SubscriptionId -ResourceGroupName $ResourceGroupName -ClusterName $ClusterName -Location $Location -AdminGroupObjectID $AdminGroupObjectID -EnableAzureRbac:$EnableAzureRbac
423+
$connectedCluster = CreateConnectedCluster -SubscriptionId $SubscriptionId `
424+
-ResourceGroupName $ResourceGroupName `
425+
-ClusterName $ClusterName `
426+
-Location $Location `
427+
-AdminGroupObjectID $AdminGroupObjectID `
428+
-EnableAzureRbac:$EnableAzureRbac
429+
$connectedClusterObject = $connectedCluster.Content | ConvertFrom-Json
430+
$null = $PSBoundParameters.Add("ConnectedClusterResourceUri", $connectedClusterObject.id)
431+
$null = $PSBoundParameters.Remove("Location")
455432
$null = $PSBoundParameters.Remove("AdminGroupObjectID")
456-
457-
# Generate public ssh key if one is not provided
458-
$SshPublicKeyObj = [Microsoft.Azure.PowerShell.Cmdlets.AksArc.Models.LinuxProfilePropertiesSshPublicKeysItem]::New()
459-
if ($PSBoundParameters.ContainsKey('SshKeyValue')) {
460-
$SshPublicKeyObj.KeyData = $SshKeyValue
461-
} else {
462-
$SshPublicKeyObj = GenerateSSHKey ClusterName $ClusterName
463-
}
464-
$null = $PSBoundParameters.Remove("SshKeyValue")
465-
$null = $PSBoundParameters.Add("SshPublicKey", @($SshPublicKeyObj))
466-
467-
# Configure Agent Pool
468-
$AgentPoolProfile = CreateAgentPoolProfile -EnableAutoScaling:$EnableAutoScaling -MinCount $MinCount -MaxCount $MaxCount -MaxPod $MaxPod -NodeTaint $NodeTaint -NodeLabel $NodeLabel
469-
$null = $PSBoundParameters.Add("AgentPoolProfile", $AgentPoolProfile)
470-
471-
if ($PSBoundParameters.ContainsKey('EnableAzureHybridBenefit')) {
472-
$null = $PSBoundParameters.Remove("EnableAzureHybridBenefit")
473-
}
474-
475-
if ($PSBoundParameters.ContainsKey('NodeTaint')) {
476-
$null = $PSBoundParameters.Remove("NodeTaint")
477-
}
478-
479-
if ($PSBoundParameters.ContainsKey('NodeLabel')) {
480-
$null = $PSBoundParameters.Remove("NodeLabel")
481-
}
482-
483-
if ($PSBoundParameters.ContainsKey('MinCount')) {
484-
$null = $PSBoundParameters.Remove("MinCount")
485-
}
486-
487-
if ($PSBoundParameters.ContainsKey('MaxCount')) {
488-
$null = $PSBoundParameters.Remove("MaxCount")
489-
}
490-
491-
if ($PSBoundParameters.ContainsKey('MaxPod')) {
492-
$null = $PSBoundParameters.Remove("MaxPod")
493-
}
433+
$null = $PSBoundParameters.Remove("EnableAzureRbac")
434+
$null = $PSBoundParameters.Remove("SubscriptionId")
435+
$null = $PSBoundParameters.Remove("ResourceGroupName")
436+
$null = $PSBoundParameters.Remove("ClusterName")
494437

495-
# Create Provisioned Cluster
496-
if ($EnableAzureHybridBenefit) {
497-
$null = $PSBoundParameters.Add("LicenseProfileAzureHybridBenefit", $true)
498-
} else {
499-
$null = $PSBoundParameters.Add("LicenseProfileAzureHybridBenefit", $false)
438+
# TODO: If user passed in JsonFilePath or JsonString, let the back-end validate its correctness for now.
439+
# Below is validation for CreateExpanded parameter set.
440+
if (($PSCmdlet.ParameterSetName -ne "CreateViaJsonFilePath") -and ($PSCmdlet.ParameterSetName -ne "CreateViaJsonString")) {
441+
# Edit parameters
442+
$null = $PSBoundParameters.Add("InfraNetworkProfileVnetSubnetId", @($VnetId))
443+
$null = $PSBoundParameters.Remove("VnetId")
444+
$null = $PSBoundParameters.Add("ExtendedLocationType", "CustomLocation")
445+
$null = $PSBoundParameters.Add("NetworkProfileNetworkPolicy", "calico")
446+
$null = $PSBoundParameters.Add("ExtendedLocationName", $CustomLocationID)
447+
448+
# Generate public ssh key if one is not provided.
449+
$SshPublicKeyObj = [Microsoft.Azure.PowerShell.Cmdlets.AksArc.Models.LinuxProfilePropertiesSshPublicKeysItem]::New()
450+
if ($PSBoundParameters.ContainsKey('SshKeyValue')) {
451+
$SshPublicKeyObj.KeyData = $SshKeyValue
452+
} else {
453+
try {
454+
$SshPublicKeyObj = GenerateSSHKey ClusterName $ClusterName
455+
} catch {
456+
if ($_.Exception.Message -like "*ssh-keygen not found*") {
457+
throw "ssh-keygen command not found. Please install OpenSSH client tools and ensure ssh-keygen is in your PATH, or pass your SSH public key to the -SshKeyValue parameter."
458+
} else {
459+
throw $_.Exception.Message
460+
}
461+
}
462+
}
463+
$null = $PSBoundParameters.Remove("SshKeyValue")
464+
$null = $PSBoundParameters.Add("SshPublicKey", @($SshPublicKeyObj))
465+
466+
# Configure Agent Pool
467+
$AgentPoolProfile = CreateAgentPoolProfile -EnableAutoScaling:$EnableAutoScaling `
468+
-MinCount $MinCount `
469+
-MaxCount $MaxCount `
470+
-MaxPod $MaxPod `
471+
-NodeTaint $NodeTaint `
472+
-NodeLabel $NodeLabel
473+
$null = $PSBoundParameters.Add("AgentPoolProfile", $AgentPoolProfile)
474+
$null = $PSBoundParameters.Remove("EnableAutoScaling")
475+
476+
if ($PSBoundParameters.ContainsKey('MinCount')) {
477+
$null = $PSBoundParameters.Remove("MinCount")
478+
}
479+
if ($PSBoundParameters.ContainsKey('MaxCount')) {
480+
$null = $PSBoundParameters.Remove("MaxCount")
481+
}
482+
if ($PSBoundParameters.ContainsKey('MaxPod')) {
483+
$null = $PSBoundParameters.Remove("MaxPod")
484+
}
485+
if ($EnableAzureHybridBenefit) {
486+
$null = $PSBoundParameters.Add("LicenseProfileAzureHybridBenefit", "True")
487+
$null = $PSBoundParameters.Remove("EnableAzureHybridBenefit")
488+
} else {
489+
$null = $PSBoundParameters.Add("LicenseProfileAzureHybridBenefit", "False")
490+
}
491+
if ($PSBoundParameters.ContainsKey('NodeTaint')) {
492+
$null = $PSBoundParameters.Remove("NodeTaint")
493+
}
494+
if ($PSBoundParameters.ContainsKey('NodeLabel')) {
495+
$null = $PSBoundParameters.Remove("NodeLabel")
496+
}
500497
}
501-
502498
Az.AksArc.internal\New-AzAksArcCluster @PSBoundParameters
503499
}
504-
}
500+
}
505501

src/AksArc/AksArc.Autorest/custom/New-AzAksArcNodepool.ps1

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -74,12 +74,6 @@ param(
7474
# Parameter for the name of the agent pool in the provisioned cluster.
7575
${Name},
7676

77-
[Parameter(ParameterSetName='CreateViaIdentityExpanded', Mandatory, ValueFromPipeline)]
78-
[Microsoft.Azure.PowerShell.Cmdlets.AksArc.Category('Path')]
79-
[Microsoft.Azure.PowerShell.Cmdlets.AksArc.Models.IAksArcIdentity]
80-
# Identity Parameter
81-
${InputObject},
82-
8377
[Parameter(ParameterSetName='CreateExpanded')]
8478
[Microsoft.Azure.PowerShell.Cmdlets.AksArc.Category('Body')]
8579
[System.Int32]

src/AksArc/AksArc.Autorest/custom/New-AzAksArcVirtualNetwork.ps1

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -175,12 +175,12 @@ param(
175175
)
176176

177177
process {
178-
# Format custom location
179-
$CustomLocationID = ConvertCustomLocationNameToID -CustomLocationName $CustomLocationName -SubscriptionId $SubscriptionId -ResourceGroupName $ResourceGroupName
180-
$null = $PSBoundParameters.Add("ExtendedLocationType", "CustomLocation")
181-
$null = $PSBoundParameters.Add("ExtendedLocationName", $CustomLocationID)
182-
$null = $PSBoundParameters.Remove("CustomLocationName")
183-
178+
if ($PSCmdlet.ParameterSetName -eq "CreateExpanded") {
179+
$CustomLocationID = ConvertCustomLocationNameToID -CustomLocationName $CustomLocationName -SubscriptionId $SubscriptionId -ResourceGroupName $ResourceGroupName
180+
$null = $PSBoundParameters.Add("ExtendedLocationType", "CustomLocation")
181+
$null = $PSBoundParameters.Add("ExtendedLocationName", $CustomLocationID)
182+
$null = $PSBoundParameters.Remove("CustomLocationName")
183+
}
184184
Az.AksArc.internal\New-AzAksArcVirtualNetwork @PSBoundParameters
185185
}
186186
}

0 commit comments

Comments
 (0)