@@ -75,13 +75,6 @@ function New-AzAksArcCluster {
75
75
[System.String ]
76
76
# ARM Id of the extended location.
77
77
${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} ,
85
78
86
79
[Parameter ()]
87
80
[Microsoft.Azure.PowerShell.Cmdlets.AksArc.Category (' Body' )]
@@ -92,15 +85,21 @@ function New-AzAksArcCluster {
92
85
[Parameter ()]
93
86
[Microsoft.Azure.PowerShell.Cmdlets.AksArc.Category (' Body' )]
94
87
[System.String ]
95
- # Location
96
88
${Location} ,
97
89
98
90
[Parameter ()]
99
91
[AllowEmptyCollection ()]
100
92
[Microsoft.Azure.PowerShell.Cmdlets.AksArc.Category (' Body' )]
101
93
[System.String []]
102
94
${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
+
104
103
[Parameter (ParameterSetName = ' CreateExpanded' )]
105
104
[Microsoft.Azure.PowerShell.Cmdlets.AksArc.Category (' Body' )]
106
105
[System.String ]
@@ -126,7 +125,7 @@ function New-AzAksArcCluster {
126
125
# The version of Kubernetes in use by the provisioned cluster.
127
126
${KubernetesVersion} ,
128
127
129
- [Parameter ()]
128
+ [Parameter (ParameterSetName = ' CreateExpanded ' )]
130
129
[Microsoft.Azure.PowerShell.Cmdlets.AksArc.Category (' Body' )]
131
130
[System.Management.Automation.SwitchParameter ]
132
131
# Indicates whether Azure Hybrid Benefit is opted in.
@@ -190,12 +189,9 @@ function New-AzAksArcCluster {
190
189
[Parameter (ParameterSetName = ' AutoScaling' , Mandatory )]
191
190
[Microsoft.Azure.PowerShell.Cmdlets.AksArc.Category (' Body' )]
192
191
[System.Management.Automation.SwitchParameter ]
193
- # Indicates whether to enable NFS CSI Driver.
194
- # The default value is true.
195
192
${EnableAutoScaling} ,
196
193
197
194
[Parameter (ParameterSetName = ' CreateExpanded' )]
198
- [Parameter (ParameterSetName = ' AutoScaling' , Mandatory )]
199
195
[Microsoft.Azure.PowerShell.Cmdlets.AksArc.Category (' Path' )]
200
196
[System.Int32 ]
201
197
${MaxPod} ,
@@ -410,36 +406,10 @@ function New-AzAksArcCluster {
410
406
)
411
407
412
408
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
443
413
$null = $PSBoundParameters.Remove (" CustomLocationName" )
444
414
445
415
# Create connected cluster parent resource
@@ -450,56 +420,82 @@ function New-AzAksArcCluster {
450
420
} elseif ($Location -ne $cllocation ) {
451
421
throw " Location parameter must be equal to custom location's location $cllocation "
452
422
}
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" )
455
432
$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" )
494
437
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
+ }
500
497
}
501
-
502
498
Az.AksArc.internal\New-AzAksArcCluster @PSBoundParameters
503
499
}
504
- }
500
+ }
505
501
0 commit comments