Skip to content

Commit

Permalink
Migrate ConnectedKubernetes from generation to main (Azure#26675)
Browse files Browse the repository at this point in the history
* Move ConnectedKubernetes to main

* Update ChangeLog.md

---------

Co-authored-by: Yabo Hu <yabhu@microsoft.com>
  • Loading branch information
azure-powershell-bot and VeryEarly authored Nov 13, 2024
1 parent 691d74a commit c8dcd4c
Show file tree
Hide file tree
Showing 11 changed files with 179 additions and 64 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ function New-AzConnectedKubernetes {
catch {
# This is attempting to delete Azure Arc resources that are orphaned.
# We are catching and ignoring any messages here.
$null = helm delete azure-arc --ignore-not-found --namespace $ReleaseNamespace --kubeconfig $KubeConfig --kube-context $KubeContext
$null = helm delete azure-arc --ignore-not-found --namespace $ReleaseNamespace --kubeconfig $KubeConfig --kube-context $KubeContext | Out-Null
}
}

Expand Down Expand Up @@ -622,11 +622,11 @@ function New-AzConnectedKubernetes {

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

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

if ((-not $WhatIfPreference) -and (-not $Response)) {
if ((-not $WhatIfPreference) -and (-not $CCResponse)) {
Write-Error "Failed to create the 'Kubernetes - Azure Arc' resource."
return
}
Expand All @@ -639,8 +639,8 @@ function New-AzConnectedKubernetes {
-Debug:($PSCmdlet.MyInvocation.BoundParameters["Debug"].IsPresent -eq $true)

# Convert the $Response object into a nested hashtable.
Write-Debug "PUT response: $Response"
$Response = ConvertFrom-Json "$Response"
Write-Debug "PUT response: $CCResponse"
$Response = ConvertFrom-Json "$CCResponse"
$Response = ConvertTo-Hashtable $Response

# What-If processing does not create a full response so we might have
Expand Down Expand Up @@ -716,7 +716,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...."
Write-Verbose "Executing helm upgrade command, this can take a few minutes...."
try {
helm upgrade `
--install azure-arc `
Expand All @@ -733,7 +733,7 @@ function New-AzConnectedKubernetes {
--set global.azureEnvironment=AZUREPUBLICCLOUD `
--set systemDefaultValues.clusterconnect-agent.enabled=true `
--set global.kubernetesDistro=$Distribution `
--set global.kubernetesInfra=$Infrastructure (-split $options)
--set global.kubernetesInfra=$Infrastructure (-split $options) | Out-Null
}
catch {
throw "Unable to install helm chart at $ChartPath"
Expand All @@ -744,7 +744,7 @@ function New-AzConnectedKubernetes {
if ($PSBoundParameters.ContainsKey('OidcIssuerProfileEnabled') -or $PSBoundParameters.ContainsKey('WorkloadIdentityEnabled') ) {
$ExistConnectedKubernetes = Get-AzConnectedKubernetes -ResourceGroupName $ResourceGroupName -ClusterName $ClusterName @CommonPSBoundParameters

Write-Output "Cluster configuration is in progress..."
Write-Verbose "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 @@ -753,7 +753,7 @@ function New-AzConnectedKubernetes {
}

if ($ExistConnectedKubernetes.ArcAgentProfileAgentState -eq "Succeeded") {
Write-Output "Cluster configuration succeeded."
Write-Verbose "Cluster configuration succeeded."
}
elseif ($ExistConnectedKubernetes.ArcAgentProfileAgentState -eq "Failed") {
Write-Error "Cluster configuration failed."
Expand All @@ -763,6 +763,6 @@ function New-AzConnectedKubernetes {
}
}
}
Return $Response
Return $CCResponse
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -675,12 +675,46 @@ function Set-AzConnectedKubernetes {

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

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

# Wait for the agent state to settle before proceeding. If it doesn't,
# we'll continue anyway - but remember and throw an error at the end.
$agentsInTerminalState = $true
if ($PSCmdlet.ShouldProcess($ClusterName, "Check agent state of the connected cluster")) {

$timeout = [datetime]::Now.AddMinutes(60)

for (;;) {
$CCResponse = Get-AzConnectedKubernetes -ResourceGroupName $ResourceGroupName -ClusterName $ClusterName @CommonPSBoundParameters

if ($null -eq $CCResponse.ArcAgentProfileAgentState) {
Write-Verbose "No agent configuration in progress."
break
}
if ($CCResponse.ArcAgentProfileAgentState -eq "Succeeded") {
Write-Verbose "Cluster agent configuration succeeded."
break
}
if ($CCResponse.ArcAgentProfileAgentState -eq "Failed") {
Write-Error "Cluster agent configuration failed."
break
}
if ([datetime]::Now -ge $timeout) {
Write-Error "Cluster agent configuration timed out after 60 minutes."
$agentsInTerminalState = $false
break
}

Write-Verbose "Cluster agent configuration is in progress..."
Start-Sleep -Seconds 30
}
}

$arcAgentryConfigs = ConvertTo-ArcAgentryConfiguration `
-ConfigurationSetting $ConfigurationSetting `
-RedactedProtectedConfiguration $RedactedProtectedConfiguration `
Expand All @@ -690,8 +724,8 @@ function Set-AzConnectedKubernetes {


# Convert the $Response object into a nested hashtable.
Write-Debug "PUT response: $Response"
$Response = ConvertFrom-Json "$Response"
Write-Debug "PUT response: $CCResponse"
$Response = ConvertFrom-Json "$CCResponse"
$Response = ConvertTo-Hashtable $Response

# Whatif may return empty response
Expand All @@ -709,7 +743,7 @@ function Set-AzConnectedKubernetes {
$ResponseStr = $Response | ConvertTo-Json -Depth 10
Write-Debug "PUT response: $ResponseStr"

Write-Output "Preparing helm ...."
Write-Verbose "Preparing helm ...."

if ($PSCmdlet.ShouldProcess('configDP', 'get helm values from config DP')) {
$helmValuesDp = Get-HelmValuesFromConfigDP `
Expand Down Expand Up @@ -774,7 +808,7 @@ function Set-AzConnectedKubernetes {
-Debug:($PSCmdlet.MyInvocation.BoundParameters["Debug"].IsPresent -eq $true)
}

Write-Output "Executing helm upgrade, this can take a few minutes ...."
Write-Verbose "Executing helm upgrade, this can take a few minutes ...."
Write-Debug $options -ErrorAction Continue
if ($DebugPreference -eq "Continue") {
$options += " --debug"
Expand All @@ -786,37 +820,18 @@ function Set-AzConnectedKubernetes {
$ChartPath `
--namespace $ReleaseInstallNamespace `
-f $userValuesLocation `
--wait (-split $options)
--wait (-split $options) | Out-Null
}
catch {
throw "Unable to install helm release"
}
Return $Response
}

if ($PSCmdlet.ShouldProcess($ClusterName, "Check agent state of the connected cluster")) {
if ($PSBoundParameters.ContainsKey('OidcIssuerProfileEnabled') -or $PSBoundParameters.ContainsKey('WorkloadIdentityEnabled') ) {
$ExistConnectedKubernetes = Get-AzConnectedKubernetes -ResourceGroupName $ResourceGroupName -ClusterName $ClusterName @CommonPSBoundParameters

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)) {
Start-Sleep -Seconds 30
$ExistConnectedKubernetes = Get-AzConnectedKubernetes -ResourceGroupName $ResourceGroupName -ClusterName $ClusterName @CommonPSBoundParameters
}

if ($ExistConnectedKubernetes.ArcAgentProfileAgentState -eq "Succeeded") {
Write-Output "Cluster configuration succeeded."
}
elseif ($ExistConnectedKubernetes.ArcAgentProfileAgentState -eq "Failed") {
Write-Error "Cluster configuration failed."
}
else {
Write-Error "Cluster configuration timed out after 60 minutes."
}
}
# If there was a problem with agent state, throw the error now.
if ($agentsInTerminalState -eq $false) {
throw "Timed out waiting for Agent State to reach terminal state."
}
Return $CCResponse
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,16 @@ function New-MetadataForParameterSet()
$cmdletName = Get-MappedCmdletFromFunctionName $ParameterSetInfo.Name
$description = (Get-CmdletAttribute -CmdletInfo $ParameterSetInfo -AttributeName "DescriptionAttribute").Description
[object[]]$example = New-ExampleForParameterSet $ParameterSetInfo
if ($Null -eq $example)
{
$example = @()
}

[string[]]$signature = New-ParameterArrayInParameterSet $ParameterSetInfo
if ($Null -eq $signature)
{
$signature = @()
}

return @{
Path = $httpPath
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#
# Generated by: Microsoft Corporation
#
# Generated on: 11/8/2024
# Generated on: 11/13/2024
#

@{
Expand Down Expand Up @@ -58,10 +58,10 @@ RequiredAssemblies =
'ConnectedKubernetes.Autorest/bin/Az.ConnectedKubernetes.private.dll'

# Script files (.ps1) that are run in the caller's environment prior to importing this module.
# ScriptsToProcess = @()
ScriptsToProcess = @()

# Type files (.ps1xml) to be loaded when importing this module
# TypesToProcess = @()
TypesToProcess = @()

# Format files (.ps1xml) to be loaded when importing this module
FormatsToProcess =
Expand Down Expand Up @@ -100,7 +100,7 @@ PrivateData = @{
PSData = @{

# Tags applied to this module. These help with module discovery in online galleries.
Tags = 'Azure','ResourceManager','ARM','PSModule','ConnectedKubernetes'
Tags = 'Azure', 'ResourceManager', 'ARM', 'PSModule', 'ConnectedKubernetes'

# A URL to the license for this module.
LicenseUri = 'https://aka.ms/azps-license'
Expand All @@ -126,7 +126,7 @@ PrivateData = @{

} # End of PSData hashtable

} # End of PrivateData hashtable
} # End of PrivateData hashtable

# HelpInfo URI of this module
# HelpInfoURI = ''
Expand Down
1 change: 1 addition & 0 deletions src/ConnectedKubernetes/ConnectedKubernetes/ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
- Additional information about change #1
-->
## Upcoming Release
* Fixed output type of cmdlet

## Version 0.12.0
* Corrected function that only worked on Windows.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,25 @@ Returns the properties of the specified connected cluster, including name, ident
### List1 (Default)
```
Get-AzConnectedKubernetes [-SubscriptionId <String[]>] [-DefaultProfile <PSObject>]
[<CommonParameters>]
[-ProgressAction <ActionPreference>] [<CommonParameters>]
```

### Get
```
Get-AzConnectedKubernetes -ClusterName <String> -ResourceGroupName <String> [-SubscriptionId <String[]>]
[-DefaultProfile <PSObject>] [<CommonParameters>]
[-DefaultProfile <PSObject>] [-ProgressAction <ActionPreference>] [<CommonParameters>]
```

### List
```
Get-AzConnectedKubernetes -ResourceGroupName <String> [-SubscriptionId <String[]>] [-DefaultProfile <PSObject>]
[<CommonParameters>]
[-ProgressAction <ActionPreference>] [<CommonParameters>]
```

### GetViaIdentity
```
Get-AzConnectedKubernetes -InputObject <IConnectedKubernetesIdentity> [-DefaultProfile <PSObject>]
[<CommonParameters>]
[-ProgressAction <ActionPreference>] [<CommonParameters>]
```

## DESCRIPTION
Expand Down Expand Up @@ -145,6 +145,21 @@ Accept pipeline input: True (ByValue)
Accept wildcard characters: False
```
### -ProgressAction
{{ Fill ProgressAction Description }}
```yaml
Type: System.Management.Automation.ActionPreference
Parameter Sets: (All)
Aliases: proga

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```
### -ResourceGroupName
The name of the resource group.
The name is case insensitive.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ Gets cluster user credentials of the connected cluster with a specified resource
```
Get-AzConnectedKubernetesUserCredential -ClusterName <String> -ResourceGroupName <String>
[-SubscriptionId <String[]>] -AuthenticationMethod <AuthenticationMethod> [-ClientProxy]
[-DefaultProfile <PSObject>] [-WhatIf] [-Confirm] [<CommonParameters>]
[-DefaultProfile <PSObject>] [-ProgressAction <ActionPreference>] [-WhatIf] [-Confirm] [<CommonParameters>]
```

### List
```
Get-AzConnectedKubernetesUserCredential -ClusterName <String> -ResourceGroupName <String>
[-SubscriptionId <String[]>] -Property <IListClusterUserCredentialProperties> [-DefaultProfile <PSObject>]
[-WhatIf] [-Confirm] [<CommonParameters>]
[-ProgressAction <ActionPreference>] [-WhatIf] [-Confirm] [<CommonParameters>]
```

## DESCRIPTION
Expand Down Expand Up @@ -130,6 +130,21 @@ Accept pipeline input: False
Accept wildcard characters: False
```
### -ProgressAction
{{ Fill ProgressAction Description }}
```yaml
Type: System.Management.Automation.ActionPreference
Parameter Sets: (All)
Aliases: proga

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```
### -Property
.
To construct, see NOTES section for PROPERTY properties and create a hash table.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ New-AzConnectedKubernetes -ClusterName <String> -ResourceGroupName <String> [-Su
[-CustomLocationsOid <String>] [-OidcIssuerProfileEnabled] [-OidcIssuerProfileSelfHostedIssuerUrl <String>]
[-WorkloadIdentityEnabled] [-AcceptEULA] [-DefaultProfile <PSObject>] [-AsJob] [-NoWait]
[-ConfigurationSetting <Hashtable>] [-ConfigurationProtectedSetting <Hashtable>] [-GatewayResourceId <String>]
[-WhatIf] [-Confirm] [<CommonParameters>]
[-ProgressAction <ActionPreference>] [-WhatIf] [-Confirm] [<CommonParameters>]
```

## DESCRIPTION
Expand Down Expand Up @@ -531,6 +531,21 @@ Accept pipeline input: False
Accept wildcard characters: False
```
### -ProgressAction
{{ Fill ProgressAction Description }}
```yaml
Type: System.Management.Automation.ActionPreference
Parameter Sets: (All)
Aliases: proga

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```
### -ProvisioningState
Provisioning state of the connected cluster resource.
Expand Down
Loading

0 comments on commit c8dcd4c

Please sign in to comment.