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 src/AksArc/AksArc.Autorest/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the Apache License, Version 2.0 (the ""License"");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an ""AS IS"" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// Code generated by Microsoft (R) AutoRest Code Generator.Changes may cause incorrect behavior and will be lost if the code
// is regenerated.

using System;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

[assembly: System.Reflection.AssemblyCompanyAttribute("Microsoft")]
[assembly: System.Reflection.AssemblyCopyrightAttribute("Copyright © Microsoft")]
[assembly: System.Reflection.AssemblyProductAttribute("Microsoft Azure PowerShell")]
[assembly: System.Reflection.AssemblyTitleAttribute("Microsoft Azure PowerShell - AksArc")]
[assembly: System.Reflection.AssemblyFileVersionAttribute("0.1.4")]
[assembly: System.Reflection.AssemblyVersionAttribute("0.1.4")]
[assembly: System.Runtime.InteropServices.ComVisibleAttribute(false)]
[assembly: System.CLSCompliantAttribute(false)]
13 changes: 0 additions & 13 deletions src/AksArc/AksArc.Autorest/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -176,19 +176,6 @@ directive:
subject: KubernetesVersion
remove: true

# Rename parameters
- where:
subject: VirtualNetwork
parameter-name: ExtendedLocationName
set:
parameter-name: CustomLocationID

- where:
subject: VirtualNetwork
parameter-name: ExtendedLocationName
set:
parameter-name: CustomLocationID

# Clusters
- where:
parameter-name: ControlPlaneEndpointHostIP
Expand Down
4 changes: 2 additions & 2 deletions src/AksArc/AksArc.Autorest/custom/Az.AksArc.custom.psm1
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# region Generated
# Load the private module dll
$null = Import-Module -PassThru -Name (Join-Path $PSScriptRoot '..\bin\Az.AksArc.private.dll')
$null = Import-Module -PassThru -Name (Join-Path $PSScriptRoot '../bin/Az.AksArc.private.dll')

# Load the internal module
$internalModulePath = Join-Path $PSScriptRoot '..\internal\Az.AksArc.internal.psm1'
$internalModulePath = Join-Path $PSScriptRoot '../internal/Az.AksArc.internal.psm1'
if(Test-Path $internalModulePath) {
$null = Import-Module -Name $internalModulePath
}
Expand Down
15 changes: 6 additions & 9 deletions src/AksArc/AksArc.Autorest/custom/Get-AzAksArcNodepool.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,6 @@ param(
# Parameter for the name of the agent pool in the provisioned cluster.
${Name},

[Parameter(ParameterSetName='GetViaIdentity', Mandatory, ValueFromPipeline)]
[Microsoft.Azure.PowerShell.Cmdlets.AksArc.Category('Path')]
[Microsoft.Azure.PowerShell.Cmdlets.AksArc.Models.IAksArcIdentity]
# Identity Parameter
${InputObject},

[Parameter(DontShow)]
[Microsoft.Azure.PowerShell.Cmdlets.AksArc.Category('Runtime')]
[System.Management.Automation.SwitchParameter]
Expand Down Expand Up @@ -121,11 +115,14 @@ param(
)

process {
$Scope = GetConnectedClusterResourceURI -SubscriptionId $SubscriptionId -ResourceGroupName $ResourceGroupName -ClusterName $ClusterName
$scope = GetConnectedClusterResourceURI `
-SubscriptionId $SubscriptionId `
-ResourceGroupName $ResourceGroupName `
-ClusterName $ClusterName
$null = $PSBoundParameters.Remove("SubscriptionId")
$null = $PSBoundParameters.Remove("ResourceGroupName")
$null = $PSBoundParameters.Remove("ClusterName")
$null = $PSBoundParameters.Add("ConnectedClusterResourceUri", $Scope)
$null = $PSBoundParameters.Add("ConnectedClusterResourceUri", $scope)
Az.AksArc.internal\Get-AzAksArcNodepool @PSBoundParameters
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ function Invoke-AzAksArcClusterUpgrade {
[Parameter(ParameterSetName='Upgrade', Mandatory)]
[Microsoft.Azure.PowerShell.Cmdlets.AksArc.Category('Body')]
[System.String]
# The version of Kubernetes in use by the provisioned cluster.
# Kubernetes version to upgrade to. If not provided, the cluster will be upgraded to the latest supported version.
${KubernetesVersion},

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

# Upgrade Provisioned Cluster
$Upgrades = Get-AzAksArcClusterUpgrade -ClusterName $ClusterName -ResourceGroupName $ResourceGroupName -SubscriptionId $SubscriptionId
if ($PSBoundParameters.ContainsKey("KubernetesVersion"))
{
$Upgrades = Get-AzAksArcClusterUpgrade -ClusterName $ClusterName -ResourceGroupName $ResourceGroupName -SubscriptionId $SubscriptionId
if (!($upgrades.ControlPlaneProfileUpgrade.KubernetesVersion -contains $KubernetesVersion)) {
throw "Kubernetes Version $KubernetesVersion is not a valid upgradable version."
}
} else {
$Upgrades = Get-AzAksArcClusterUpgrade -ClusterName $ClusterName -ResourceGroupName $ResourceGroupName -SubscriptionId $SubscriptionId
$UpgradeListLength = $upgrades.ControlPlaneProfileUpgrade.KubernetesVersion.Length
if ($UpgradeListLength -eq 0) {
if ($upgrades.ControlPlaneProfileUpgrade.KubernetesVersion.Length -eq 0) {
Write-Error "Already on latest kubernetes version."
return
}
$LatestUpgrade = $upgrades.ControlPlaneProfileUpgrade[$UpgradeListLength-1].KubernetesVersion

$LatestUpgrade = $upgrades.ControlPlaneProfileUpgrade[-1].KubernetesVersion
$null = $PSBoundParameters.Add("KubernetesVersion", $LatestUpgrade)
}

Az.AksArc.internal\Update-AzAksArcCluster @PSBoundParameters
}
}
}
176 changes: 86 additions & 90 deletions src/AksArc/AksArc.Autorest/custom/New-AzAksArcCluster.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,6 @@ function New-AzAksArcCluster {
[System.String]
# ARM Id of the extended location.
${CustomLocationName},

[Parameter(Mandatory)]
[Microsoft.Azure.PowerShell.Cmdlets.AksArc.Category('Body')]
[System.String]
# List of ARM resource Ids (maximum 1) for the infrastructure network object e.g.
# /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.AzureStackHCI/logicalNetworks/{logicalNetworkName}
${VnetId},

[Parameter()]
[Microsoft.Azure.PowerShell.Cmdlets.AksArc.Category('Body')]
Expand All @@ -92,15 +85,21 @@ function New-AzAksArcCluster {
[Parameter()]
[Microsoft.Azure.PowerShell.Cmdlets.AksArc.Category('Body')]
[System.String]
# Location
${Location},

[Parameter()]
[AllowEmptyCollection()]
[Microsoft.Azure.PowerShell.Cmdlets.AksArc.Category('Body')]
[System.String[]]
${AdminGroupObjectID},


[Parameter(ParameterSetName='CreateExpanded')]
[Microsoft.Azure.PowerShell.Cmdlets.AksArc.Category('Body')]
[System.String]
# List of ARM resource Ids (maximum 1) for the infrastructure network object e.g.
# /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.AzureStackHCI/logicalNetworks/{logicalNetworkName}
${VnetId},

[Parameter(ParameterSetName='CreateExpanded')]
[Microsoft.Azure.PowerShell.Cmdlets.AksArc.Category('Body')]
[System.String]
Expand All @@ -126,7 +125,7 @@ function New-AzAksArcCluster {
# The version of Kubernetes in use by the provisioned cluster.
${KubernetesVersion},

[Parameter()]
[Parameter(ParameterSetName='CreateExpanded')]
[Microsoft.Azure.PowerShell.Cmdlets.AksArc.Category('Body')]
[System.Management.Automation.SwitchParameter]
# Indicates whether Azure Hybrid Benefit is opted in.
Expand Down Expand Up @@ -190,12 +189,9 @@ function New-AzAksArcCluster {
[Parameter(ParameterSetName='AutoScaling', Mandatory)]
[Microsoft.Azure.PowerShell.Cmdlets.AksArc.Category('Body')]
[System.Management.Automation.SwitchParameter]
# Indicates whether to enable NFS CSI Driver.
# The default value is true.
${EnableAutoScaling},

[Parameter(ParameterSetName='CreateExpanded')]
[Parameter(ParameterSetName='AutoScaling', Mandatory)]
[Microsoft.Azure.PowerShell.Cmdlets.AksArc.Category('Path')]
[System.Int32]
${MaxPod},
Expand Down Expand Up @@ -410,36 +406,10 @@ function New-AzAksArcCluster {
)

process {
$Scope = GetConnectedClusterResourceURI -SubscriptionId $SubscriptionId -ResourceGroupName $ResourceGroupName -ClusterName $ClusterName
$null = $PSBoundParameters.Remove("SubscriptionId")
$null = $PSBoundParameters.Remove("ResourceGroupName")
$null = $PSBoundParameters.Remove("ClusterName")
$null = $PSBoundParameters.Add("ConnectedClusterResourceUri", $Scope)

# Network Validations
# Logical Network
if (($PSBoundParameters.ContainsKey('ControlPlaneIP')) -And ($VnetId -match $logicalNetworkArmIDRegex)) {
$response = Invoke-AzRestMethod -Path "$VnetId/?api-version=2024-01-01" -Method GET
if ($response.StatusCode -eq 200) {
$lnet = ($response.Content | ConvertFrom-Json)
$err = ValidateLogicalNetwork -lnet $lnet -ControlPlaneIP $ControlPlaneIP
if ($err) {
throw $err
}
} else {
throw "Logical network with ID $VnetId not found."
}
}

# Edit parameters
$null = $PSBoundParameters.Add("InfraNetworkProfileVnetSubnetId", @($VnetId))
$null = $PSBoundParameters.Add("ExtendedLocationType", "CustomLocation")
$null = $PSBoundParameters.Add("NetworkProfileNetworkPolicy", "calico")
$null = $PSBoundParameters.Remove("Location")
$null = $PSBoundParameters.Remove("VnetId")

$CustomLocationID = ConvertCustomLocationNameToID -CustomLocationName $CustomLocationName -SubscriptionId $SubscriptionId -ResourceGroupName $ResourceGroupName
$null = $PSBoundParameters.Add("ExtendedLocationName", $CustomLocationID)
# Get custom location resource ID.
$CustomLocationID = ConvertCustomLocationNameToID -CustomLocationName $CustomLocationName `
-SubscriptionId $SubscriptionId `
-ResourceGroupName $ResourceGroupName
$null = $PSBoundParameters.Remove("CustomLocationName")

# Create connected cluster parent resource
Expand All @@ -450,56 +420,82 @@ function New-AzAksArcCluster {
} elseif ($Location -ne $cllocation) {
throw "Location parameter must be equal to custom location's location $cllocation"
}

CreateConnectedCluster -SubscriptionId $SubscriptionId -ResourceGroupName $ResourceGroupName -ClusterName $ClusterName -Location $Location -AdminGroupObjectID $AdminGroupObjectID -EnableAzureRbac:$EnableAzureRbac
$connectedCluster = CreateConnectedCluster -SubscriptionId $SubscriptionId `
-ResourceGroupName $ResourceGroupName `
-ClusterName $ClusterName `
-Location $Location `
-AdminGroupObjectID $AdminGroupObjectID `
-EnableAzureRbac:$EnableAzureRbac
$connectedClusterObject = $connectedCluster.Content | ConvertFrom-Json
$null = $PSBoundParameters.Add("ConnectedClusterResourceUri", $connectedClusterObject.id)
$null = $PSBoundParameters.Remove("Location")
$null = $PSBoundParameters.Remove("AdminGroupObjectID")

# Generate public ssh key if one is not provided
$SshPublicKeyObj = [Microsoft.Azure.PowerShell.Cmdlets.AksArc.Models.LinuxProfilePropertiesSshPublicKeysItem]::New()
if ($PSBoundParameters.ContainsKey('SshKeyValue')) {
$SshPublicKeyObj.KeyData = $SshKeyValue
} else {
$SshPublicKeyObj = GenerateSSHKey ClusterName $ClusterName
}
$null = $PSBoundParameters.Remove("SshKeyValue")
$null = $PSBoundParameters.Add("SshPublicKey", @($SshPublicKeyObj))

# Configure Agent Pool
$AgentPoolProfile = CreateAgentPoolProfile -EnableAutoScaling:$EnableAutoScaling -MinCount $MinCount -MaxCount $MaxCount -MaxPod $MaxPod -NodeTaint $NodeTaint -NodeLabel $NodeLabel
$null = $PSBoundParameters.Add("AgentPoolProfile", $AgentPoolProfile)

if ($PSBoundParameters.ContainsKey('EnableAzureHybridBenefit')) {
$null = $PSBoundParameters.Remove("EnableAzureHybridBenefit")
}

if ($PSBoundParameters.ContainsKey('NodeTaint')) {
$null = $PSBoundParameters.Remove("NodeTaint")
}

if ($PSBoundParameters.ContainsKey('NodeLabel')) {
$null = $PSBoundParameters.Remove("NodeLabel")
}

if ($PSBoundParameters.ContainsKey('MinCount')) {
$null = $PSBoundParameters.Remove("MinCount")
}

if ($PSBoundParameters.ContainsKey('MaxCount')) {
$null = $PSBoundParameters.Remove("MaxCount")
}

if ($PSBoundParameters.ContainsKey('MaxPod')) {
$null = $PSBoundParameters.Remove("MaxPod")
}
$null = $PSBoundParameters.Remove("EnableAzureRbac")
$null = $PSBoundParameters.Remove("SubscriptionId")
$null = $PSBoundParameters.Remove("ResourceGroupName")
$null = $PSBoundParameters.Remove("ClusterName")

# Create Provisioned Cluster
if ($EnableAzureHybridBenefit) {
$null = $PSBoundParameters.Add("LicenseProfileAzureHybridBenefit", $true)
} else {
$null = $PSBoundParameters.Add("LicenseProfileAzureHybridBenefit", $false)
# TODO: If user passed in JsonFilePath or JsonString, let the back-end validate its correctness for now.
# Below is validation for CreateExpanded parameter set.
if (($PSCmdlet.ParameterSetName -ne "CreateViaJsonFilePath") -and ($PSCmdlet.ParameterSetName -ne "CreateViaJsonString")) {
# Edit parameters
$null = $PSBoundParameters.Add("InfraNetworkProfileVnetSubnetId", @($VnetId))
$null = $PSBoundParameters.Remove("VnetId")
$null = $PSBoundParameters.Add("ExtendedLocationType", "CustomLocation")
$null = $PSBoundParameters.Add("NetworkProfileNetworkPolicy", "calico")
$null = $PSBoundParameters.Add("ExtendedLocationName", $CustomLocationID)

# Generate public ssh key if one is not provided.
$SshPublicKeyObj = [Microsoft.Azure.PowerShell.Cmdlets.AksArc.Models.LinuxProfilePropertiesSshPublicKeysItem]::New()
if ($PSBoundParameters.ContainsKey('SshKeyValue')) {
$SshPublicKeyObj.KeyData = $SshKeyValue
} else {
try {
$SshPublicKeyObj = GenerateSSHKey ClusterName $ClusterName
} catch {
if ($_.Exception.Message -like "*ssh-keygen not found*") {
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."
} else {
throw $_.Exception.Message
}
}
}
$null = $PSBoundParameters.Remove("SshKeyValue")
$null = $PSBoundParameters.Add("SshPublicKey", @($SshPublicKeyObj))

# Configure Agent Pool
$AgentPoolProfile = CreateAgentPoolProfile -EnableAutoScaling:$EnableAutoScaling `
-MinCount $MinCount `
-MaxCount $MaxCount `
-MaxPod $MaxPod `
-NodeTaint $NodeTaint `
-NodeLabel $NodeLabel
$null = $PSBoundParameters.Add("AgentPoolProfile", $AgentPoolProfile)
$null = $PSBoundParameters.Remove("EnableAutoScaling")

if ($PSBoundParameters.ContainsKey('MinCount')) {
$null = $PSBoundParameters.Remove("MinCount")
}
if ($PSBoundParameters.ContainsKey('MaxCount')) {
$null = $PSBoundParameters.Remove("MaxCount")
}
if ($PSBoundParameters.ContainsKey('MaxPod')) {
$null = $PSBoundParameters.Remove("MaxPod")
}
if ($EnableAzureHybridBenefit) {
$null = $PSBoundParameters.Add("LicenseProfileAzureHybridBenefit", "True")
$null = $PSBoundParameters.Remove("EnableAzureHybridBenefit")
} else {
$null = $PSBoundParameters.Add("LicenseProfileAzureHybridBenefit", "False")
}
if ($PSBoundParameters.ContainsKey('NodeTaint')) {
$null = $PSBoundParameters.Remove("NodeTaint")
}
if ($PSBoundParameters.ContainsKey('NodeLabel')) {
$null = $PSBoundParameters.Remove("NodeLabel")
}
}

Az.AksArc.internal\New-AzAksArcCluster @PSBoundParameters
}
}
}

6 changes: 0 additions & 6 deletions src/AksArc/AksArc.Autorest/custom/New-AzAksArcNodepool.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,6 @@ param(
# Parameter for the name of the agent pool in the provisioned cluster.
${Name},

[Parameter(ParameterSetName='CreateViaIdentityExpanded', Mandatory, ValueFromPipeline)]
[Microsoft.Azure.PowerShell.Cmdlets.AksArc.Category('Path')]
[Microsoft.Azure.PowerShell.Cmdlets.AksArc.Models.IAksArcIdentity]
# Identity Parameter
${InputObject},

[Parameter(ParameterSetName='CreateExpanded')]
[Microsoft.Azure.PowerShell.Cmdlets.AksArc.Category('Body')]
[System.Int32]
Expand Down
12 changes: 6 additions & 6 deletions src/AksArc/AksArc.Autorest/custom/New-AzAksArcVirtualNetwork.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -175,12 +175,12 @@ param(
)

process {
# Format custom location
$CustomLocationID = ConvertCustomLocationNameToID -CustomLocationName $CustomLocationName -SubscriptionId $SubscriptionId -ResourceGroupName $ResourceGroupName
$null = $PSBoundParameters.Add("ExtendedLocationType", "CustomLocation")
$null = $PSBoundParameters.Add("ExtendedLocationName", $CustomLocationID)
$null = $PSBoundParameters.Remove("CustomLocationName")

if ($PSCmdlet.ParameterSetName -eq "CreateExpanded") {
$CustomLocationID = ConvertCustomLocationNameToID -CustomLocationName $CustomLocationName -SubscriptionId $SubscriptionId -ResourceGroupName $ResourceGroupName
$null = $PSBoundParameters.Add("ExtendedLocationType", "CustomLocation")
$null = $PSBoundParameters.Add("ExtendedLocationName", $CustomLocationID)
$null = $PSBoundParameters.Remove("CustomLocationName")
}
Az.AksArc.internal\New-AzAksArcVirtualNetwork @PSBoundParameters
}
}
Loading