Skip to content

Commit fdbb30a

Browse files
Move ConnectedKubernetes to main (#26159)
Co-authored-by: azure-powershell-bot <[email protected]>
1 parent 33f0648 commit fdbb30a

File tree

10 files changed

+78
-163
lines changed

10 files changed

+78
-163
lines changed

src/ConnectedKubernetes/ConnectedKubernetes.Autorest/custom/New-AzConnectedKubernetes.ps1

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -439,8 +439,9 @@ function New-AzConnectedKubernetes {
439439
$options = ""
440440

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

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

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

606+
if ((-not $WhatIfPreference) -and (-not $Response)) {
607+
Write-Error "Failed to create the 'Kubernetes - Azure Arc' resource."
608+
return
609+
}
610+
605611
$arcAgentryConfigs = ConvertTo-ArcAgentryConfiguration -ConfigurationSetting $ConfigurationSetting -RedactedProtectedConfiguration $RedactedProtectedConfiguration -CCRP $false
606612

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

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

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

716723
if ($ExistConnectedKubernetes.ArcAgentProfileAgentState -eq "Succeeded") {
717-
Write-Host "Cluster configuration succeeded."
724+
Write-Output "Cluster configuration succeeded."
718725
} elseif ($ExistConnectedKubernetes.ArcAgentProfileAgentState -eq "Failed") {
719726
Write-Error "Cluster configuration failed."
720727
} else {

src/ConnectedKubernetes/ConnectedKubernetes.Autorest/custom/Set-AzConnectedKubernetes.ps1

Lines changed: 42 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ API to set properties of the connected cluster resource
2525
.Description
2626
API to set properties of the connected cluster resource
2727
.Example
28-
Set-AzConnectedKubernetes -ClusterName azps_test_cluster -ResourceGroupName azps_test_group -Location eastus -EnableGateway -GatewayResourceId $gatewayResourceId
28+
Set-AzConnectedKubernetes -ClusterName azps_test_cluster -ResourceGroupName azps_test_group -Location eastus -GatewayResourceId $gatewayResourceId
2929
.Example
3030
Set-AzConnectedKubernetes -ClusterName azps_test_cluster1 -ResourceGroupName azps_test_group -Location eastus -KubeConfig $HOME\.kube\config -KubeContext azps_aks_t01 -DisableGateway
3131
@@ -87,7 +87,6 @@ function Set-AzConnectedKubernetes {
8787
Justification = 'Code published before this issue was identified')]
8888
param(
8989
[Parameter(ParameterSetName = 'SetExpanded', Mandatory)]
90-
[Parameter(ParameterSetName = 'SetExpandedEnableGateway', Mandatory)]
9190
[Parameter(ParameterSetName = 'SetExpandedDisableGateway', Mandatory)]
9291
[Alias('Name')]
9392
[Microsoft.Azure.PowerShell.Cmdlets.ConnectedKubernetes.Category('Path')]
@@ -96,7 +95,6 @@ function Set-AzConnectedKubernetes {
9695
${ClusterName},
9796

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

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

115112
[Parameter(ParameterSetName = 'Set', Mandatory)]
116-
[Parameter(ParameterSetName = 'SetEnableGateway', Mandatory)]
117113
[Parameter(ParameterSetName = 'SetDisableGateway', Mandatory)]
118114
[Microsoft.Azure.PowerShell.Cmdlets.ConnectedKubernetes.Category('Body')]
119115
[Microsoft.Azure.PowerShell.Cmdlets.ConnectedKubernetes.Models.Api20240715Preview.IConnectedCluster]
@@ -326,12 +322,6 @@ function Set-AzConnectedKubernetes {
326322
# Arc Agentry System Protected Configuration
327323
${ConfigurationProtectedSetting},
328324

329-
[Parameter(ParameterSetName = 'SetEnableGateway', Mandatory)]
330-
[Parameter(ParameterSetName = 'SetExpandedEnableGateway', Mandatory)]
331-
[Microsoft.Azure.PowerShell.Cmdlets.ConnectedKubernetes.Category('body')]
332-
[System.Management.Automation.SwitchParameter]
333-
${EnableGateway},
334-
335325
[Parameter(ParameterSetName = 'SetDisableGateway', Mandatory)]
336326
[Parameter(ParameterSetName = 'SetExpandedDisableGateway', Mandatory)]
337327
[Microsoft.Azure.PowerShell.Cmdlets.ConnectedKubernetes.Category('body')]
@@ -341,7 +331,7 @@ function Set-AzConnectedKubernetes {
341331
[Parameter()]
342332
[Microsoft.Azure.PowerShell.Cmdlets.ConnectedKubernetes.Category('body')]
343333
[System.String]
344-
# Arc Gateway resource Id
334+
# Arc Gateway resource Id, providing this will enable the gateway
345335
${GatewayResourceId}
346336
)
347337

@@ -415,10 +405,7 @@ function Set-AzConnectedKubernetes {
415405
$ResourceGroupName = $InputObject.ResourceGroupName
416406
$PSBoundParameters.Add('ResourceGroupName', $ResourceGroupName)
417407

418-
if ((-not $PSBoundParameters.ContainsKey('EnableGateway')) -and (-not $PSBoundParameters.ContainsKey('DisableGateway'))) {
419-
if ($InputObject.GatewayEnabled) {
420-
$EnableGateway = $InputObject.GatewayEnabled
421-
}
408+
if (-not $PSBoundParameters.ContainsKey('DisableGateway')) {
422409
if (-not $InputObject.GatewayEnabled) {
423410
$DisableGateway = -not $InputObject.GatewayEnabled
424411
}
@@ -427,11 +414,14 @@ function Set-AzConnectedKubernetes {
427414
$GatewayResourceId = $InputObject.GatewayResourceId
428415
$PSBoundParameters.Add('GatewayResourceId', $GatewayResourceId)
429416
}
417+
418+
if (-not $PSBoundParameters.ContainsKey('DisableAutoUpgrade')) {
419+
$DisableAutoUpgrade = ($InputObject.ArcAgentProfileAgentAutoUpgrade -eq 'Disabled')
420+
}
430421
}
431422

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

475-
476465
#Endregion
477466

478467
#Region validate release namespace
@@ -511,9 +500,9 @@ function Set-AzConnectedKubernetes {
511500

512501
$options = ""
513502

514-
if ($DisableAutoUpgrade) {
515-
$options += " --set systemDefaultValues.azureArcAgents.autoUpdate=false"
503+
if ($DisableAutoUpgrade -or ($ExistConnectedKubernetes.ArcAgentProfileAgentAutoUpgrade -eq 'Disabled')) {
516504
$Null = $PSBoundParameters.Remove('DisableAutoUpgrade')
505+
$PSBoundParameters.Add('ArcAgentProfileAgentAutoUpgrade', 'Disabled')
517506
}
518507
if (-not ([string]::IsNullOrEmpty($ContainerLogPath))) {
519508
$options += " --set systemDefaultValues.fluent-bit.containerLogPath=$ContainerLogPath"
@@ -549,6 +538,17 @@ function Set-AzConnectedKubernetes {
549538
#Endregion
550539

551540
#Region Deal with configuration settings and protected settings
541+
542+
# If the user does not provide proxy settings, or configuration settings, we shall use arc config of existing object
543+
$userProvidedArcConfiguration = (
544+
($null -ne $InputObject) -and ($InputObject.ArcAgentryConfiguration.Length > 0) `
545+
-and (-not ([string]::IsNullOrEmpty($HttpProxy))) `
546+
-and (-not ([string]::IsNullOrEmpty($HttpsProxy))) `
547+
-and (-not ([string]::IsNullOrEmpty($NoProxy))) `
548+
-and ((-not ([string]::IsNullOrEmpty($ProxyCert)))) `
549+
-and ($PSBoundParameters.ContainsKey('ConfigurationSetting')) `
550+
-and ($PSBoundParameters.ContainsKey('ConfigurationProtectedSetting')))
551+
552552
if ($null -eq $ConfigurationSetting) {
553553
$ConfigurationSetting = @{}
554554
}
@@ -654,9 +654,18 @@ function Set-AzConnectedKubernetes {
654654
$PSBoundParameters.Remove('ConfigurationProtectedSetting')
655655
}
656656

657-
$PSBoundParameters.Add('ArcAgentryConfiguration', $arcAgentryConfigs)
657+
if ($userProvidedArcConfiguration) {
658+
$PSBoundParameters.Add('ArcAgentryConfiguration', $arcAgentryConfigs)
659+
} else {
660+
$PSBoundParameters.Add('ArcAgentryConfiguration', $ExistConnectedKubernetes.ArcAgentryConfiguration)
661+
}
658662

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

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

674-
$Response['properties']['arcAgentryConfigurations'] = $arcAgentryConfigs
683+
if ($userProvidedArcConfiguration) {
684+
$Response['properties']['arcAgentryConfigurations'] = $arcAgentryConfigs
685+
} else {
686+
$Response['properties']['arcAgentryConfigurations'] = $ExistConnectedKubernetes.ArcAgentryConfiguration
687+
}
688+
675689

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

695+
Write-Output "Preparing helm ...."
696+
681697
if ($PSCmdlet.ShouldProcess('configDP', 'get helm values from config DP')) {
682698
$helmValuesDp = Get-HelmValuesFromConfigDP `
683699
-configDPEndpoint $configDPEndpoint `
@@ -741,6 +757,7 @@ function Set-AzConnectedKubernetes {
741757
}
742758
}
743759

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

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

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

776793
if ($ExistConnectedKubernetes.ArcAgentProfileAgentState -eq "Succeeded") {
777-
Write-Host "Cluster configuration succeeded."
794+
Write-Output "Cluster configuration succeeded."
778795
} elseif ($ExistConnectedKubernetes.ArcAgentProfileAgentState -eq "Failed") {
779796
Write-Error "Cluster configuration failed."
780797
} else {

src/ConnectedKubernetes/ConnectedKubernetes.Autorest/examples/Set-AzConnectedKubernetes.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
### Example 1: Disable gateway feature of a connected kubernetes.
1+
### Example 1: Disable gateway feature of a connected kubernetes.
22
```powershell
33
Set-AzConnectedKubernetes -ClusterName azps_test_cluster -ResourceGroupName azps_test_group -Location eastus -DisableGateway
44
```
@@ -13,7 +13,7 @@ This command disable gateway feature of a connected kubernetes.
1313

1414
### Example 2: Enable gateway feature of connected kubernetes.
1515
```powershell
16-
Set-AzConnectedKubernetes -ClusterName azps_test_cluster -ResourceGroupName azps_test_group -Location eastus -EnableGateway -GatewayResourceId gatewayResourceId
16+
Set-AzConnectedKubernetes -ClusterName azps_test_cluster -ResourceGroupName azps_test_group -Location eastus -GatewayResourceId gatewayResourceId
1717
1818
```
1919

src/ConnectedKubernetes/ConnectedKubernetes.Autorest/exports/ProxyCmdletDefinitions.ps1

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1021,7 +1021,7 @@ API to set properties of the connected cluster resource
10211021
.Example
10221022
Set-AzConnectedKubernetes -ClusterName azps_test_cluster -ResourceGroupName azps_test_group -Location eastus -DisableGateway
10231023
.Example
1024-
Set-AzConnectedKubernetes -ClusterName azps_test_cluster -ResourceGroupName azps_test_group -Location eastus -EnableGateway -GatewayResourceId gatewayResourceId
1024+
Set-AzConnectedKubernetes -ClusterName azps_test_cluster -ResourceGroupName azps_test_group -Location eastus -GatewayResourceId gatewayResourceId
10251025
10261026
10271027
.Outputs
@@ -1081,7 +1081,6 @@ function Set-AzConnectedKubernetes {
10811081
param(
10821082
[Parameter(ParameterSetName='SetExpanded', Mandatory)]
10831083
[Parameter(ParameterSetName='SetExpandedDisableGateway', Mandatory)]
1084-
[Parameter(ParameterSetName='SetExpandedEnableGateway', Mandatory)]
10851084
[Alias('Name')]
10861085
[Microsoft.Azure.PowerShell.Cmdlets.ConnectedKubernetes.Category('Path')]
10871086
[System.String]
@@ -1090,7 +1089,6 @@ param(
10901089

10911090
[Parameter(ParameterSetName='SetExpanded', Mandatory)]
10921091
[Parameter(ParameterSetName='SetExpandedDisableGateway', Mandatory)]
1093-
[Parameter(ParameterSetName='SetExpandedEnableGateway', Mandatory)]
10941092
[Microsoft.Azure.PowerShell.Cmdlets.ConnectedKubernetes.Category('Path')]
10951093
[System.String]
10961094
# The name of the resource group.
@@ -1142,7 +1140,6 @@ param(
11421140

11431141
[Parameter(ParameterSetName='SetExpanded', Mandatory)]
11441142
[Parameter(ParameterSetName='SetExpandedDisableGateway', Mandatory)]
1145-
[Parameter(ParameterSetName='SetExpandedEnableGateway', Mandatory)]
11461143
[Microsoft.Azure.PowerShell.Cmdlets.ConnectedKubernetes.Category('Body')]
11471144
[System.String]
11481145
# The geo-location where the resource lives
@@ -1257,7 +1254,7 @@ param(
12571254
[Parameter()]
12581255
[Microsoft.Azure.PowerShell.Cmdlets.ConnectedKubernetes.Category('Body')]
12591256
[System.String]
1260-
# Arc Gateway resource Id
1257+
# Arc Gateway resource Id, providing this will enable the gateway
12611258
${GatewayResourceId},
12621259

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

1269-
[Parameter(ParameterSetName='SetExpandedEnableGateway', Mandatory)]
1270-
[Parameter(ParameterSetName='SetEnableGateway', Mandatory)]
1271-
[Microsoft.Azure.PowerShell.Cmdlets.ConnectedKubernetes.Category('Body')]
1272-
[System.Management.Automation.SwitchParameter]
1273-
${EnableGateway},
1274-
12751266
[Parameter(ParameterSetName='SetDisableGateway', Mandatory)]
1276-
[Parameter(ParameterSetName='SetEnableGateway', Mandatory)]
12771267
[Parameter(ParameterSetName='Set', Mandatory)]
12781268
[Microsoft.Azure.PowerShell.Cmdlets.ConnectedKubernetes.Category('Body')]
12791269
[Microsoft.Azure.PowerShell.Cmdlets.ConnectedKubernetes.Models.Api20240715Preview.IConnectedCluster]
@@ -1368,12 +1358,10 @@ begin {
13681358
$mapping = @{
13691359
SetExpanded = 'Az.ConnectedKubernetes.custom\Set-AzConnectedKubernetes';
13701360
SetExpandedDisableGateway = 'Az.ConnectedKubernetes.custom\Set-AzConnectedKubernetes';
1371-
SetExpandedEnableGateway = 'Az.ConnectedKubernetes.custom\Set-AzConnectedKubernetes';
13721361
SetDisableGateway = 'Az.ConnectedKubernetes.custom\Set-AzConnectedKubernetes';
1373-
SetEnableGateway = 'Az.ConnectedKubernetes.custom\Set-AzConnectedKubernetes';
13741362
Set = 'Az.ConnectedKubernetes.custom\Set-AzConnectedKubernetes';
13751363
}
1376-
if (('SetExpanded', 'SetExpandedDisableGateway', 'SetExpandedEnableGateway', 'SetDisableGateway', 'SetEnableGateway', 'Set') -contains $parameterSet -and -not $PSBoundParameters.ContainsKey('SubscriptionId')) {
1364+
if (('SetExpanded', 'SetExpandedDisableGateway', 'SetDisableGateway', 'Set') -contains $parameterSet -and -not $PSBoundParameters.ContainsKey('SubscriptionId')) {
13771365
$testPlayback = $false
13781366
$PSBoundParameters['HttpPipelinePrepend'] | Foreach-Object { if ($_) { $testPlayback = $testPlayback -or ('Microsoft.Azure.PowerShell.Cmdlets.ConnectedKubernetes.Runtime.PipelineMock' -eq $_.Target.GetType().FullName -and 'Playback' -eq $_.Target.Mode) } }
13791367
if ($testPlayback) {

0 commit comments

Comments
 (0)