Skip to content

Commit

Permalink
Move ConnectedKubernetes to main
Browse files Browse the repository at this point in the history
  • Loading branch information
azure-powershell-bot committed Sep 24, 2024
1 parent 33f0648 commit e43b544
Show file tree
Hide file tree
Showing 10 changed files with 78 additions and 163 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -439,8 +439,9 @@ function New-AzConnectedKubernetes {
$options = ""

if ($DisableAutoUpgrade) {
$options += " --set systemDefaultValues.azureArcAgents.autoUpdate=false"
# $options += " --set systemDefaultValues.azureArcAgents.autoUpdate=false"
$Null = $PSBoundParameters.Remove('DisableAutoUpgrade')
$PSBoundParameters.Add('ArcAgentProfileAgentAutoUpgrade', 'Disabled')
}
if (-not ([string]::IsNullOrEmpty($ContainerLogPath))) {
$options += " --set systemDefaultValues.fluent-bit.containerLogPath=$ContainerLogPath"
Expand Down Expand Up @@ -599,9 +600,14 @@ function New-AzConnectedKubernetes {

$PSBoundParameters.Add('ArcAgentryConfiguration', $arcAgentryConfigs)

Write-Verbose "Creating 'Kubernetes - Azure Arc' object in Azure"
Write-Output "Creating 'Kubernetes - Azure Arc' object in Azure"
$Response = Az.ConnectedKubernetes.internal\New-AzConnectedKubernetes @PSBoundParameters

if ((-not $WhatIfPreference) -and (-not $Response)) {
Write-Error "Failed to create the 'Kubernetes - Azure Arc' resource."
return
}

$arcAgentryConfigs = ConvertTo-ArcAgentryConfiguration -ConfigurationSetting $ConfigurationSetting -RedactedProtectedConfiguration $RedactedProtectedConfiguration -CCRP $false

# Convert the $Response object into a nested hashtable.
Expand Down Expand Up @@ -676,6 +682,7 @@ function New-AzConnectedKubernetes {
$options += " --debug"
}
if ($PSCmdlet.ShouldProcess($ClusterName, "Update Kubernetes cluster with Azure Arc")) {
Write-Output "Executing helm upgrade command, this can take a few minutes...."
try {
helm upgrade `
--install azure-arc `
Expand Down Expand Up @@ -705,7 +712,7 @@ function New-AzConnectedKubernetes {
if ($PSBoundParameters.ContainsKey('OidcIssuerProfileEnabled') -or $PSBoundParameters.ContainsKey('WorkloadIdentityEnabled') ) {
$ExistConnectedKubernetes = Get-AzConnectedKubernetes -ResourceGroupName $ResourceGroupName -ClusterName $ClusterName @CommonPSBoundParameters

Write-Host "Cluster configuration is in progress..."
Write-Output "Cluster configuration is in progress..."
$timeout = [datetime]::Now.AddMinutes(60)

while (($ExistConnectedKubernetes.ArcAgentProfileAgentState -ne "Succeeded") -and ($ExistConnectedKubernetes.ArcAgentProfileAgentState -ne "Failed") -and ([datetime]::Now -lt $timeout)) {
Expand All @@ -714,7 +721,7 @@ function New-AzConnectedKubernetes {
}

if ($ExistConnectedKubernetes.ArcAgentProfileAgentState -eq "Succeeded") {
Write-Host "Cluster configuration succeeded."
Write-Output "Cluster configuration succeeded."
} elseif ($ExistConnectedKubernetes.ArcAgentProfileAgentState -eq "Failed") {
Write-Error "Cluster configuration failed."
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ API to set properties of the connected cluster resource
.Description
API to set properties of the connected cluster resource
.Example
Set-AzConnectedKubernetes -ClusterName azps_test_cluster -ResourceGroupName azps_test_group -Location eastus -EnableGateway -GatewayResourceId $gatewayResourceId
Set-AzConnectedKubernetes -ClusterName azps_test_cluster -ResourceGroupName azps_test_group -Location eastus -GatewayResourceId $gatewayResourceId
.Example
Set-AzConnectedKubernetes -ClusterName azps_test_cluster1 -ResourceGroupName azps_test_group -Location eastus -KubeConfig $HOME\.kube\config -KubeContext azps_aks_t01 -DisableGateway
Expand Down Expand Up @@ -87,7 +87,6 @@ function Set-AzConnectedKubernetes {
Justification = 'Code published before this issue was identified')]
param(
[Parameter(ParameterSetName = 'SetExpanded', Mandatory)]
[Parameter(ParameterSetName = 'SetExpandedEnableGateway', Mandatory)]
[Parameter(ParameterSetName = 'SetExpandedDisableGateway', Mandatory)]
[Alias('Name')]
[Microsoft.Azure.PowerShell.Cmdlets.ConnectedKubernetes.Category('Path')]
Expand All @@ -96,7 +95,6 @@ function Set-AzConnectedKubernetes {
${ClusterName},

[Parameter(ParameterSetName = 'SetExpanded', Mandatory)]
[Parameter(ParameterSetName = 'SetExpandedEnableGateway', Mandatory)]
[Parameter(ParameterSetName = 'SetExpandedDisableGateway', Mandatory)]
[Microsoft.Azure.PowerShell.Cmdlets.ConnectedKubernetes.Category('Path')]
[System.String]
Expand All @@ -105,15 +103,13 @@ function Set-AzConnectedKubernetes {
${ResourceGroupName},

[Parameter(ParameterSetName = 'SetExpanded', Mandatory)]
[Parameter(ParameterSetName = 'SetExpandedEnableGateway', Mandatory)]
[Parameter(ParameterSetName = 'SetExpandedDisableGateway', Mandatory)]
[Microsoft.Azure.PowerShell.Cmdlets.ConnectedKubernetes.Category('Body')]
[System.String]
# The geo-location where the resource lives
${Location},

[Parameter(ParameterSetName = 'Set', Mandatory)]
[Parameter(ParameterSetName = 'SetEnableGateway', Mandatory)]
[Parameter(ParameterSetName = 'SetDisableGateway', Mandatory)]
[Microsoft.Azure.PowerShell.Cmdlets.ConnectedKubernetes.Category('Body')]
[Microsoft.Azure.PowerShell.Cmdlets.ConnectedKubernetes.Models.Api20240715Preview.IConnectedCluster]
Expand Down Expand Up @@ -326,12 +322,6 @@ function Set-AzConnectedKubernetes {
# Arc Agentry System Protected Configuration
${ConfigurationProtectedSetting},

[Parameter(ParameterSetName = 'SetEnableGateway', Mandatory)]
[Parameter(ParameterSetName = 'SetExpandedEnableGateway', Mandatory)]
[Microsoft.Azure.PowerShell.Cmdlets.ConnectedKubernetes.Category('body')]
[System.Management.Automation.SwitchParameter]
${EnableGateway},

[Parameter(ParameterSetName = 'SetDisableGateway', Mandatory)]
[Parameter(ParameterSetName = 'SetExpandedDisableGateway', Mandatory)]
[Microsoft.Azure.PowerShell.Cmdlets.ConnectedKubernetes.Category('body')]
Expand All @@ -341,7 +331,7 @@ function Set-AzConnectedKubernetes {
[Parameter()]
[Microsoft.Azure.PowerShell.Cmdlets.ConnectedKubernetes.Category('body')]
[System.String]
# Arc Gateway resource Id
# Arc Gateway resource Id, providing this will enable the gateway
${GatewayResourceId}
)

Expand Down Expand Up @@ -415,10 +405,7 @@ function Set-AzConnectedKubernetes {
$ResourceGroupName = $InputObject.ResourceGroupName
$PSBoundParameters.Add('ResourceGroupName', $ResourceGroupName)

if ((-not $PSBoundParameters.ContainsKey('EnableGateway')) -and (-not $PSBoundParameters.ContainsKey('DisableGateway'))) {
if ($InputObject.GatewayEnabled) {
$EnableGateway = $InputObject.GatewayEnabled
}
if (-not $PSBoundParameters.ContainsKey('DisableGateway')) {
if (-not $InputObject.GatewayEnabled) {
$DisableGateway = -not $InputObject.GatewayEnabled
}
Expand All @@ -427,11 +414,14 @@ function Set-AzConnectedKubernetes {
$GatewayResourceId = $InputObject.GatewayResourceId
$PSBoundParameters.Add('GatewayResourceId', $GatewayResourceId)
}

if (-not $PSBoundParameters.ContainsKey('DisableAutoUpgrade')) {
$DisableAutoUpgrade = ($InputObject.ArcAgentProfileAgentAutoUpgrade -eq 'Disabled')
}
}

if ($EnableGateway) {
if (-not [String]::IsNullOrEmpty($GatewayResourceId) -and -not $DisableGateway) {
Write-Debug "Gateway enabled"
$Null = $PSBoundParameters.Remove('EnableGateway')
$PSBoundParameters.Add('GatewayEnabled', $true)
}
# If DisableGateway is provided then set the gateway as disabled and remove gateway resourceId from parameters
Expand Down Expand Up @@ -472,7 +462,6 @@ function Set-AzConnectedKubernetes {
$ReleaseNamespace = $ReleaseNamespaces['ReleaseNamespace']
$ReleaseInstallNamespace = $ReleaseNamespaces['ReleaseInstallNamespace']


#Endregion

#Region validate release namespace
Expand Down Expand Up @@ -511,9 +500,9 @@ function Set-AzConnectedKubernetes {

$options = ""

if ($DisableAutoUpgrade) {
$options += " --set systemDefaultValues.azureArcAgents.autoUpdate=false"
if ($DisableAutoUpgrade -or ($ExistConnectedKubernetes.ArcAgentProfileAgentAutoUpgrade -eq 'Disabled')) {
$Null = $PSBoundParameters.Remove('DisableAutoUpgrade')
$PSBoundParameters.Add('ArcAgentProfileAgentAutoUpgrade', 'Disabled')
}
if (-not ([string]::IsNullOrEmpty($ContainerLogPath))) {
$options += " --set systemDefaultValues.fluent-bit.containerLogPath=$ContainerLogPath"
Expand Down Expand Up @@ -549,6 +538,17 @@ function Set-AzConnectedKubernetes {
#Endregion

#Region Deal with configuration settings and protected settings

# If the user does not provide proxy settings, or configuration settings, we shall use arc config of existing object
$userProvidedArcConfiguration = (
($null -ne $InputObject) -and ($InputObject.ArcAgentryConfiguration.Length > 0) `
-and (-not ([string]::IsNullOrEmpty($HttpProxy))) `
-and (-not ([string]::IsNullOrEmpty($HttpsProxy))) `
-and (-not ([string]::IsNullOrEmpty($NoProxy))) `
-and ((-not ([string]::IsNullOrEmpty($ProxyCert)))) `
-and ($PSBoundParameters.ContainsKey('ConfigurationSetting')) `
-and ($PSBoundParameters.ContainsKey('ConfigurationProtectedSetting')))

if ($null -eq $ConfigurationSetting) {
$ConfigurationSetting = @{}
}
Expand Down Expand Up @@ -654,9 +654,18 @@ function Set-AzConnectedKubernetes {
$PSBoundParameters.Remove('ConfigurationProtectedSetting')
}

$PSBoundParameters.Add('ArcAgentryConfiguration', $arcAgentryConfigs)
if ($userProvidedArcConfiguration) {
$PSBoundParameters.Add('ArcAgentryConfiguration', $arcAgentryConfigs)
} else {
$PSBoundParameters.Add('ArcAgentryConfiguration', $ExistConnectedKubernetes.ArcAgentryConfiguration)
}

Write-Output "Updating the connected cluster resource...."
$Response = Az.ConnectedKubernetes.internal\Set-AzConnectedKubernetes @PSBoundParameters
if ((-not $WhatIfPreference) -and (-not $Response)) {
Write-Error "Failed to update the 'Kubernetes - Azure Arc' resource"
return
}
$arcAgentryConfigs = ConvertTo-ArcAgentryConfiguration -ConfigurationSetting $ConfigurationSetting -RedactedProtectedConfiguration $RedactedProtectedConfiguration -CCRP $false

# Convert the $Response object into a nested hashtable.
Expand All @@ -671,13 +680,20 @@ function Set-AzConnectedKubernetes {
$Response['properties'] = @{}
}

$Response['properties']['arcAgentryConfigurations'] = $arcAgentryConfigs
if ($userProvidedArcConfiguration) {
$Response['properties']['arcAgentryConfigurations'] = $arcAgentryConfigs
} else {
$Response['properties']['arcAgentryConfigurations'] = $ExistConnectedKubernetes.ArcAgentryConfiguration
}


# Retrieving Helm chart OCI (Open Container Initiative) Artifact location
Write-Debug "Retrieving Helm chart OCI (Open Container Initiative) Artifact location."
$ResponseStr = $Response | ConvertTo-Json -Depth 10
Write-Debug "PUT response: $ResponseStr"

Write-Output "Preparing helm ...."

if ($PSCmdlet.ShouldProcess('configDP', 'get helm values from config DP')) {
$helmValuesDp = Get-HelmValuesFromConfigDP `
-configDPEndpoint $configDPEndpoint `
Expand Down Expand Up @@ -741,6 +757,7 @@ function Set-AzConnectedKubernetes {
}
}

Write-Output "Executing helm upgrade, this can take a few minutes ...."
Write-Debug $options -ErrorAction Continue
if ($DebugPreference -eq "Continue") {
$options += " --debug"
Expand All @@ -765,7 +782,7 @@ function Set-AzConnectedKubernetes {
if ($PSBoundParameters.ContainsKey('OidcIssuerProfileEnabled') -or $PSBoundParameters.ContainsKey('WorkloadIdentityEnabled') ) {
$ExistConnectedKubernetes = Get-AzConnectedKubernetes -ResourceGroupName $ResourceGroupName -ClusterName $ClusterName @CommonPSBoundParameters

Write-Host "Cluster configuration is in progress..."
Write-Output "Cluster configuration is in progress..."
$timeout = [datetime]::Now.AddMinutes(60)

while (($ExistConnectedKubernetes.ArcAgentProfileAgentState -ne "Succeeded") -and ($ExistConnectedKubernetes.ArcAgentProfileAgentState -ne "Failed") -and ([datetime]::Now -lt $timeout)) {
Expand All @@ -774,7 +791,7 @@ function Set-AzConnectedKubernetes {
}

if ($ExistConnectedKubernetes.ArcAgentProfileAgentState -eq "Succeeded") {
Write-Host "Cluster configuration succeeded."
Write-Output "Cluster configuration succeeded."
} elseif ($ExistConnectedKubernetes.ArcAgentProfileAgentState -eq "Failed") {
Write-Error "Cluster configuration failed."
} else {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
### Example 1: Disable gateway feature of a connected kubernetes.
### Example 1: Disable gateway feature of a connected kubernetes.
```powershell
Set-AzConnectedKubernetes -ClusterName azps_test_cluster -ResourceGroupName azps_test_group -Location eastus -DisableGateway
```
Expand All @@ -13,7 +13,7 @@ This command disable gateway feature of a connected kubernetes.

### Example 2: Enable gateway feature of connected kubernetes.
```powershell
Set-AzConnectedKubernetes -ClusterName azps_test_cluster -ResourceGroupName azps_test_group -Location eastus -EnableGateway -GatewayResourceId gatewayResourceId
Set-AzConnectedKubernetes -ClusterName azps_test_cluster -ResourceGroupName azps_test_group -Location eastus -GatewayResourceId gatewayResourceId
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1021,7 +1021,7 @@ API to set properties of the connected cluster resource
.Example
Set-AzConnectedKubernetes -ClusterName azps_test_cluster -ResourceGroupName azps_test_group -Location eastus -DisableGateway
.Example
Set-AzConnectedKubernetes -ClusterName azps_test_cluster -ResourceGroupName azps_test_group -Location eastus -EnableGateway -GatewayResourceId gatewayResourceId
Set-AzConnectedKubernetes -ClusterName azps_test_cluster -ResourceGroupName azps_test_group -Location eastus -GatewayResourceId gatewayResourceId
.Outputs
Expand Down Expand Up @@ -1081,7 +1081,6 @@ function Set-AzConnectedKubernetes {
param(
[Parameter(ParameterSetName='SetExpanded', Mandatory)]
[Parameter(ParameterSetName='SetExpandedDisableGateway', Mandatory)]
[Parameter(ParameterSetName='SetExpandedEnableGateway', Mandatory)]
[Alias('Name')]
[Microsoft.Azure.PowerShell.Cmdlets.ConnectedKubernetes.Category('Path')]
[System.String]
Expand All @@ -1090,7 +1089,6 @@ param(

[Parameter(ParameterSetName='SetExpanded', Mandatory)]
[Parameter(ParameterSetName='SetExpandedDisableGateway', Mandatory)]
[Parameter(ParameterSetName='SetExpandedEnableGateway', Mandatory)]
[Microsoft.Azure.PowerShell.Cmdlets.ConnectedKubernetes.Category('Path')]
[System.String]
# The name of the resource group.
Expand Down Expand Up @@ -1142,7 +1140,6 @@ param(

[Parameter(ParameterSetName='SetExpanded', Mandatory)]
[Parameter(ParameterSetName='SetExpandedDisableGateway', Mandatory)]
[Parameter(ParameterSetName='SetExpandedEnableGateway', Mandatory)]
[Microsoft.Azure.PowerShell.Cmdlets.ConnectedKubernetes.Category('Body')]
[System.String]
# The geo-location where the resource lives
Expand Down Expand Up @@ -1257,7 +1254,7 @@ param(
[Parameter()]
[Microsoft.Azure.PowerShell.Cmdlets.ConnectedKubernetes.Category('Body')]
[System.String]
# Arc Gateway resource Id
# Arc Gateway resource Id, providing this will enable the gateway
${GatewayResourceId},

[Parameter(ParameterSetName='SetExpandedDisableGateway', Mandatory)]
Expand All @@ -1266,14 +1263,7 @@ param(
[System.Management.Automation.SwitchParameter]
${DisableGateway},

[Parameter(ParameterSetName='SetExpandedEnableGateway', Mandatory)]
[Parameter(ParameterSetName='SetEnableGateway', Mandatory)]
[Microsoft.Azure.PowerShell.Cmdlets.ConnectedKubernetes.Category('Body')]
[System.Management.Automation.SwitchParameter]
${EnableGateway},

[Parameter(ParameterSetName='SetDisableGateway', Mandatory)]
[Parameter(ParameterSetName='SetEnableGateway', Mandatory)]
[Parameter(ParameterSetName='Set', Mandatory)]
[Microsoft.Azure.PowerShell.Cmdlets.ConnectedKubernetes.Category('Body')]
[Microsoft.Azure.PowerShell.Cmdlets.ConnectedKubernetes.Models.Api20240715Preview.IConnectedCluster]
Expand Down Expand Up @@ -1368,12 +1358,10 @@ begin {
$mapping = @{
SetExpanded = 'Az.ConnectedKubernetes.custom\Set-AzConnectedKubernetes';
SetExpandedDisableGateway = 'Az.ConnectedKubernetes.custom\Set-AzConnectedKubernetes';
SetExpandedEnableGateway = 'Az.ConnectedKubernetes.custom\Set-AzConnectedKubernetes';
SetDisableGateway = 'Az.ConnectedKubernetes.custom\Set-AzConnectedKubernetes';
SetEnableGateway = 'Az.ConnectedKubernetes.custom\Set-AzConnectedKubernetes';
Set = 'Az.ConnectedKubernetes.custom\Set-AzConnectedKubernetes';
}
if (('SetExpanded', 'SetExpandedDisableGateway', 'SetExpandedEnableGateway', 'SetDisableGateway', 'SetEnableGateway', 'Set') -contains $parameterSet -and -not $PSBoundParameters.ContainsKey('SubscriptionId')) {
if (('SetExpanded', 'SetExpandedDisableGateway', 'SetDisableGateway', 'Set') -contains $parameterSet -and -not $PSBoundParameters.ContainsKey('SubscriptionId')) {
$testPlayback = $false
$PSBoundParameters['HttpPipelinePrepend'] | Foreach-Object { if ($_) { $testPlayback = $testPlayback -or ('Microsoft.Azure.PowerShell.Cmdlets.ConnectedKubernetes.Runtime.PipelineMock' -eq $_.Target.GetType().FullName -and 'Playback' -eq $_.Target.Mode) } }
if ($testPlayback) {
Expand Down
Loading

0 comments on commit e43b544

Please sign in to comment.