diff --git a/src/ConnectedKubernetes/ConnectedKubernetes.Autorest/Az.ConnectedKubernetes.psd1 b/src/ConnectedKubernetes/ConnectedKubernetes.Autorest/Az.ConnectedKubernetes.psd1 index 639e92376889..99fc4deda480 100644 --- a/src/ConnectedKubernetes/ConnectedKubernetes.Autorest/Az.ConnectedKubernetes.psd1 +++ b/src/ConnectedKubernetes/ConnectedKubernetes.Autorest/Az.ConnectedKubernetes.psd1 @@ -1,5 +1,5 @@ @{ - GUID = 'd3467834-8989-4142-8c05-ab93c4bfa6eb' + GUID = 'efbb1325-5081-4947-8508-ab47abbf6e76' RootModule = './Az.ConnectedKubernetes.psm1' ModuleVersion = '0.1.0' CompatiblePSEditions = 'Core', 'Desktop' diff --git a/src/ConnectedKubernetes/ConnectedKubernetes.Autorest/build-module.ps1 b/src/ConnectedKubernetes/ConnectedKubernetes.Autorest/build-module.ps1 index 922a23b3f1b7..d01944fe2481 100644 --- a/src/ConnectedKubernetes/ConnectedKubernetes.Autorest/build-module.ps1 +++ b/src/ConnectedKubernetes/ConnectedKubernetes.Autorest/build-module.ps1 @@ -67,6 +67,8 @@ if(-not $Isolated -and -not $Debugger) { $binFolder = Join-Path $PSScriptRoot 'bin' $objFolder = Join-Path $PSScriptRoot 'obj' +$isAzure = [System.Convert]::ToBoolean('true') + if(-not $Debugger) { Write-Host -ForegroundColor Green 'Cleaning build folders...' $null = Remove-Item -Recurse -ErrorAction SilentlyContinue -Path $binFolder, $objFolder @@ -143,7 +145,7 @@ if($NoDocs) { $null = Get-ChildItem -Path $docsFolder -Recurse -Exclude 'README.md' | Remove-Item -Recurse -ErrorAction SilentlyContinue } $null = New-Item -ItemType Directory -Force -Path $docsFolder - $addComplexInterfaceInfo = ![System.Convert]::ToBoolean('true') + $addComplexInterfaceInfo = !$isAzure Export-ProxyCmdlet -ModuleName $moduleName -ModulePath $modulePaths -ExportsFolder $exportsFolder -InternalFolder $internalFolder -ModuleDescription $moduleDescription -DocsFolder $docsFolder -ExamplesFolder $examplesFolder -ModuleGuid $guid -AddComplexInterfaceInfo:$addComplexInterfaceInfo } @@ -178,5 +180,4 @@ if (-not $DisableAfterBuildTasks){ } } - -Write-Host -ForegroundColor Green '-------------Done-------------' +Write-Host -ForegroundColor Green '-------------Done-------------' \ No newline at end of file diff --git a/src/ConnectedKubernetes/ConnectedKubernetes.Autorest/custom/DEVELOP.md b/src/ConnectedKubernetes/ConnectedKubernetes.Autorest/custom/DEVELOP.md index f9974023d076..c09ab184b9b3 100644 --- a/src/ConnectedKubernetes/ConnectedKubernetes.Autorest/custom/DEVELOP.md +++ b/src/ConnectedKubernetes/ConnectedKubernetes.Autorest/custom/DEVELOP.md @@ -1,42 +1,99 @@ -# Develpoing ConnectedKubernetes Powershell Cmdlets -> These notes are intended to compliment and extend the common instructions for this process. If you spot a sensible common location where part of this document could live, please do move the information out of here. +# Developing ConnectedKubernetes Powershell Cmdlets +> These notes are intended to complement and extend the common instructions for this process. If you spot a sensible common location where part of this document could live, please do move the information out of here. # Overview ## Why Custom Cmdlets? -Powerhsll cmdlets can be created almost totally automatically for many products but ConnectedKubernetes is special. The standard cmdlet interations are one or more ([Swagger]) REST API exchanges with Azure but ConnectedKubernetes also has to install Azure Arc support into a Kubernetes cluster and this requires work to be performed using [helm]. +Powershell cmdlets can be created almost totally automatically for many products but ConnectedKubernetes is special. The standard cmdlet interactions are one or more ([Swagger]) REST API exchanges with Azure but ConnectedKubernetes also has to install Azure Arc support into a Kubernetes cluster and this requires work to be performed using [helm]. For this reason, the ConnectedKubernetes cmdlets have two or more steps such as: - Interact with Azure using the REST APIs; this often involves just calling the autogenerated cmdlets - Now interact with Kubernetes using [helm]. ## (Part) Autogeneration Process -The autogeneration process uses [autorest.powershell], an [autorest] extension for creating Powershell cmdlets based on a (Swagger) REST API definition. this is typically as follows: +The autogeneration process uses [autorest.powershell], an [autorest] extension for creating Powershell cmdlets based on a (Swagger) REST API definition. This tool is run via an [autorest] [Docker] image (you will need something like [Docker Desktop] installed). The typical cmdlet development process is this: 1. Carefully craft your [Swagger] definition of the REST API 1. Read the [Quickstart for Azure PowerShell development using code generator] 1. Clone the [azure-powershell] repo -1. Create a develpoment branch based on the `generate` branch **and not based on `main`**! -1. Run the [autorest] Docker image; if you have no local image for [autorest], refer to -1. Run [autorest] to generate configuration and files that will result in the autogenerated cmdlets -1. Run the build process (`pwsh build-module.ps1`) which completes the build process. +1. Create a development branch based on the `generate` branch **and not based on `main`**! +1. Run the [autorest] [Docker] image; see below if you do not already have a local image for [autorest], +1. Inside the [autorest] environment... + 1. Run `autorest` to generate configuration and files that will result in the autogenerated cmdlets + 1. Run the build process, `pwsh build-module.ps1`, which completes the build process + 1. Optionally create a local package `pwsh pack-module.ps1`. + +--- +Note that many of the intermediate steps rely on output from a previous step. For example `build-module.ps1` is an output from the `autorest` step. + +--- ### Building the [autorest] Docker image -> Do **NOT** build an [autorest] image based on the Dockerfile contained in the `tools/autorest` directory below the [azure-powershell] repo as this does not produce a working image! +If you do not already have an [autorest] image, do **NOT** build one using the Dockerfile contained in the `tools/autorest` directory in the [azure-powershell] - repo as this does not produce a working image! Instead, build the image like this: - Clone the [autorest.powershell] repo - Navigate to the `tools/docker` directory -- Follow the instructions in the README file in that directory +- Follow the instructions in the README file in that directory. ## Special Aspects for ConnectedKubernetes The autogenerated cmdlets are created in C# with Powershell wrappers that are placed into the `internal` folder. This is because we are **NOT** exposing the autogenerated functions to the user, rather er export our custom versions. > As described earlier, the custom versions often call-through to the autogenerated version to perform the ARM REST API portion of their work. -### Gotchas -#### You Want a New Cmdlet? +The custom cmdlets can be found in the `custom` directory. They are written in Powershell and do some manuipulation of input parameters before interacting with Azure and then Kubernetes via [helm]. + +## Gotchas +### Desktop Powershell (v5.1) Back-Compatibility +The `Az` packages are all written to work with the preinstalled Windows Desktop version of Powershell, which is obsolete! + +We have to maintain this compatibility and the way to prove this is to use `PSScriptAnalyzer` (invoked as `Invoke-ScriptAnalyzer`) to confirm this. The process is below and the following references contain useful information: +- https://devblogs.microsoft.com/powershell/using-psscriptanalyzer-to-check-powershell-version-compatibility/ +- https://learn.microsoft.com/en-gb/powershell/utility-modules/psscriptanalyzer/rules/usecompatiblecommands?view=ps-modules + +```Powershell +# Run this from within the "custom" directory. +Write-Host -ForegroundColor Green 'Linting and checking Powershell back-compatibility...' +Install-Module PSScriptAnalyzer -Scope CurrentUser -Force +$settings = @{ + # Ref: https://devblogs.microsoft.com/powershell/using-psscriptanalyzer-to-check-powershell-version-compatibility/ + Rules = @{ + PSUseCompatibleSyntax = @{ + # This turns the rule on (setting it to false will turn it off) + Enable = $true + + # List the targeted versions of PowerShell here + TargetVersions = @( + '5.1', + '7.0' + ) + } + PSUseCompatibleCommands = @{ + # Turns the rule on + Enable = $true + + # Lists the PowerShell platforms we want to check compatibility with + # Ref: https://learn.microsoft.com/en-gb/powershell/utility-modules/psscriptanalyzer/rules/usecompatiblecommands?view=ps-modules + TargetProfiles = @( + 'win-8_x64_10.0.17763.0_5.1.17763.316_x64_4.0.30319.42000_framework', + 'win-8_x64_10.0.14393.0_7.0.0_x64_3.1.2_core' + ) + } +} + +# Recursively find all *.ps1 files and run Invoke-ScriptAnalyzer against them. +Get-ChildItem -Path . -Recurse -Include '*.ps1' | Invoke-ScriptAnalyzer -Settings $settings +if ($LastExitCode -ne 0) { + Write-Error 'ScriptAnalyzer found (possibly back-compatibility) issues.' +} +``` + + +### Dependencies +We have thus far been unable to make the `Az.ConnectedKubernetes` module install its dependencies (`Az.Resources` and `Az.Accounts`). This is possible for powershell but the issue is that the configuration to do this has to somehow be passed through the [autorest] process and attempts to do this have thus far failed. + +### You Want a New Cmdlet? If you are creating a whole new command, then you need to get the [autorest] process and the build process to work together to create the underlying `internal` command for you and this is not trivial. When we tried to add the `Set-` cmdlet, we found it never appeared but eventually we discovered these nuggets of knowledge. -- [autorest] will look at the `operationId` field in the [Swagger] for each REST API method and determine what commands to create. So in our case `ConnectedCluster_Create` only causes `New-` cmdlets to be created and we had to update the [Swagger] to say `ConnectedCluster_CreateOrUpdate` before any `Set-` cmdlets were created +- [autorest] will look at the `operationId` field in the [Swagger] for each REST API method and determine what commands to create. So in our case `ConnectedCluster_Create` only causes `New-` cmdlets to be created and we had to update the [Swagger] to say `ConnectedCluster_CreateOrUpdate` before any `Set-` cmdlets were created. Note that there are other options possible and the Swagger teams preferred `ConnectedCluster_CreateOrReplace` which works just as well for what we need and introduces no external API differences. - The `internal` cmdlets are really just Powershell wrappers but these are not created until the `pwsh build-module-ps1` step - Between the steps above sits the [autorest] configuration found in the XML at the end of [README.md]. This does stuff like: - Stops the generation of various versions of cmdlets that are not required @@ -48,4 +105,6 @@ When we tried to add the `Set-` cmdlet, we found it never appeared but eventuall [Swagger]: https://swagger.io/ [README.md]: ./README.md [Quickstart for Azure PowerShell development using code generator]: https://eng.ms/docs/cloud-ai-platform/azure-core/azure-management-and-platforms/control-plane-bburns/azure-cli-tools-azure-cli-powershell-and-terraform/azure-cli-tools/onboarding/azurepowershell/quickstart_codegen -[azure-powershell]: https://github.com/azure/azure-powershell \ No newline at end of file +[azure-powershell]: https://github.com/azure/azure-powershell +[Docker]: https://www.docker.com +[Docker Desktop]: https://www.docker.com/products/docker-desktop/ diff --git a/src/ConnectedKubernetes/ConnectedKubernetes.Autorest/custom/New-AzConnectedKubernetes.ps1 b/src/ConnectedKubernetes/ConnectedKubernetes.Autorest/custom/New-AzConnectedKubernetes.ps1 index 55b709814174..b770a2121d4c 100644 --- a/src/ConnectedKubernetes/ConnectedKubernetes.Autorest/custom/New-AzConnectedKubernetes.ps1 +++ b/src/ConnectedKubernetes/ConnectedKubernetes.Autorest/custom/New-AzConnectedKubernetes.ps1 @@ -10,8 +10,6 @@ # 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. # ---------------------------------------------------------------------------------- [System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseSingularNouns', '', @@ -374,7 +372,7 @@ function New-AzConnectedKubernetes { $helmClientLocation = 'helm' #Region get release namespace - $ReleaseNamespaces = Get-HelmReleaseNamespaces -KubeConfig $KubeConfig -KubeContext $KubeContext + $ReleaseNamespaces = Get-HelmReleaseNamespace -KubeConfig $KubeConfig -KubeContext $KubeContext $ReleaseNamespace = $ReleaseNamespaces['ReleaseNamespace'] $ReleaseInstallNamespace = $ReleaseNamespaces['ReleaseInstallNamespace'] @@ -417,7 +415,7 @@ function New-AzConnectedKubernetes { } } - $RegistryPath = Set-HelmRepositoryAndModules -KubeConfig $KubeConfig -KubeContext $KubeContext -Location $Location -ProxyCert $ProxyCert -DisableAutoUpgrade $DisableAutoUpgrade -ContainerLogPath $ContainerLogPath -CustomLocationsOid $CustomLocationsOid + $RegistryPath = Set-HelmModulesAndRepository -KubeConfig $KubeConfig -KubeContext $KubeContext -Location $Location # Region create RSA keys Write-Debug "Generating RSA keys for secure communication." @@ -641,9 +639,9 @@ 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" -AsHashTable -Depth 10 + $Response = ConvertFrom-Json "$Response" + $Response = ConvertTo-Hashtable $Response # What-If processing does not create a full response so we might have # to create a minimal one. @@ -660,7 +658,7 @@ function New-AzConnectedKubernetes { Write-Debug "PUT response: $Response" $ResponseStr = $Response | ConvertTo-Json -Depth 10 Write-Debug "PUT response: $ResponseStr" - + if ($PSCmdlet.ShouldProcess("configDP", "request Helm values")) { $helmValuesDp = Get-HelmValuesFromConfigDP ` -configDPEndpoint $configDPEndpoint ` @@ -736,8 +734,6 @@ function New-AzConnectedKubernetes { --set systemDefaultValues.clusterconnect-agent.enabled=true ` --set global.kubernetesDistro=$Distribution ` --set global.kubernetesInfra=$Infrastructure (-split $options) - - # $helmDebug } catch { throw "Unable to install helm chart at $ChartPath" @@ -747,15 +743,15 @@ function New-AzConnectedKubernetes { 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." } @@ -764,7 +760,7 @@ function New-AzConnectedKubernetes { } else { Write-Error "Cluster configuration timed out after 60 minutes." - } + } } } Return $Response diff --git a/src/ConnectedKubernetes/ConnectedKubernetes.Autorest/custom/Remove-AzConnectedKubernetes.ps1 b/src/ConnectedKubernetes/ConnectedKubernetes.Autorest/custom/Remove-AzConnectedKubernetes.ps1 index f41edf4a37e6..d77604ce0eec 100644 --- a/src/ConnectedKubernetes/ConnectedKubernetes.Autorest/custom/Remove-AzConnectedKubernetes.ps1 +++ b/src/ConnectedKubernetes/ConnectedKubernetes.Autorest/custom/Remove-AzConnectedKubernetes.ps1 @@ -10,9 +10,10 @@ # 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. # ---------------------------------------------------------------------------------- +[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseSingularNouns', '', + Justification = 'Kubernetes is a recognised term', Scope = 'Function', Target = 'Remove-AzConnectedKubernetes')] +param() <# .Synopsis @@ -42,124 +43,127 @@ INPUTOBJECT : Identity Parameter https://learn.microsoft.com/powershell/module/az.connectedkubernetes/remove-azconnectedkubernetes #> function Remove-AzConnectedKubernetes { -[OutputType([System.Boolean])] -[CmdletBinding(DefaultParameterSetName='Delete', PositionalBinding=$false, SupportsShouldProcess, ConfirmImpact='Medium')] -param( - [Parameter(ParameterSetName='Delete', Mandatory)] - [Alias('Name')] - [Microsoft.Azure.PowerShell.Cmdlets.ConnectedKubernetes.Category('Path')] - [System.String] - # The name of the Kubernetes cluster on which get is called. - ${ClusterName}, - - [Parameter(ParameterSetName='Delete', Mandatory)] - [Microsoft.Azure.PowerShell.Cmdlets.ConnectedKubernetes.Category('Path')] - [System.String] - # The name of the resource group. - # The name is case insensitive. - ${ResourceGroupName}, - - [Parameter(HelpMessage="Path to the kube config file")] - [Microsoft.Azure.PowerShell.Cmdlets.ConnectedKubernetes.Category('Body')] - [System.String] - # Path to the kube config file - ${KubeConfig}, - - [Parameter(HelpMessage="Kubconfig context from current machine")] - [Microsoft.Azure.PowerShell.Cmdlets.ConnectedKubernetes.Category('Body')] - [System.String] - # Kubconfig context from current machine - ${KubeContext}, - - [Parameter(ParameterSetName='Delete')] - [Microsoft.Azure.PowerShell.Cmdlets.ConnectedKubernetes.Category('Path')] - [Microsoft.Azure.PowerShell.Cmdlets.ConnectedKubernetes.Runtime.DefaultInfo(Script='(Get-AzContext).Subscription.Id')] - [System.String] - # The ID of the target subscription. - ${SubscriptionId}, - - [Parameter(ParameterSetName='DeleteViaIdentity', Mandatory, ValueFromPipeline)] - [Microsoft.Azure.PowerShell.Cmdlets.ConnectedKubernetes.Category('Path')] - [Microsoft.Azure.PowerShell.Cmdlets.ConnectedKubernetes.Models.IConnectedKubernetesIdentity] - # Identity Parameter - # To construct, see NOTES section for INPUTOBJECT properties and create a hash table. - ${InputObject}, - - [Parameter()] - [Alias('AzureRMContext', 'AzureCredential')] - [ValidateNotNull()] - [Microsoft.Azure.PowerShell.Cmdlets.ConnectedKubernetes.Category('Azure')] - [System.Management.Automation.PSObject] - # The credentials, account, tenant, and subscription used for communication with Azure. - ${DefaultProfile}, - - [Parameter()] - [Microsoft.Azure.PowerShell.Cmdlets.ConnectedKubernetes.Category('Runtime')] - [System.Management.Automation.SwitchParameter] - # Run the command as a job - ${AsJob}, - - [Parameter(DontShow)] - [Microsoft.Azure.PowerShell.Cmdlets.ConnectedKubernetes.Category('Runtime')] - [System.Management.Automation.SwitchParameter] - # Wait for .NET debugger to attach - ${Break}, - - [Parameter(DontShow)] - [ValidateNotNull()] - [Microsoft.Azure.PowerShell.Cmdlets.ConnectedKubernetes.Category('Runtime')] - [Microsoft.Azure.PowerShell.Cmdlets.ConnectedKubernetes.Runtime.SendAsyncStep[]] - # SendAsync Pipeline Steps to be appended to the front of the pipeline - ${HttpPipelineAppend}, - - [Parameter(DontShow)] - [ValidateNotNull()] - [Microsoft.Azure.PowerShell.Cmdlets.ConnectedKubernetes.Category('Runtime')] - [Microsoft.Azure.PowerShell.Cmdlets.ConnectedKubernetes.Runtime.SendAsyncStep[]] - # SendAsync Pipeline Steps to be prepended to the front of the pipeline - ${HttpPipelinePrepend}, - - [Parameter()] - [Microsoft.Azure.PowerShell.Cmdlets.ConnectedKubernetes.Category('Runtime')] - [System.Management.Automation.SwitchParameter] - # Run the command asynchronously - ${NoWait}, - - [Parameter()] - [Microsoft.Azure.PowerShell.Cmdlets.ConnectedKubernetes.Category('Runtime')] - [System.Management.Automation.SwitchParameter] - # Returns true when the command succeeds - ${PassThru}, - - [Parameter(DontShow)] - [Microsoft.Azure.PowerShell.Cmdlets.ConnectedKubernetes.Category('Runtime')] - [System.Uri] - # The URI for the proxy server to use - ${Proxy}, - - [Parameter(DontShow)] - [ValidateNotNull()] - [Microsoft.Azure.PowerShell.Cmdlets.ConnectedKubernetes.Category('Runtime')] - [System.Management.Automation.PSCredential] - # Credentials for a proxy server to use for the remote call - ${ProxyCredential}, - - [Parameter(DontShow)] - [Microsoft.Azure.PowerShell.Cmdlets.ConnectedKubernetes.Category('Runtime')] - [System.Management.Automation.SwitchParameter] - # Use the default credentials for the proxy - ${ProxyUseDefaultCredentials} -) + [OutputType([System.Boolean])] + [CmdletBinding(DefaultParameterSetName = 'Delete', PositionalBinding = $false, ConfirmImpact = 'Medium', SupportsShouldProcess = $true)] + param( + [Parameter(ParameterSetName = 'Delete', Mandatory)] + [Alias('Name')] + [Microsoft.Azure.PowerShell.Cmdlets.ConnectedKubernetes.Category('Path')] + [System.String] + # The name of the Kubernetes cluster on which get is called. + ${ClusterName}, + + [Parameter(ParameterSetName = 'Delete', Mandatory)] + [Microsoft.Azure.PowerShell.Cmdlets.ConnectedKubernetes.Category('Path')] + [System.String] + # The name of the resource group. + # The name is case insensitive. + ${ResourceGroupName}, + + [Parameter(HelpMessage = "Path to the kube config file")] + [Microsoft.Azure.PowerShell.Cmdlets.ConnectedKubernetes.Category('Body')] + [System.String] + # Path to the kube config file + ${KubeConfig}, + + [Parameter(HelpMessage = "Kubconfig context from current machine")] + [Microsoft.Azure.PowerShell.Cmdlets.ConnectedKubernetes.Category('Body')] + [System.String] + # Kubconfig context from current machine + ${KubeContext}, + + [Parameter(ParameterSetName = 'Delete')] + [Microsoft.Azure.PowerShell.Cmdlets.ConnectedKubernetes.Category('Path')] + [Microsoft.Azure.PowerShell.Cmdlets.ConnectedKubernetes.Runtime.DefaultInfo(Script = '(Get-AzContext).Subscription.Id')] + [System.String] + # The ID of the target subscription. + ${SubscriptionId}, + + [Parameter(ParameterSetName = 'DeleteViaIdentity', Mandatory, ValueFromPipeline)] + [Microsoft.Azure.PowerShell.Cmdlets.ConnectedKubernetes.Category('Path')] + [Microsoft.Azure.PowerShell.Cmdlets.ConnectedKubernetes.Models.IConnectedKubernetesIdentity] + # Identity Parameter + # To construct, see NOTES section for INPUTOBJECT properties and create a hash table. + ${InputObject}, + + [Parameter()] + [Alias('AzureRMContext', 'AzureCredential')] + [ValidateNotNull()] + [Microsoft.Azure.PowerShell.Cmdlets.ConnectedKubernetes.Category('Azure')] + [System.Management.Automation.PSObject] + # The credentials, account, tenant, and subscription used for communication with Azure. + ${DefaultProfile}, + + [Parameter()] + [Microsoft.Azure.PowerShell.Cmdlets.ConnectedKubernetes.Category('Runtime')] + [System.Management.Automation.SwitchParameter] + # Run the command as a job + ${AsJob}, + + [Parameter(DontShow)] + [Microsoft.Azure.PowerShell.Cmdlets.ConnectedKubernetes.Category('Runtime')] + [System.Management.Automation.SwitchParameter] + # Wait for .NET debugger to attach + ${Break}, + + [Parameter(DontShow)] + [ValidateNotNull()] + [Microsoft.Azure.PowerShell.Cmdlets.ConnectedKubernetes.Category('Runtime')] + [Microsoft.Azure.PowerShell.Cmdlets.ConnectedKubernetes.Runtime.SendAsyncStep[]] + # SendAsync Pipeline Steps to be appended to the front of the pipeline + ${HttpPipelineAppend}, + + [Parameter(DontShow)] + [ValidateNotNull()] + [Microsoft.Azure.PowerShell.Cmdlets.ConnectedKubernetes.Category('Runtime')] + [Microsoft.Azure.PowerShell.Cmdlets.ConnectedKubernetes.Runtime.SendAsyncStep[]] + # SendAsync Pipeline Steps to be prepended to the front of the pipeline + ${HttpPipelinePrepend}, + + [Parameter()] + [Microsoft.Azure.PowerShell.Cmdlets.ConnectedKubernetes.Category('Runtime')] + [System.Management.Automation.SwitchParameter] + # Run the command asynchronously + ${NoWait}, + + [Parameter()] + [Microsoft.Azure.PowerShell.Cmdlets.ConnectedKubernetes.Category('Runtime')] + [System.Management.Automation.SwitchParameter] + # Returns true when the command succeeds + ${PassThru}, + + [Parameter(DontShow)] + [Microsoft.Azure.PowerShell.Cmdlets.ConnectedKubernetes.Category('Runtime')] + [System.Uri] + # The URI for the proxy server to use + ${Proxy}, + + [Parameter(DontShow)] + [ValidateNotNull()] + [Microsoft.Azure.PowerShell.Cmdlets.ConnectedKubernetes.Category('Runtime')] + [System.Management.Automation.PSCredential] + # Credentials for a proxy server to use for the remote call + ${ProxyCredential}, + + [Parameter(DontShow)] + [Microsoft.Azure.PowerShell.Cmdlets.ConnectedKubernetes.Category('Runtime')] + [System.Management.Automation.SwitchParameter] + # Use the default credentials for the proxy + ${ProxyUseDefaultCredentials} + ) process { . "$PSScriptRoot/helpers/HelmHelper.ps1" if ($PSBoundParameters.ContainsKey('KubeConfig')) { $Null = $PSBoundParameters.Remove('KubeConfig') - } elseif (Test-Path Env:KUBECONFIG) { + } + elseif (Test-Path Env:KUBECONFIG) { $KubeConfig = Get-ChildItem -Path $Env:KUBECONFIG - } elseif (Test-Path Env:Home) { + } + elseif (Test-Path Env:Home) { $KubeConfig = Join-Path -Path $Env:Home -ChildPath '.kube' | Join-Path -ChildPath 'config' - } else { + } + else { $KubeConfig = Join-Path -Path $Home -ChildPath '.kube' | Join-Path -ChildPath 'config' } if (-not (Test-Path $KubeConfig)) { @@ -184,7 +188,8 @@ param( Write-Error "Helm version 3+ is required. Ensure that you have installed the latest version of Helm. Learn more at https://aka.ms/arc/k8s/onboarding-helm-install" return } - } catch { + } + catch { throw "Helm version 3+ is required. Ensure that you have installed the latest version of Helm. Learn more at https://aka.ms/arc/k8s/onboarding-helm-install" } #Endregion @@ -197,13 +202,16 @@ param( $ReleaseNamespace = $null try { $ReleaseNamespace = (helm status azure-arc -o json --kubeconfig $KubeConfig --kube-context $KubeContext -n $ReleaseInstallNamespace | ConvertFrom-Json).namespace - } catch { + } + catch { Write-Error "Fail to find the namespace for azure-arc." } #Endregion if ($null -eq $ReleaseNamespace) { - Az.ConnectedKubernetes.internal\Remove-AzConnectedKubernetes @PSBoundParameters + if ($PSCmdlet.ShouldProcess($PSBoundParameters)) { + Az.ConnectedKubernetes.internal\Remove-AzConnectedKubernetes @PSBoundParameters + } return } @@ -218,15 +226,19 @@ param( $PSBoundParameters.Add('ClusterName') } if (($ResourceGroupName -eq $ConfigmapRgName) -and ($ClusterName -eq $ConfigmapClusterName)) { - Az.ConnectedKubernetes.internal\Remove-AzConnectedKubernetes @PSBoundParameters - helm delete azure-arc --namespace $ReleaseInstallNamespace --kubeconfig $KubeConfig --kube-context $KubeContext - } else { + if ($PSCmdlet.ShouldProcess($PSBoundParameters)) { + Az.ConnectedKubernetes.internal\Remove-AzConnectedKubernetes @PSBoundParameters + helm delete azure-arc --namespace $ReleaseInstallNamespace --kubeconfig $KubeConfig --kube-context $KubeContext + } + } + else { Write-Error "The current context in the kubeconfig file does not correspond to the connected cluster resource specified. Agents installed on this cluster correspond to the resource group name '$ConfigmapRgName' and resource name '$ConfigmapClusterName'." } if ($ReleaseNamespace -eq $ReleaseInstallNamespace) { try { kubectl delete namespace $ReleaseInstallNamespace - } catch { + } + catch { throw "Unable to clean-up kubernetes namespace: $ReleaseInstallNamespace" } } diff --git a/src/ConnectedKubernetes/ConnectedKubernetes.Autorest/custom/Set-AzConnectedKubernetes.ps1 b/src/ConnectedKubernetes/ConnectedKubernetes.Autorest/custom/Set-AzConnectedKubernetes.ps1 index 513793adf1cd..94c0997a55fc 100644 --- a/src/ConnectedKubernetes/ConnectedKubernetes.Autorest/custom/Set-AzConnectedKubernetes.ps1 +++ b/src/ConnectedKubernetes/ConnectedKubernetes.Autorest/custom/Set-AzConnectedKubernetes.ps1 @@ -10,8 +10,6 @@ # 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. # ---------------------------------------------------------------------------------- [System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseSingularNouns', '', @@ -23,7 +21,7 @@ param() .Synopsis API to set properties of the connected cluster resource .Description -API to set properties of the connected cluster resource +API to set properties of the connected cluster resource. Replaces all configuration of an existing connected cluster; any properties not specified will be reset to their default values. .Example Set-AzConnectedKubernetes -ClusterName azps_test_cluster -ResourceGroupName azps_test_group -Location eastus -GatewayResourceId $gatewayResourceId .Example @@ -36,7 +34,7 @@ COMPLEX PARAMETER PROPERTIES To create the parameters described below, construct a hash table containing the appropriate properties. For information on hash tables, run Get-Help about_Hash_Tables. -INPUTOBJECT : +INPUTOBJECT : Location : The geo-location where the resource lives AgentPublicKeyCertificate : Base64 encoded public certificate used by the agent to do the initial handshake to the backend services in Azure. IdentityType : The type of identity used for the connected cluster. The type 'SystemAssigned, includes a system created identity. The type 'None' means no identity is assigned to the connected cluster. @@ -88,6 +86,7 @@ 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] @@ -96,6 +95,7 @@ function Set-AzConnectedKubernetes { [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. @@ -104,13 +104,15 @@ function Set-AzConnectedKubernetes { [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 ${Location}, - [Parameter(ParameterSetName = 'Set', Mandatory)] - [Parameter(ParameterSetName = 'SetDisableGateway', Mandatory)] + [Parameter(ParameterSetName = 'Set', Mandatory, ValueFromPipeline)] + [Parameter(ParameterSetName = 'SetDisableGateway', Mandatory, ValueFromPipeline)] + [Parameter(ParameterSetName = 'SetEnableGateway', Mandatory, ValueFromPipeline)] [Microsoft.Azure.PowerShell.Cmdlets.ConnectedKubernetes.Category('Body')] [Microsoft.Azure.PowerShell.Cmdlets.ConnectedKubernetes.Models.Api20240715Preview.IConnectedCluster] ${InputObject}, @@ -243,7 +245,7 @@ function Set-AzConnectedKubernetes { [Parameter()] [Microsoft.Azure.PowerShell.Cmdlets.ConnectedKubernetes.Category('Body')] [System.Management.Automation.SwitchParameter] - # Whether to enable or disable the workload identity Webhook + # Enable the workload identity Webhook ${WorkloadIdentityEnabled}, [Parameter()] @@ -328,7 +330,8 @@ function Set-AzConnectedKubernetes { [System.Management.Automation.SwitchParameter] ${DisableGateway}, - [Parameter()] + [Parameter(ParameterSetName = 'SetEnableGateway', Mandatory)] + [Parameter(ParameterSetName = 'SetExpandedEnableGateway', Mandatory)] [Microsoft.Azure.PowerShell.Cmdlets.ConnectedKubernetes.Category('body')] [System.String] # Arc Gateway resource Id, providing this will enable the gateway @@ -394,7 +397,9 @@ function Set-AzConnectedKubernetes { $KubeContext = kubectl config current-context } - # Parse value from inputObject + # The internal Set command does not support inputObject probably due to current implementation of swagger + # So we do it hard way and parse value from inputObject + # ArcAgentryConfiguration is handled in a separate block if ($null -ne $InputObject) { $Location = $InputObject.Location $PSBoundParameters.Add('Location', $Location) @@ -405,31 +410,36 @@ function Set-AzConnectedKubernetes { $ResourceGroupName = $InputObject.ResourceGroupName $PSBoundParameters.Add('ResourceGroupName', $ResourceGroupName) - if (-not $PSBoundParameters.ContainsKey('DisableGateway')) { - if (-not $InputObject.GatewayEnabled) { - $DisableGateway = -not $InputObject.GatewayEnabled - } + if (-not $PSBoundParameters.ContainsKey('DisableGateway') -and $InputObject.PSObject.Properties['GatewayEnabled']) { + $DisableGateway = -not $InputObject.GatewayEnabled } if ((-not $PSBoundParameters.ContainsKey('GatewayResourceId')) -and (-not [String]::IsNullOrEmpty($InputObject.GatewayResourceId))) { $GatewayResourceId = $InputObject.GatewayResourceId - $PSBoundParameters.Add('GatewayResourceId', $GatewayResourceId) } if (-not $PSBoundParameters.ContainsKey('DisableAutoUpgrade')) { $DisableAutoUpgrade = ($InputObject.ArcAgentProfileAgentAutoUpgrade -eq 'Disabled') } + + # Merge the fields that use a common merging process. + Merge-MaybeNullInput -InputObject $InputObject -LclPSBoundParameters $PSBoundParameters } - if (-not [String]::IsNullOrEmpty($GatewayResourceId) -and -not $DisableGateway) { + if ($PSBoundParameters.ContainsKey('GatewayResourceId')) { Write-Debug "Gateway enabled" $PSBoundParameters.Add('GatewayEnabled', $true) } - # If DisableGateway is provided then set the gateway as disabled and remove gateway resourceId from parameters - if ($DisableGateway) { + elseif ($PSBoundParameters.ContainsKey('DisableGateway')) { Write-Debug "Gateway disabled" $Null = $PSBoundParameters.Remove('DisableGateway') $PSBoundParameters.Add('GatewayEnabled', $false) } + else { + $PSBoundParameters.Add('GatewayEnabled', -not $DisableGateway) + if (-not [String]::IsNullOrEmpty($GatewayResourceId)) { + $PSBoundParameters.Add('GatewayResourceId', $GatewayResourceId) + } + } $CommonPSBoundParameters = @{} if ($PSBoundParameters.ContainsKey('HttpPipelineAppend')) { @@ -461,7 +471,7 @@ function Set-AzConnectedKubernetes { $helmClientLocation = 'helm' #Region get release namespace - $ReleaseNamespaces = Get-HelmReleaseNamespaces -KubeConfig $KubeConfig -KubeContext $KubeContext + $ReleaseNamespaces = Get-HelmReleaseNamespace -KubeConfig $KubeConfig -KubeContext $KubeContext $ReleaseNamespace = $ReleaseNamespaces['ReleaseNamespace'] $ReleaseInstallNamespace = $ReleaseNamespaces['ReleaseInstallNamespace'] @@ -497,13 +507,13 @@ function Set-AzConnectedKubernetes { #Endregion # Adding Helm repo - $RegistryPath = Set-HelmRepositoryAndModules -KubeConfig $KubeConfig -KubeContext $KubeContext -Location $Location -ProxyCert $ProxyCert -DisableAutoUpgrade $DisableAutoUpgrade -ContainerLogPath $ContainerLogPath -CustomLocationsOid $CustomLocationsOid + $RegistryPath = Set-HelmModulesAndRepository -KubeConfig $KubeConfig -KubeContext $KubeContext -Location $Location Write-Debug "Processing Helm chart installation options." $options = "" - if ($DisableAutoUpgrade -or ($ExistConnectedKubernetes.ArcAgentProfileAgentAutoUpgrade -eq 'Disabled')) { + if ($DisableAutoUpgrade) { $Null = $PSBoundParameters.Remove('DisableAutoUpgrade') $PSBoundParameters.Add('ArcAgentProfileAgentAutoUpgrade', 'Disabled') } @@ -538,20 +548,11 @@ function Set-AzConnectedKubernetes { Write-Warning "If the proxy is a private proxy, pass ProxyCredential parameter or provide username and password in the Proxy parameter" } } + #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 = @{} } @@ -591,7 +592,7 @@ function Set-AzConnectedKubernetes { $NoProxy = $NoProxy -replace '/', '\/' $ConfigurationProtectedSetting["proxy"]["no_proxy"] = $NoProxy $Null = $PSBoundParameters.Remove('NoProxy') - } + } try { if ((-not ([string]::IsNullOrEmpty($ProxyCert))) -and (Test-Path $ProxyCert)) { @@ -672,12 +673,7 @@ function Set-AzConnectedKubernetes { $PSBoundParameters.Remove('ConfigurationProtectedSetting') } - if ($userProvidedArcConfiguration) { - $PSBoundParameters.Add('ArcAgentryConfiguration', $arcAgentryConfigs) - } - else { - $PSBoundParameters.Add('ArcAgentryConfiguration', $ExistConnectedKubernetes.ArcAgentryConfiguration) - } + $PSBoundParameters.Add('ArcAgentryConfiguration', $arcAgentryConfigs) Write-Output "Updating the connected cluster resource...." $Response = Az.ConnectedKubernetes.internal\Set-AzConnectedKubernetes @PSBoundParameters @@ -695,8 +691,9 @@ function Set-AzConnectedKubernetes { # Convert the $Response object into a nested hashtable. Write-Debug "PUT response: $Response" - $Response = ConvertFrom-Json "$Response" -AsHashTable -Depth 10 - + $Response = ConvertFrom-Json "$Response" + $Response = ConvertTo-Hashtable $Response + # Whatif may return empty response if (-not $Response) { $Response = @{} @@ -705,19 +702,13 @@ function Set-AzConnectedKubernetes { $Response['properties'] = @{} } - if ($userProvidedArcConfiguration) { - $Response['properties']['arcAgentryConfigurations'] = $arcAgentryConfigs - } - else { - $Response['properties']['arcAgentryConfigurations'] = $ExistConnectedKubernetes.ArcAgentryConfiguration - } - + $Response['properties']['arcAgentryConfigurations'] = $arcAgentryConfigs # 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')) { @@ -756,7 +747,7 @@ function Set-AzConnectedKubernetes { if ($ExistConnectedKubernetes.AgentVersion) { $repositoryPath = $repositoryPath -replace "(?<=:).*", $ExistConnectedKubernetes.AgentVersion } - } + } if ($PSCmdlet.ShouldProcess('configDP', 'get helm chart path')) { # Get helm chart path (within the OCI registry). @@ -774,19 +765,13 @@ function Set-AzConnectedKubernetes { # Get current helm values if ($PSCmdlet.ShouldProcess($ClusterName, "Get current helm values")) { - - try { - $userValuesLocation = Join-Path $env:USERPROFILE ".azure\userValues.txt" - - helm get values azure-arc ` - --debug ` - --namespace $ReleaseInstallNamespace ` - --kubeconfig $KubeConfig ` - --kube-context $KubeContext > $userValuesLocation - } - catch { - throw "Unable to get helm values" - } + $userValuesLocation = Get-HelmValue ` + -HelmClientLocation $HelmClientLocation ` + -Namespace $ReleaseInstallNamespace ` + -KubeConfig $KubeConfig ` + -KubeContext $KubeContext ` + -Verbose:($PSCmdlet.MyInvocation.BoundParameters["Verbose"].IsPresent -eq $true) ` + -Debug:($PSCmdlet.MyInvocation.BoundParameters["Debug"].IsPresent -eq $true) } Write-Output "Executing helm upgrade, this can take a few minutes ...." @@ -797,7 +782,6 @@ function Set-AzConnectedKubernetes { if ($PSCmdlet.ShouldProcess($ClusterName, "Update Kubernetes cluster with Azure Arc")) { try { helm upgrade ` - --debug ` azure-arc ` $ChartPath ` --namespace $ReleaseInstallNamespace ` @@ -813,15 +797,15 @@ function Set-AzConnectedKubernetes { 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." } @@ -830,8 +814,27 @@ function Set-AzConnectedKubernetes { } else { Write-Error "Cluster configuration timed out after 60 minutes." - } + } } } } } + +function Merge-MaybeNullInput { + [Microsoft.Azure.PowerShell.Cmdlets.ConnectedKubernetes.DoNotExportAttribute()] + param( + [Microsoft.Azure.PowerShell.Cmdlets.ConnectedKubernetes.Models.Api20240715Preview.IConnectedCluster] + $InputObject, + [System.Collections.Generic.Dictionary[system.String, System.Object]] + $LclPSBoundParameters + ) + + $mergeFields = 'WorkloadIdentityEnabled', 'OidcIssuerProfileEnabled', 'OidcIssuerProfileSelfHostedIssuerUrl', 'Distribution', 'DistributionVersion', 'Infrastructure', 'PrivateLinkState' + + foreach ($mergeField in $mergeFields) { + if ((-not $LclPSBoundParameters.ContainsKey($mergeField)) -and $InputObject.PSObject.Properties[$mergeField] -and $null -ne $InputObject.PSObject.Properties[$mergeField].Value) { + $parameterValue = $InputObject.PSObject.Properties[$mergeField].Value + $LclPSBoundParameters.Add($mergeField, $parameterValue) + } + } +} diff --git a/src/ConnectedKubernetes/ConnectedKubernetes.Autorest/custom/Update-AzConnectedKubernetes.ps1 b/src/ConnectedKubernetes/ConnectedKubernetes.Autorest/custom/Update-AzConnectedKubernetes.ps1 index d8441eea262b..8eef8b124fb9 100644 --- a/src/ConnectedKubernetes/ConnectedKubernetes.Autorest/custom/Update-AzConnectedKubernetes.ps1 +++ b/src/ConnectedKubernetes/ConnectedKubernetes.Autorest/custom/Update-AzConnectedKubernetes.ps1 @@ -10,9 +10,10 @@ # 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. # ---------------------------------------------------------------------------------- +[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseSingularNouns', '', + Justification = 'Kubernetes is a recognised term', Scope = 'Function', Target = 'Update-AzConnectedKubernetes')] +param() <# .Synopsis @@ -43,30 +44,30 @@ https://learn.microsoft.com/powershell/module/az.connectedkubernetes/update-azco #> function Update-AzConnectedKubernetes { [OutputType([Microsoft.Azure.PowerShell.Cmdlets.ConnectedKubernetes.Models.Api20240715Preview.IConnectedCluster])] - [CmdletBinding(DefaultParameterSetName='UpdateExpanded', PositionalBinding=$false, SupportsShouldProcess, ConfirmImpact='Medium')] + [CmdletBinding(DefaultParameterSetName = 'UpdateExpanded', PositionalBinding = $false, ConfirmImpact = 'Medium', SupportsShouldProcess)] param( - [Parameter(ParameterSetName='UpdateExpanded', Mandatory)] + [Parameter(ParameterSetName = 'UpdateExpanded', Mandatory)] [Alias('Name')] [Microsoft.Azure.PowerShell.Cmdlets.ConnectedKubernetes.Category('Path')] [System.String] # The name of the Kubernetes cluster on which get is called. ${ClusterName}, - [Parameter(ParameterSetName='UpdateExpanded', Mandatory)] + [Parameter(ParameterSetName = 'UpdateExpanded', Mandatory)] [Microsoft.Azure.PowerShell.Cmdlets.ConnectedKubernetes.Category('Path')] [System.String] # The name of the resource group. # The name is case insensitive. ${ResourceGroupName}, - [Parameter(ParameterSetName='UpdateExpanded')] + [Parameter(ParameterSetName = 'UpdateExpanded')] [Microsoft.Azure.PowerShell.Cmdlets.ConnectedKubernetes.Category('Path')] - [Microsoft.Azure.PowerShell.Cmdlets.ConnectedKubernetes.Runtime.DefaultInfo(Script='(Get-AzContext).Subscription.Id')] + [Microsoft.Azure.PowerShell.Cmdlets.ConnectedKubernetes.Runtime.DefaultInfo(Script = '(Get-AzContext).Subscription.Id')] [System.String] # The ID of the target subscription. ${SubscriptionId}, - [Parameter(ParameterSetName='UpdateViaIdentityExpanded', Mandatory, ValueFromPipeline)] + [Parameter(ParameterSetName = 'UpdateViaIdentityExpanded', Mandatory, ValueFromPipeline)] [Microsoft.Azure.PowerShell.Cmdlets.ConnectedKubernetes.Category('Path')] [Microsoft.Azure.PowerShell.Cmdlets.ConnectedKubernetes.Models.IConnectedKubernetesIdentity] # Identity Parameter @@ -99,7 +100,7 @@ function Update-AzConnectedKubernetes { [Parameter()] [Microsoft.Azure.PowerShell.Cmdlets.ConnectedKubernetes.Category('Body')] - [Microsoft.Azure.PowerShell.Cmdlets.ConnectedKubernetes.Runtime.Info(PossibleTypes=([Microsoft.Azure.PowerShell.Cmdlets.ConnectedKubernetes.Models.Api20240715Preview.IConnectedClusterPatchTags]))] + [Microsoft.Azure.PowerShell.Cmdlets.ConnectedKubernetes.Runtime.Info(PossibleTypes = ([Microsoft.Azure.PowerShell.Cmdlets.ConnectedKubernetes.Models.Api20240715Preview.IConnectedClusterPatchTags]))] [System.Collections.Hashtable] # Resource tags. ${Tag}, @@ -153,23 +154,26 @@ function Update-AzConnectedKubernetes { ) process { - if($AzureHybridBenefit){ - if(!$AcceptEULA){ + if ($AzureHybridBenefit) { + if (!$AcceptEULA) { $legalTermPath = Join-Path $PSScriptRoot -ChildPath "LegalTerm.txt" try { $legalTerm = (Get-Content -Path $legalTermPath) -join "`r`n" - } catch { + } + catch { Write-Error "Get legal term failed." throw } $confirmation = Read-Host $legalTerm"`n[Y] Yes [N] No (default is `"N`")" - if($confirmation -ine "Y"){ + if ($confirmation -ine "Y") { Return } } } $null = $PSBoundParameters.Remove('AcceptEULA') - Az.ConnectedKubernetes.internal\Update-AzConnectedKubernetes @PSBoundParameters + if ($PSCmdlet.ShouldProcess($PSBoundParameters)) { + Az.ConnectedKubernetes.internal\Update-AzConnectedKubernetes @PSBoundParameters + } } } \ No newline at end of file diff --git a/src/ConnectedKubernetes/ConnectedKubernetes.Autorest/custom/helpers/AzCloudMetadataHelper.ps1 b/src/ConnectedKubernetes/ConnectedKubernetes.Autorest/custom/helpers/AzCloudMetadataHelper.ps1 index 37782d6cbb39..c07be4df56ce 100644 --- a/src/ConnectedKubernetes/ConnectedKubernetes.Autorest/custom/helpers/AzCloudMetadataHelper.ps1 +++ b/src/ConnectedKubernetes/ConnectedKubernetes.Autorest/custom/helpers/AzCloudMetadataHelper.ps1 @@ -3,7 +3,7 @@ param() function Get-AZCloudMetadataResourceId { - [Microsoft.Azure.PowerShell.Cmdlets.ConnectedKubernetes.DoNotExport()] + [Microsoft.Azure.PowerShell.Cmdlets.ConnectedKubernetes.DoNotExportAttribute()] param ( [Parameter(Mandatory = $true)] [PSCustomObject]$cloudMetadata diff --git a/src/ConnectedKubernetes/ConnectedKubernetes.Autorest/custom/helpers/ConfigDPHelper.ps1 b/src/ConnectedKubernetes/ConnectedKubernetes.Autorest/custom/helpers/ConfigDPHelper.ps1 index 10bdb8d79079..c7d6c3273acd 100644 --- a/src/ConnectedKubernetes/ConnectedKubernetes.Autorest/custom/helpers/ConfigDPHelper.ps1 +++ b/src/ConnectedKubernetes/ConnectedKubernetes.Autorest/custom/helpers/ConfigDPHelper.ps1 @@ -27,8 +27,6 @@ function Invoke-ConfigDPHealthCheck { -Uri $chartLocationUrl ` -Headers $headers ` -UriParameters $uriParameters ` - -MaximumRetryCount 5 ` - -RetryIntervalSec 3 ` -StatusCodeVariable statusCode ` -Verbose:($PSCmdlet.MyInvocation.BoundParameters["Verbose"].IsPresent -eq $true) ` -Debug:($PSCmdlet.MyInvocation.BoundParameters["Debug"].IsPresent -eq $true) @@ -40,7 +38,7 @@ function Invoke-ConfigDPHealthCheck { function Get-ConfigDPEndpoint { - [Microsoft.Azure.PowerShell.Cmdlets.ConnectedKubernetes.DoNotExport()] + [Microsoft.Azure.PowerShell.Cmdlets.ConnectedKubernetes.DoNotExportAttribute()] param ( [Parameter(Mandatory = $true)] [string]$Location, @@ -56,12 +54,11 @@ function Get-ConfigDPEndpoint { -CloudMetadata $cloudMetadata ` -Verbose:($PSCmdlet.MyInvocation.BoundParameters["Verbose"].IsPresent -eq $true) ` -Debug:($PSCmdlet.MyInvocation.BoundParameters["Debug"].IsPresent -eq $true) - return @{ ConfigDpEndpoint = $ConfigDpEndpoint; ReleaseTrain = $ReleaseTrain } } function Get-ConfigDpDefaultEndpoint { - [Microsoft.Azure.PowerShell.Cmdlets.ConnectedKubernetes.DoNotExport()] + [Microsoft.Azure.PowerShell.Cmdlets.ConnectedKubernetes.DoNotExportAttribute()] param ( [Parameter(Mandatory = $true)] [string]$location, @@ -87,8 +84,6 @@ function Invoke-RestMethodWithUriParameters { [Hashtable]$headers, [System.Collections.Specialized.OrderedDictionary]$uriParameters, [String]$requestBody, - [Int]$maximumRetryCount, - [Int]$retryIntervalSec, [String]$statusCodeVariable ) @@ -107,26 +102,34 @@ function Invoke-RestMethodWithUriParameters { # $uriParametersArray = $uriParameters.GetEnumerator() | ForEach-Object { "$($_.Key)=$($_.Value)" } | ForEach-Object { $_ -join '=' } | ForEach-Object { $_ -join '&' } # } Write-Debug "Issue REST request to ${uri} with method ${method} and headers ${headers} and body ${requestBody}" - $rsp = Invoke-RestMethod ` - -Method $method ` - -Uri $uri ` - -Headers $headers ` - -Body $requestBody ` - -ContentType "application/json" ` - -MaximumRetryCount $maximumRetryCount ` - -RetryIntervalSec $retryintervalSec ` - -StatusCodeVariable statusCode ` - -Verbose:($PSCmdlet.MyInvocation.BoundParameters["Verbose"].IsPresent -eq $true) ` - -Debug:($PSCmdlet.MyInvocation.BoundParameters["Debug"].IsPresent -eq $true) + try { + $rsp = Invoke-RestMethod ` + -Method $method ` + -Uri $uri ` + -Headers $headers ` + -Body $requestBody ` + -ContentType "application/json" ` + -Verbose:($PSCmdlet.MyInvocation.BoundParameters["Verbose"].IsPresent -eq $true) ` + -Debug:($PSCmdlet.MyInvocation.BoundParameters["Debug"].IsPresent -eq $true) + $statusCode = 200; + } + catch { + # We do not know what went wrong, but something did! + $statusCode = 400 + Write-Error "Error while issuing REST request: $_" + } + finally { + # Note need to explcitly clear WhatIf for this method otherwise the value is + # not passed back during What-If testing. + Set-Variable -Name "${statusCodeVariable}" -Value $statusCode -Scope Script -WhatIf:$false + } Write-Debug "Response: $($rsp | ConvertTo-Json -Depth 10)" - # Note need to explcitly clear WhatIf for this method otherwise the value is - # not passed back during What-If testing. - Set-Variable -Name "${statusCodeVariable}" -Value $statusCode -Scope Script -WhatIf:$false return $rsp } + function Get-HelmValuesFromConfigDP { - [Microsoft.Azure.PowerShell.Cmdlets.ConnectedKubernetes.DoNotExport()] + [Microsoft.Azure.PowerShell.Cmdlets.ConnectedKubernetes.DoNotExportAttribute()] param ( [Parameter(Mandatory = $true)] $ConfigDpEndpoint, @@ -165,8 +168,6 @@ function Get-HelmValuesFromConfigDP { -Headers $headers ` -UriParameters $uriParameters ` -RequestBody $RequestBody ` - -MaximumRetryCount 5 ` - -RetryIntervalSec 3 ` -StatusCodeVariable StatusCode ` -Verbose:($PSCmdlet.MyInvocation.BoundParameters["Verbose"].IsPresent -eq $true) ` -Debug:($PSCmdlet.MyInvocation.BoundParameters["Debug"].IsPresent -eq $true) diff --git a/src/ConnectedKubernetes/ConnectedKubernetes.Autorest/custom/helpers/HelmHelper.ps1 b/src/ConnectedKubernetes/ConnectedKubernetes.Autorest/custom/helpers/HelmHelper.ps1 index 5f0d57f57eb7..227b6f6eaaba 100644 --- a/src/ConnectedKubernetes/ConnectedKubernetes.Autorest/custom/helpers/HelmHelper.ps1 +++ b/src/ConnectedKubernetes/ConnectedKubernetes.Autorest/custom/helpers/HelmHelper.ps1 @@ -3,6 +3,7 @@ param() function Set-HelmClientLocation { [Microsoft.Azure.PowerShell.Cmdlets.ConnectedKubernetes.DoNotExportAttribute()] + [CmdletBinding(SupportsShouldProcess = $true)] param( ) process { @@ -18,7 +19,9 @@ function Set-HelmClientLocation { if (!($env:Path.contains($HelmLocation)) -and (Test-Path $HelmLocation)) { Write-Debug "Updating PATH environment variable with Helm location." $PathStr = $HelmLocation + ";$env:Path" - Set-Item -Path Env:Path -Value $PathStr + if ($PSCmdlet.ShouldProcess($Env:Path)) { + Set-Item -Path Env:Path -Value $PathStr + } } } } @@ -122,9 +125,65 @@ function IsAmd64 { return $isSupport } } +function Get-AzureHelmPath { + [Microsoft.Azure.PowerShell.Cmdlets.ConnectedKubernetes.DoNotExportAttribute()] + param( + [string]$ChildPath + ) + + # The top-level directory is always determined from HOME or USERPROFILE + # and ".azure" + if (Test-Path Env:USERPROFILE) { + $Path = $Env:USERPROFILE + } + elseif (Test-Path Env:HOME) { + $Path = $Env:HOME + } + else { + throw "No environment to use as Azure/helm path root." + } + + # In Powershell v5.1 (Desktop), Join-Path lacks the AdditionalChildPaths + # argument so we have to avoid using it. + $Path = Join-Path -Path $Path -ChildPath '.azure' + $Path = Join-Path -Path $Path -ChildPath $ChildPath + + return $Path +} +function Get-HelmValue { + [Microsoft.Azure.PowerShell.Cmdlets.ConnectedKubernetes.DoNotExportAttribute()] + param ( + [Parameter(Mandatory)] + [string]$HelmClientLocation, + [Parameter(Mandatory)] + [string]$Namespace, + [string]$KubeConfig, + [string]$KubeContext, + [string]$ValuesFile = 'userValues.txt' + ) + + try { + $userValuesLocation = Get-AzureHelmPath -ChildPath $ValuesFile + + $cmdHelmValuesPull = @($HelmClientLocation, "get", "values", "azure-arc", "--namespace", $ReleaseInstallNamespace) + if ($KubeConfig) { + $cmdHelmValuesPull += "--kubeconfig", $KubeConfig + } + if ($KubeContext) { + $cmdHelmValuesPull += "--kube-context", $KubeContext + } + + Write-Debug "Pull helm values: $cmdHelmValuesPull[0] $cmdValuesPull[1..($cmdHelmValuesPull.Count - 1)]" + Invoke-ExternalCommand $cmdHelmValuesPull[0] $cmdHelmValuesPull[1..($cmdHelmValuesPull.Count - 1)] > $userValuesLocation + } + catch { + throw "Unable to get helm values: `n$_" + } + return $userValuesLocation +} function Get-HelmChartPath { - [Microsoft.Azure.PowerShell.Cmdlets.ConnectedKubernetes.DoNotExport()] + [Microsoft.Azure.PowerShell.Cmdlets.ConnectedKubernetes.DoNotExportAttribute()] param ( [Parameter(Mandatory)] [string]$RegistryPath, @@ -140,19 +199,7 @@ function Get-HelmChartPath { # Special path! $PreOnboardingHelmChartsFolderName = 'PreOnboardingChecksCharts' - - # Exporting Helm chart; note that we might be one Windows or Linux. - if (Test-Path Env:USERPROFILE) { - $root = $Env:USERPROFILE - } - elseif (Test-Path Env:HOME) { - $root = $Env:HOME - } - else { - throw "No environment to use as root." - } - Write-Verbose "Using 'helm' to add Azure Arc resources to Kubernetes cluster" - $ChartExportPath = Join-Path -Path $root -ChildPath '.azure' -AdditionalChildPath $ChartFolderName + $ChartExportPath = Get-AzureHelmPath -ChildPath $ChartFolderName try { if (Test-Path $ChartExportPath) { Write-Debug "Cleaning up existing Helm chart folder at: $ChartExportPath" @@ -187,7 +234,7 @@ function Get-HelmChartPath { } function Get-HelmChart { - [Microsoft.Azure.PowerShell.Cmdlets.ConnectedKubernetes.DoNotExport()] + [Microsoft.Azure.PowerShell.Cmdlets.ConnectedKubernetes.DoNotExportAttribute()] param ( [Parameter(Mandatory)] [string]$RegistryPath, @@ -249,7 +296,7 @@ function Get-HelmChart { # This method exists to allow us to effectively Mock the call operator (&). # We cannnot do that directly so instead we have this wrapper, which we can mock! function Invoke-ExternalCommand { - [Microsoft.Azure.PowerShell.Cmdlets.ConnectedKubernetes.DoNotExport()] + [Microsoft.Azure.PowerShell.Cmdlets.ConnectedKubernetes.DoNotExportAttribute()] param ( [Parameter(Mandatory = $true)] [string]$Command, @@ -258,16 +305,13 @@ function Invoke-ExternalCommand { & $Command $Arguments } - -function Set-HelmRepositoryAndModules { +function Set-HelmModulesAndRepository { + [Microsoft.Azure.PowerShell.Cmdlets.ConnectedKubernetes.DoNotExportAttribute()] + [CmdletBinding(SupportsShouldProcess = $true)] param ( [string]$KubeConfig, [string]$KubeContext, - [string]$Location, - [string]$ProxyCert, - [bool]$DisableAutoUpgrade, - [string]$ContainerLogPath, - [string]$CustomLocationsOid + [string]$Location ) Write-Debug "Setting Helm repository and checking for required modules." if ((Test-Path Env:HELMREPONAME) -and (Test-Path Env:HELMREPOURL)) { @@ -325,11 +369,13 @@ function Set-HelmRepositoryAndModules { return } } - Set-Item -Path Env:HELM_EXPERIMENTAL_OCI -Value 1 + if ($PSCmdlet.ShouldProcess($Env:HEML_EXPERIMENAL_OCI)) { + Set-Item -Path Env:HELM_EXPERIMENTAL_OCI -Value 1 + } return $RegistryPath } -function Get-HelmReleaseNamespaces { +function Get-HelmReleaseNamespace { param ( [string]$KubeConfig, [string]$KubeContext diff --git a/src/ConnectedKubernetes/ConnectedKubernetes.Autorest/custom/helpers/RSAHelper.ps1 b/src/ConnectedKubernetes/ConnectedKubernetes.Autorest/custom/helpers/RSAHelper.ps1 index c49b33f74bcf..4ea21cbac3c6 100644 --- a/src/ConnectedKubernetes/ConnectedKubernetes.Autorest/custom/helpers/RSAHelper.ps1 +++ b/src/ConnectedKubernetes/ConnectedKubernetes.Autorest/custom/helpers/RSAHelper.ps1 @@ -1,13 +1,13 @@ -function ExportRSAPrivateKeyBase64{ +function ExportRSAPrivateKeyBase64 { [Microsoft.Azure.PowerShell.Cmdlets.ConnectedKubernetes.DoNotExportAttribute()] param( [Parameter(Mandatory)] [System.Security.Cryptography.RSA] $RSA ) - process{ + process { $RSAParams = $RSA.ExportParameters(1) - [byte]$Sequence = 0x30 + [byte]$Sequence = 0x30 [byte[]]$Version = (0x00) $stream = [System.IO.MemoryStream]::new() $writer = [System.IO.BinaryWriter]::new($stream) @@ -35,16 +35,16 @@ function ExportRSAPrivateKeyBase64{ } } -function ExportRSAPublicKeyBase64{ +function ExportRSAPublicKeyBase64 { [Microsoft.Azure.PowerShell.Cmdlets.ConnectedKubernetes.DoNotExportAttribute()] param( [Parameter(Mandatory)] [System.Security.Cryptography.RSA] $RSA ) - process{ + process { $RSAParams = $RSA.ExportParameters(0) - [byte]$Sequence = 0x30 + [byte]$Sequence = 0x30 $stream = [System.IO.MemoryStream]::new() $writer = [System.IO.BinaryWriter]::new($stream) $writer.Write($Sequence); @@ -56,28 +56,28 @@ function ExportRSAPublicKeyBase64{ $length = ([int]($innerStream.Length)) EncodeLength $writer $length $writer.Write($innerStream.GetBuffer(), 0, $length) - + $base64 = [Convert]::ToBase64String($stream.GetBuffer(), 0, ([int]($stream.Length))) return $base64 } } -function EncodeLength{ +function EncodeLength { [Microsoft.Azure.PowerShell.Cmdlets.ConnectedKubernetes.DoNotExportAttribute()] param( [System.IO.BinaryWriter]$stream, [int]$length ) - process{ + process { [byte]$bytex80 = 0x80 - if($length -lt 0){ + if ($length -lt 0) { throw "Length must be non-negative" } - if($length -lt $bytex80){ + if ($length -lt $bytex80) { $stream.Write(([byte]$length)) } - else{ + else { $temp = $length $bytesRequired = 0; while ($temp -gt 0) { @@ -97,33 +97,33 @@ function EncodeLength{ } } -function EncodeIntegerBigEndian{ +function EncodeIntegerBigEndian { [Microsoft.Azure.PowerShell.Cmdlets.ConnectedKubernetes.DoNotExportAttribute()] param( [System.IO.BinaryWriter]$stream, [byte[]]$value, [bool]$forceUnsigned = $true ) - process{ + process { [byte]$Integer = 0x02 $stream.Write($Integer); # INTEGER $prefixZeros = 0 for ($i = 0; $i -lt $value.Length; $i++) { - if ($value[$i] -ne 0){break} + if ($value[$i] -ne 0) { break } $prefixZeros++ } - if(($value.Length - $prefixZeros) -eq 0){ + if (($value.Length - $prefixZeros) -eq 0) { EncodeLength $stream 1 $stream.Write(([byte]0)) } - else{ + else { [byte]$newByte = 0x7f - if(($forceUnsigned) -AND ($value[$prefixZeros] -gt $newByte)){ - EncodeLength $stream ($value.Length - $prefixZeros +1) + if (($forceUnsigned) -AND ($value[$prefixZeros] -gt $newByte)) { + EncodeLength $stream ($value.Length - $prefixZeros + 1) $stream.Write(([byte]0)) } - else{ + else { EncodeLength $stream ($value.Length - $prefixZeros) } for ($i = $prefixZeros; $i -lt $value.Length; $i++) { diff --git a/src/ConnectedKubernetes/ConnectedKubernetes.Autorest/custom/helpers/UtilsHelper.ps1 b/src/ConnectedKubernetes/ConnectedKubernetes.Autorest/custom/helpers/UtilsHelper.ps1 index 7b6ced587914..fdd89f98d39e 100644 --- a/src/ConnectedKubernetes/ConnectedKubernetes.Autorest/custom/helpers/UtilsHelper.ps1 +++ b/src/ConnectedKubernetes/ConnectedKubernetes.Autorest/custom/helpers/UtilsHelper.ps1 @@ -44,7 +44,7 @@ function ConvertTo-ArcAgentryConfiguration { # This ensures that when a new feature is implemented, only the ConfigDP # needs to change and not the Powershell script (or az CLI). $arcAgentryConfigs = New-Object System.Collections.Generic.List[Microsoft.Azure.PowerShell.Cmdlets.ConnectedKubernetes.Models.Api20240715Preview.ArcAgentryConfigurations] - $combinedKeys = $ConfigurationSetting.Keys + $combinedKeys = $ConfigurationSetting.Keys } else { $arcAgentryConfigs = New-Object System.Collections.ArrayList @@ -57,7 +57,12 @@ function ConvertTo-ArcAgentryConfiguration { # Do not send protected settings to CCRP foreach ($feature in $combinedKeys) { - $settings = ($ConfigurationSetting.ContainsKey($feature) ? $ConfigurationSetting[$feature] : @{}) + if ($ConfigurationSetting.ContainsKey($feature)) { + $settings = $ConfigurationSetting[$feature] + } + else { + $settings = @{} + } if ($CCRP) { $ArcAgentryConfiguration = [Microsoft.Azure.PowerShell.Cmdlets.ConnectedKubernetes.Models.Api20240715Preview.ArcAgentryConfigurations]@{ Feature = $feature @@ -65,7 +70,12 @@ function ConvertTo-ArcAgentryConfiguration { } } else { - $protectedSettings = ($RedactedProtectedConfiguration.ContainsKey($feature) ? $RedactedProtectedConfiguration[$feature] : @{}) + if ($RedactedProtectedConfiguration.ContainsKey($feature)) { + $protectedSettings = $RedactedProtectedConfiguration[$feature] + } + else { + $protectedSettings = @{} + } $ArcAgentryConfiguration = @{ Feature = $feature Settings = $settings @@ -103,4 +113,35 @@ function Convert-ProxySetting { Write-Error "Variable $name does not exist" -ErrorAction SilentlyContinue } return $ConfigurationProtectedSetting -} \ No newline at end of file +} + +# This function exists because in Powershell 5.1 there is no -AsHashTable +# argument available for ConvertFrom-Json. +function ConvertTo-HashTable { + param( + [PSCustomObject]$object + ) + $HashTable = @{} + foreach ($property in $object.psobject.properties) { + $Value = $property.Value + $Key = $property.Name + if ($Value -is [System.Management.Automation.PSCustomObject]) { + $HashTable[$Key] = ConvertTo-HashTable $Value + } + elseif ($Value -is [System.Array]) { + $AnArray = @() + foreach ($Element in $Value) { + $AnArray += ConvertTo-HashTable $Element + } + $HashTable[$Key] = $AnArray + } + elseif ($Value -is [Hashtable]) { + $HashTable[$Key] = $Value + } + else { + $HashTable[$Key] = $Value + } + } + $HashTable +} + diff --git a/src/ConnectedKubernetes/ConnectedKubernetes.Autorest/examples/Set-AzConnectedKubernetes.md b/src/ConnectedKubernetes/ConnectedKubernetes.Autorest/examples/Set-AzConnectedKubernetes.md index 05f2cf83ee5b..976afe73709d 100644 --- a/src/ConnectedKubernetes/ConnectedKubernetes.Autorest/examples/Set-AzConnectedKubernetes.md +++ b/src/ConnectedKubernetes/ConnectedKubernetes.Autorest/examples/Set-AzConnectedKubernetes.md @@ -1,4 +1,4 @@ -### Example 1: Disable gateway feature of a connected kubernetes. +### Example 1: Disable gateway for a connected Kubernetes cluster ```powershell Set-AzConnectedKubernetes -ClusterName azps_test_cluster -ResourceGroupName azps_test_group -Location eastus -DisableGateway ``` @@ -9,11 +9,11 @@ Location Name ResourceGroupName eastus azps_test_cluster azps_test_group ``` -This command disable gateway feature of a connected kubernetes. +This command disable gateway feature of a connected kubernete cluster. -### Example 2: Enable gateway feature of connected kubernetes. +### Example 2: Enable gateway for a connected Kubernetes cluster ```powershell -Set-AzConnectedKubernetes -ClusterName azps_test_cluster -ResourceGroupName azps_test_group -Location eastus -GatewayResourceId gatewayResourceId +Set-AzConnectedKubernetes -ClusterName azps_test_cluster -ResourceGroupName azps_test_group -Location eastus -GatewayResourceId $gatewayResourceId ``` @@ -23,5 +23,71 @@ Location Name ResourceGroupName eastus azps_test_cluster azps_test_group ``` -This command disable gateway feature of a connected kubernetes. +This command enables gateway feature of a connected kubernetes cluster. +### Example 3: Enable gateway for a connected Kubernetes cluster with InputObject +```powershell +# Get an existing cluster first +$inputObject = Get-AzConnectedKubernetes -ClusterName azps_test_cluster -ResourceGroupName azps_test_group -SubscriptionId $subscriptionId +# Enable gateway and set gateway resource Id +$inputObject.GatewayEnabled=$true +$inputObject.GatewayResourceId=$gatewayResourceId +Set-AzConnectedKubernetes -InputObject $inputObject + +``` + +```output +Location Name ResourceGroupName +-------- ---- ----------------- +eastus azps_test_cluster azps_test_group +``` + +This command enables gateway feature of a connected kubernetes cluster. + +### Example 4: Enable workload identity of a connected kubernetes cluster with InputObject +```powershell +# Get an existing cluster first +$inputObject = Get-AzConnectedKubernetes -ClusterName azps_test_cluster -ResourceGroupName azps_test_group -SubscriptionId $subscriptionId +# Enable workload identity and OIDC issuer profile +$inputObject.WorkloadIdentityEnabled=$true +$inputObject.OidcIssuerProfileEnabled=$true +Set-AzConnectedKubernetes -InputObject $inputObject +``` + +```output +Location Name ResourceGroupName +-------- ---- ----------------- +eastus azps_test_cluster azps_test_group +``` + +This command enables workload identity and OIDC Issuer Profile for a connected Kubernetes cluster + +### Example 5: Disable workload identity of a connected kubernetes cluster with InputOjbect +```powershell +# Get an existing cluster first +$inputObject = Get-AzConnectedKubernetes -ClusterName azps_test_cluster -ResourceGroupName azps_test_group -SubscriptionId $subscriptionId +# Disable workload identity +$inputObject.WorkloadIdentityEnabled=$falue +Set-AzConnectedKubernetes -InputObject $inputObject +``` + +```output +Location Name ResourceGroupName +-------- ---- ----------------- +eastus azps_test_cluster azps_test_group +``` + +This command disables workload identity of a connected kubernetes cluster + +### Example 6: Disable workload identity of a connected kubernetes cluster +```powershell +Get-AzConnectedKubernetes -ClusterName azps_test_cluster -ResourceGroupName azps_test_group -SubscriptionId $subscriptionId | Set-AzConnectedKubernetes -WorkloadIdentityEnabled:$false +``` + +```output +Location Name ResourceGroupName +-------- ---- ----------------- +eastus azps_test_cluster azps_test_group +``` + +This command disables workload identity of a connected kubernetes cluster \ No newline at end of file diff --git a/src/ConnectedKubernetes/ConnectedKubernetes.Autorest/exports/ProxyCmdletDefinitions.ps1 b/src/ConnectedKubernetes/ConnectedKubernetes.Autorest/exports/ProxyCmdletDefinitions.ps1 index 92a9a34fbac7..0713b3726ac9 100644 --- a/src/ConnectedKubernetes/ConnectedKubernetes.Autorest/exports/ProxyCmdletDefinitions.ps1 +++ b/src/ConnectedKubernetes/ConnectedKubernetes.Autorest/exports/ProxyCmdletDefinitions.ps1 @@ -1017,13 +1017,39 @@ end { .Synopsis API to set properties of the connected cluster resource .Description -API to set properties of the connected cluster resource +API to set properties of the connected cluster resource. +Replaces all configuration of an existing connected cluster; any properties not specified will be reset to their default values. .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 -GatewayResourceId gatewayResourceId +Set-AzConnectedKubernetes -ClusterName azps_test_cluster -ResourceGroupName azps_test_group -Location eastus -GatewayResourceId $gatewayResourceId + +.Example +# Get an existing cluster first +$inputObject = Get-AzConnectedKubernetes -ClusterName azps_test_cluster -ResourceGroupName azps_test_group -SubscriptionId $subscriptionId +# Enable gateway and set gateway resource Id +$inputObject.GatewayEnabled=$true +$inputObject.GatewayResourceId=$gatewayResourceId +Set-AzConnectedKubernetes -InputObject $inputObject +.Example +# Get an existing cluster first +$inputObject = Get-AzConnectedKubernetes -ClusterName azps_test_cluster -ResourceGroupName azps_test_group -SubscriptionId $subscriptionId +# Enable workload identity and OIDC issuer profile +$inputObject.WorkloadIdentityEnabled=$true +$inputObject.OidcIssuerProfileEnabled=$true +Set-AzConnectedKubernetes -InputObject $inputObject +.Example +# Get an existing cluster first +$inputObject = Get-AzConnectedKubernetes -ClusterName azps_test_cluster -ResourceGroupName azps_test_group -SubscriptionId $subscriptionId +# Disable workload identity +$inputObject.WorkloadIdentityEnabled=$falue +Set-AzConnectedKubernetes -InputObject $inputObject +.Example +Get-AzConnectedKubernetes -ClusterName azps_test_cluster -ResourceGroupName azps_test_group -SubscriptionId $subscriptionId | Set-AzConnectedKubernetes -WorkloadIdentityEnabled:$false +.Inputs +Microsoft.Azure.PowerShell.Cmdlets.ConnectedKubernetes.Models.Api20240715Preview.IConnectedCluster .Outputs Microsoft.Azure.PowerShell.Cmdlets.ConnectedKubernetes.Models.Api20240715Preview.IConnectedCluster .Notes @@ -1080,6 +1106,7 @@ function Set-AzConnectedKubernetes { [CmdletBinding(DefaultParameterSetName='SetExpanded', PositionalBinding=$false, SupportsShouldProcess, ConfirmImpact='Medium')] param( [Parameter(ParameterSetName='SetExpanded', Mandatory)] + [Parameter(ParameterSetName='SetExpandedEnableGateway', Mandatory)] [Parameter(ParameterSetName='SetExpandedDisableGateway', Mandatory)] [Alias('Name')] [Microsoft.Azure.PowerShell.Cmdlets.ConnectedKubernetes.Category('Path')] @@ -1088,6 +1115,7 @@ param( ${ClusterName}, [Parameter(ParameterSetName='SetExpanded', Mandatory)] + [Parameter(ParameterSetName='SetExpandedEnableGateway', Mandatory)] [Parameter(ParameterSetName='SetExpandedDisableGateway', Mandatory)] [Microsoft.Azure.PowerShell.Cmdlets.ConnectedKubernetes.Category('Path')] [System.String] @@ -1139,6 +1167,7 @@ param( ${ContainerLogPath}, [Parameter(ParameterSetName='SetExpanded', Mandatory)] + [Parameter(ParameterSetName='SetExpandedEnableGateway', Mandatory)] [Parameter(ParameterSetName='SetExpandedDisableGateway', Mandatory)] [Microsoft.Azure.PowerShell.Cmdlets.ConnectedKubernetes.Category('Body')] [System.String] @@ -1230,7 +1259,7 @@ param( [Parameter()] [Microsoft.Azure.PowerShell.Cmdlets.ConnectedKubernetes.Category('Body')] [System.Management.Automation.SwitchParameter] - # Whether to enable or disable the workload identity Webhook + # Enable the workload identity Webhook ${WorkloadIdentityEnabled}, [Parameter()] @@ -1251,7 +1280,8 @@ param( # Arc Agentry System Protected Configuration ${ConfigurationProtectedSetting}, - [Parameter()] + [Parameter(ParameterSetName='SetExpandedEnableGateway', Mandatory)] + [Parameter(ParameterSetName='SetEnableGateway', Mandatory)] [Microsoft.Azure.PowerShell.Cmdlets.ConnectedKubernetes.Category('Body')] [System.String] # Arc Gateway resource Id, providing this will enable the gateway @@ -1263,8 +1293,9 @@ param( [System.Management.Automation.SwitchParameter] ${DisableGateway}, - [Parameter(ParameterSetName='SetDisableGateway', Mandatory)] - [Parameter(ParameterSetName='Set', Mandatory)] + [Parameter(ParameterSetName='SetEnableGateway', Mandatory, ValueFromPipeline)] + [Parameter(ParameterSetName='SetDisableGateway', Mandatory, ValueFromPipeline)] + [Parameter(ParameterSetName='Set', Mandatory, ValueFromPipeline)] [Microsoft.Azure.PowerShell.Cmdlets.ConnectedKubernetes.Category('Body')] [Microsoft.Azure.PowerShell.Cmdlets.ConnectedKubernetes.Models.Api20240715Preview.IConnectedCluster] # To construct, see NOTES section for INPUTOBJECT properties and create a hash table. @@ -1357,11 +1388,13 @@ begin { $mapping = @{ SetExpanded = 'Az.ConnectedKubernetes.custom\Set-AzConnectedKubernetes'; + SetExpandedEnableGateway = 'Az.ConnectedKubernetes.custom\Set-AzConnectedKubernetes'; SetExpandedDisableGateway = 'Az.ConnectedKubernetes.custom\Set-AzConnectedKubernetes'; + SetEnableGateway = 'Az.ConnectedKubernetes.custom\Set-AzConnectedKubernetes'; SetDisableGateway = 'Az.ConnectedKubernetes.custom\Set-AzConnectedKubernetes'; Set = 'Az.ConnectedKubernetes.custom\Set-AzConnectedKubernetes'; } - if (('SetExpanded', 'SetExpandedDisableGateway', 'SetDisableGateway', 'Set') -contains $parameterSet -and -not $PSBoundParameters.ContainsKey('SubscriptionId')) { + if (('SetExpanded', 'SetExpandedEnableGateway', 'SetExpandedDisableGateway', 'SetEnableGateway', '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) { diff --git a/src/ConnectedKubernetes/ConnectedKubernetes.Autorest/exports/Set-AzConnectedKubernetes.ps1 b/src/ConnectedKubernetes/ConnectedKubernetes.Autorest/exports/Set-AzConnectedKubernetes.ps1 index 7406b104aed9..b9df301da669 100644 --- a/src/ConnectedKubernetes/ConnectedKubernetes.Autorest/exports/Set-AzConnectedKubernetes.ps1 +++ b/src/ConnectedKubernetes/ConnectedKubernetes.Autorest/exports/Set-AzConnectedKubernetes.ps1 @@ -18,13 +18,39 @@ .Synopsis API to set properties of the connected cluster resource .Description -API to set properties of the connected cluster resource +API to set properties of the connected cluster resource. +Replaces all configuration of an existing connected cluster; any properties not specified will be reset to their default values. .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 -GatewayResourceId gatewayResourceId +Set-AzConnectedKubernetes -ClusterName azps_test_cluster -ResourceGroupName azps_test_group -Location eastus -GatewayResourceId $gatewayResourceId +.Example +# Get an existing cluster first +$inputObject = Get-AzConnectedKubernetes -ClusterName azps_test_cluster -ResourceGroupName azps_test_group -SubscriptionId $subscriptionId +# Enable gateway and set gateway resource Id +$inputObject.GatewayEnabled=$true +$inputObject.GatewayResourceId=$gatewayResourceId +Set-AzConnectedKubernetes -InputObject $inputObject +.Example +# Get an existing cluster first +$inputObject = Get-AzConnectedKubernetes -ClusterName azps_test_cluster -ResourceGroupName azps_test_group -SubscriptionId $subscriptionId +# Enable workload identity and OIDC issuer profile +$inputObject.WorkloadIdentityEnabled=$true +$inputObject.OidcIssuerProfileEnabled=$true +Set-AzConnectedKubernetes -InputObject $inputObject +.Example +# Get an existing cluster first +$inputObject = Get-AzConnectedKubernetes -ClusterName azps_test_cluster -ResourceGroupName azps_test_group -SubscriptionId $subscriptionId +# Disable workload identity +$inputObject.WorkloadIdentityEnabled=$falue +Set-AzConnectedKubernetes -InputObject $inputObject +.Example +Get-AzConnectedKubernetes -ClusterName azps_test_cluster -ResourceGroupName azps_test_group -SubscriptionId $subscriptionId | Set-AzConnectedKubernetes -WorkloadIdentityEnabled:$false + +.Inputs +Microsoft.Azure.PowerShell.Cmdlets.ConnectedKubernetes.Models.Api20240715Preview.IConnectedCluster .Outputs Microsoft.Azure.PowerShell.Cmdlets.ConnectedKubernetes.Models.Api20240715Preview.IConnectedCluster .Notes @@ -81,6 +107,7 @@ function Set-AzConnectedKubernetes { [CmdletBinding(DefaultParameterSetName='SetExpanded', PositionalBinding=$false, SupportsShouldProcess, ConfirmImpact='Medium')] param( [Parameter(ParameterSetName='SetExpanded', Mandatory)] + [Parameter(ParameterSetName='SetExpandedEnableGateway', Mandatory)] [Parameter(ParameterSetName='SetExpandedDisableGateway', Mandatory)] [Alias('Name')] [Microsoft.Azure.PowerShell.Cmdlets.ConnectedKubernetes.Category('Path')] @@ -89,6 +116,7 @@ param( ${ClusterName}, [Parameter(ParameterSetName='SetExpanded', Mandatory)] + [Parameter(ParameterSetName='SetExpandedEnableGateway', Mandatory)] [Parameter(ParameterSetName='SetExpandedDisableGateway', Mandatory)] [Microsoft.Azure.PowerShell.Cmdlets.ConnectedKubernetes.Category('Path')] [System.String] @@ -140,6 +168,7 @@ param( ${ContainerLogPath}, [Parameter(ParameterSetName='SetExpanded', Mandatory)] + [Parameter(ParameterSetName='SetExpandedEnableGateway', Mandatory)] [Parameter(ParameterSetName='SetExpandedDisableGateway', Mandatory)] [Microsoft.Azure.PowerShell.Cmdlets.ConnectedKubernetes.Category('Body')] [System.String] @@ -231,7 +260,7 @@ param( [Parameter()] [Microsoft.Azure.PowerShell.Cmdlets.ConnectedKubernetes.Category('Body')] [System.Management.Automation.SwitchParameter] - # Whether to enable or disable the workload identity Webhook + # Enable the workload identity Webhook ${WorkloadIdentityEnabled}, [Parameter()] @@ -252,7 +281,8 @@ param( # Arc Agentry System Protected Configuration ${ConfigurationProtectedSetting}, - [Parameter()] + [Parameter(ParameterSetName='SetExpandedEnableGateway', Mandatory)] + [Parameter(ParameterSetName='SetEnableGateway', Mandatory)] [Microsoft.Azure.PowerShell.Cmdlets.ConnectedKubernetes.Category('Body')] [System.String] # Arc Gateway resource Id, providing this will enable the gateway @@ -264,8 +294,9 @@ param( [System.Management.Automation.SwitchParameter] ${DisableGateway}, - [Parameter(ParameterSetName='SetDisableGateway', Mandatory)] - [Parameter(ParameterSetName='Set', Mandatory)] + [Parameter(ParameterSetName='SetEnableGateway', Mandatory, ValueFromPipeline)] + [Parameter(ParameterSetName='SetDisableGateway', Mandatory, ValueFromPipeline)] + [Parameter(ParameterSetName='Set', Mandatory, ValueFromPipeline)] [Microsoft.Azure.PowerShell.Cmdlets.ConnectedKubernetes.Category('Body')] [Microsoft.Azure.PowerShell.Cmdlets.ConnectedKubernetes.Models.Api20240715Preview.IConnectedCluster] # To construct, see NOTES section for INPUTOBJECT properties and create a hash table. @@ -358,11 +389,13 @@ begin { $mapping = @{ SetExpanded = 'Az.ConnectedKubernetes.custom\Set-AzConnectedKubernetes'; + SetExpandedEnableGateway = 'Az.ConnectedKubernetes.custom\Set-AzConnectedKubernetes'; SetExpandedDisableGateway = 'Az.ConnectedKubernetes.custom\Set-AzConnectedKubernetes'; + SetEnableGateway = 'Az.ConnectedKubernetes.custom\Set-AzConnectedKubernetes'; SetDisableGateway = 'Az.ConnectedKubernetes.custom\Set-AzConnectedKubernetes'; Set = 'Az.ConnectedKubernetes.custom\Set-AzConnectedKubernetes'; } - if (('SetExpanded', 'SetExpandedDisableGateway', 'SetDisableGateway', 'Set') -contains $parameterSet -and -not $PSBoundParameters.ContainsKey('SubscriptionId')) { + if (('SetExpanded', 'SetExpandedEnableGateway', 'SetExpandedDisableGateway', 'SetEnableGateway', '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) { diff --git a/src/ConnectedKubernetes/ConnectedKubernetes.Autorest/help/Az.ConnectedKubernetes.md b/src/ConnectedKubernetes/ConnectedKubernetes.Autorest/help/Az.ConnectedKubernetes.md index 99f7d0920833..95cdb2819574 100644 --- a/src/ConnectedKubernetes/ConnectedKubernetes.Autorest/help/Az.ConnectedKubernetes.md +++ b/src/ConnectedKubernetes/ConnectedKubernetes.Autorest/help/Az.ConnectedKubernetes.md @@ -1,6 +1,6 @@ --- Module Name: Az.ConnectedKubernetes -Module Guid: d3467834-8989-4142-8c05-ab93c4bfa6eb +Module Guid: efbb1325-5081-4947-8508-ab47abbf6e76 Download Help Link: https://learn.microsoft.com/powershell/module/az.connectedkubernetes Help Version: 1.0.0.0 Locale: en-US diff --git a/src/ConnectedKubernetes/ConnectedKubernetes.Autorest/help/Set-AzConnectedKubernetes.md b/src/ConnectedKubernetes/ConnectedKubernetes.Autorest/help/Set-AzConnectedKubernetes.md index 69e4c597ed4d..1146bdcf0a68 100644 --- a/src/ConnectedKubernetes/ConnectedKubernetes.Autorest/help/Set-AzConnectedKubernetes.md +++ b/src/ConnectedKubernetes/ConnectedKubernetes.Autorest/help/Set-AzConnectedKubernetes.md @@ -19,11 +19,11 @@ Set-AzConnectedKubernetes -ClusterName -ResourceGroupName -Loc [-ProxyCert ] [-SubscriptionId ] [-AcceptEULA] [-AzureHybridBenefit ] [-ConfigurationProtectedSetting ] [-ConfigurationSetting ] [-CustomLocationsOid ] [-Distribution ] [-DistributionVersion ] - [-GatewayResourceId ] [-Infrastructure ] [-KubeConfig ] [-KubeContext ] - [-OidcIssuerProfileEnabled] [-OidcIssuerProfileSelfHostedIssuerUrl ] - [-PrivateLinkScopeResourceId ] [-PrivateLinkState ] - [-ProvisioningState ] [-Tag ] [-WorkloadIdentityEnabled] - [-DefaultProfile ] [-AsJob] [-NoWait] [-Confirm] [-WhatIf] [] + [-Infrastructure ] [-KubeConfig ] [-KubeContext ] [-OidcIssuerProfileEnabled] + [-OidcIssuerProfileSelfHostedIssuerUrl ] [-PrivateLinkScopeResourceId ] + [-PrivateLinkState ] [-ProvisioningState ] [-Tag ] + [-WorkloadIdentityEnabled] [-DefaultProfile ] [-AsJob] [-NoWait] [-Confirm] [-WhatIf] + [] ``` ### Set @@ -32,12 +32,11 @@ Set-AzConnectedKubernetes -InputObject [-ContainerLogPath ] [-HttpsProxy ] [-NoProxy ] [-ProxyCert ] [-SubscriptionId ] [-AcceptEULA] [-AzureHybridBenefit ] [-ConfigurationProtectedSetting ] [-ConfigurationSetting ] [-CustomLocationsOid ] [-Distribution ] - [-DistributionVersion ] [-GatewayResourceId ] [-Infrastructure ] - [-KubeConfig ] [-KubeContext ] [-OidcIssuerProfileEnabled] - [-OidcIssuerProfileSelfHostedIssuerUrl ] [-PrivateLinkScopeResourceId ] - [-PrivateLinkState ] [-ProvisioningState ] [-Tag ] - [-WorkloadIdentityEnabled] [-DefaultProfile ] [-AsJob] [-NoWait] [-Confirm] [-WhatIf] - [] + [-DistributionVersion ] [-Infrastructure ] [-KubeConfig ] [-KubeContext ] + [-OidcIssuerProfileEnabled] [-OidcIssuerProfileSelfHostedIssuerUrl ] + [-PrivateLinkScopeResourceId ] [-PrivateLinkState ] + [-ProvisioningState ] [-Tag ] [-WorkloadIdentityEnabled] + [-DefaultProfile ] [-AsJob] [-NoWait] [-Confirm] [-WhatIf] [] ``` ### SetDisableGateway @@ -47,11 +46,25 @@ Set-AzConnectedKubernetes -DisableGateway -InputObject [-Con [-SubscriptionId ] [-AcceptEULA] [-AzureHybridBenefit ] [-ConfigurationProtectedSetting ] [-ConfigurationSetting ] [-CustomLocationsOid ] [-Distribution ] [-DistributionVersion ] - [-GatewayResourceId ] [-Infrastructure ] [-KubeConfig ] [-KubeContext ] - [-OidcIssuerProfileEnabled] [-OidcIssuerProfileSelfHostedIssuerUrl ] - [-PrivateLinkScopeResourceId ] [-PrivateLinkState ] - [-ProvisioningState ] [-Tag ] [-WorkloadIdentityEnabled] - [-DefaultProfile ] [-AsJob] [-NoWait] [-Confirm] [-WhatIf] [] + [-Infrastructure ] [-KubeConfig ] [-KubeContext ] [-OidcIssuerProfileEnabled] + [-OidcIssuerProfileSelfHostedIssuerUrl ] [-PrivateLinkScopeResourceId ] + [-PrivateLinkState ] [-ProvisioningState ] [-Tag ] + [-WorkloadIdentityEnabled] [-DefaultProfile ] [-AsJob] [-NoWait] [-Confirm] [-WhatIf] + [] +``` + +### SetEnableGateway +``` +Set-AzConnectedKubernetes -GatewayResourceId -InputObject + [-ContainerLogPath ] [-DisableAutoUpgrade] [-HttpProxy ] [-HttpsProxy ] [-NoProxy ] + [-ProxyCert ] [-SubscriptionId ] [-AcceptEULA] [-AzureHybridBenefit ] + [-ConfigurationProtectedSetting ] [-ConfigurationSetting ] + [-CustomLocationsOid ] [-Distribution ] [-DistributionVersion ] + [-Infrastructure ] [-KubeConfig ] [-KubeContext ] [-OidcIssuerProfileEnabled] + [-OidcIssuerProfileSelfHostedIssuerUrl ] [-PrivateLinkScopeResourceId ] + [-PrivateLinkState ] [-ProvisioningState ] [-Tag ] + [-WorkloadIdentityEnabled] [-DefaultProfile ] [-AsJob] [-NoWait] [-Confirm] [-WhatIf] + [] ``` ### SetExpandedDisableGateway @@ -61,7 +74,21 @@ Set-AzConnectedKubernetes -ClusterName -ResourceGroupName -Dis [-ProxyCert ] [-SubscriptionId ] [-AcceptEULA] [-AzureHybridBenefit ] [-ConfigurationProtectedSetting ] [-ConfigurationSetting ] [-CustomLocationsOid ] [-Distribution ] [-DistributionVersion ] - [-GatewayResourceId ] [-Infrastructure ] [-KubeConfig ] [-KubeContext ] + [-Infrastructure ] [-KubeConfig ] [-KubeContext ] [-OidcIssuerProfileEnabled] + [-OidcIssuerProfileSelfHostedIssuerUrl ] [-PrivateLinkScopeResourceId ] + [-PrivateLinkState ] [-ProvisioningState ] [-Tag ] + [-WorkloadIdentityEnabled] [-DefaultProfile ] [-AsJob] [-NoWait] [-Confirm] [-WhatIf] + [] +``` + +### SetExpandedEnableGateway +``` +Set-AzConnectedKubernetes -ClusterName -ResourceGroupName -GatewayResourceId + -Location [-ContainerLogPath ] [-DisableAutoUpgrade] [-HttpProxy ] [-HttpsProxy ] + [-NoProxy ] [-ProxyCert ] [-SubscriptionId ] [-AcceptEULA] + [-AzureHybridBenefit ] [-ConfigurationProtectedSetting ] + [-ConfigurationSetting ] [-CustomLocationsOid ] [-Distribution ] + [-DistributionVersion ] [-Infrastructure ] [-KubeConfig ] [-KubeContext ] [-OidcIssuerProfileEnabled] [-OidcIssuerProfileSelfHostedIssuerUrl ] [-PrivateLinkScopeResourceId ] [-PrivateLinkState ] [-ProvisioningState ] [-Tag ] [-WorkloadIdentityEnabled] @@ -69,11 +96,12 @@ Set-AzConnectedKubernetes -ClusterName -ResourceGroupName -Dis ``` ## DESCRIPTION -API to set properties of the connected cluster resource +API to set properties of the connected cluster resource. +Replaces all configuration of an existing connected cluster; any properties not specified will be reset to their default values. ## EXAMPLES -### Example 1: Disable gateway feature of a connected kubernetes. +### Example 1: Disable gateway for a connected Kubernetes cluster ```powershell Set-AzConnectedKubernetes -ClusterName azps_test_cluster -ResourceGroupName azps_test_group -Location eastus -DisableGateway ``` @@ -84,11 +112,11 @@ Location Name ResourceGroupName eastus azps_test_cluster azps_test_group ``` -This command disable gateway feature of a connected kubernetes. +This command disable gateway feature of a connected kubernete cluster. -### Example 2: Enable gateway feature of connected kubernetes. +### Example 2: Enable gateway for a connected Kubernetes cluster ```powershell -Set-AzConnectedKubernetes -ClusterName azps_test_cluster -ResourceGroupName azps_test_group -Location eastus -GatewayResourceId gatewayResourceId +Set-AzConnectedKubernetes -ClusterName azps_test_cluster -ResourceGroupName azps_test_group -Location eastus -GatewayResourceId $gatewayResourceId ``` @@ -98,7 +126,74 @@ Location Name ResourceGroupName eastus azps_test_cluster azps_test_group ``` -This command disable gateway feature of a connected kubernetes. +This command enables gateway feature of a connected kubernetes cluster. + +### Example 3: Enable gateway for a connected Kubernetes cluster with InputObject +```powershell +# Get an existing cluster first +$inputObject = Get-AzConnectedKubernetes -ClusterName azps_test_cluster -ResourceGroupName azps_test_group -SubscriptionId $subscriptionId +# Enable gateway and set gateway resource Id +$inputObject.GatewayEnabled=$true +$inputObject.GatewayResourceId=$gatewayResourceId +Set-AzConnectedKubernetes -InputObject $inputObject + +``` + +```output +Location Name ResourceGroupName +-------- ---- ----------------- +eastus azps_test_cluster azps_test_group +``` + +This command enables gateway feature of a connected kubernetes cluster. + +### Example 4: Enable workload identity of a connected kubernetes cluster with InputObject +```powershell +# Get an existing cluster first +$inputObject = Get-AzConnectedKubernetes -ClusterName azps_test_cluster -ResourceGroupName azps_test_group -SubscriptionId $subscriptionId +# Enable workload identity and OIDC issuer profile +$inputObject.WorkloadIdentityEnabled=$true +$inputObject.OidcIssuerProfileEnabled=$true +Set-AzConnectedKubernetes -InputObject $inputObject +``` + +```output +Location Name ResourceGroupName +-------- ---- ----------------- +eastus azps_test_cluster azps_test_group +``` + +This command enables workload identity and OIDC Issuer Profile for a connected Kubernetes cluster + +### Example 5: Disable workload identity of a connected kubernetes cluster with InputOjbect +```powershell +# Get an existing cluster first +$inputObject = Get-AzConnectedKubernetes -ClusterName azps_test_cluster -ResourceGroupName azps_test_group -SubscriptionId $subscriptionId +# Disable workload identity +$inputObject.WorkloadIdentityEnabled=$falue +Set-AzConnectedKubernetes -InputObject $inputObject +``` + +```output +Location Name ResourceGroupName +-------- ---- ----------------- +eastus azps_test_cluster azps_test_group +``` + +This command disables workload identity of a connected kubernetes cluster + +### Example 6: Disable workload identity of a connected kubernetes cluster +```powershell +Get-AzConnectedKubernetes -ClusterName azps_test_cluster -ResourceGroupName azps_test_group -SubscriptionId $subscriptionId | Set-AzConnectedKubernetes -WorkloadIdentityEnabled:$false +``` + +```output +Location Name ResourceGroupName +-------- ---- ----------------- +eastus azps_test_cluster azps_test_group +``` + +This command disables workload identity of a connected kubernetes cluster ## PARAMETERS @@ -152,7 +247,7 @@ The name of the Kubernetes cluster on which get is called. ```yaml Type: System.String -Parameter Sets: SetExpanded, SetExpandedDisableGateway +Parameter Sets: SetExpanded, SetExpandedDisableGateway, SetExpandedEnableGateway Aliases: Name Required: True @@ -302,10 +397,10 @@ Arc Gateway resource Id, providing this will enable the gateway ```yaml Type: System.String -Parameter Sets: (All) +Parameter Sets: SetEnableGateway, SetExpandedEnableGateway Aliases: -Required: False +Required: True Position: Named Default value: None Accept pipeline input: False @@ -362,13 +457,13 @@ To construct, see NOTES section for INPUTOBJECT properties and create a hash tab ```yaml Type: Microsoft.Azure.PowerShell.Cmdlets.ConnectedKubernetes.Models.Api20240715Preview.IConnectedCluster -Parameter Sets: Set, SetDisableGateway +Parameter Sets: Set, SetDisableGateway, SetEnableGateway Aliases: Required: True Position: Named Default value: None -Accept pipeline input: False +Accept pipeline input: True (ByValue) Accept wildcard characters: False ``` @@ -407,7 +502,7 @@ The geo-location where the resource lives ```yaml Type: System.String -Parameter Sets: SetExpanded, SetExpandedDisableGateway +Parameter Sets: SetExpanded, SetExpandedDisableGateway, SetExpandedEnableGateway Aliases: Required: True @@ -543,7 +638,7 @@ The name is case insensitive. ```yaml Type: System.String -Parameter Sets: SetExpanded, SetExpandedDisableGateway +Parameter Sets: SetExpanded, SetExpandedDisableGateway, SetExpandedEnableGateway Aliases: Required: True @@ -584,7 +679,7 @@ Accept wildcard characters: False ``` ### -WorkloadIdentityEnabled -Whether to enable or disable the workload identity Webhook +Enable the workload identity Webhook ```yaml Type: System.Management.Automation.SwitchParameter @@ -634,6 +729,8 @@ This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable ## INPUTS +### Microsoft.Azure.PowerShell.Cmdlets.ConnectedKubernetes.Models.Api20240715Preview.IConnectedCluster + ## OUTPUTS ### Microsoft.Azure.PowerShell.Cmdlets.ConnectedKubernetes.Models.Api20240715Preview.IConnectedCluster diff --git a/src/ConnectedKubernetes/ConnectedKubernetes.Autorest/internal/ProxyCmdletDefinitions.ps1 b/src/ConnectedKubernetes/ConnectedKubernetes.Autorest/internal/ProxyCmdletDefinitions.ps1 index 40278654d757..39b5e74f4b76 100644 --- a/src/ConnectedKubernetes/ConnectedKubernetes.Autorest/internal/ProxyCmdletDefinitions.ps1 +++ b/src/ConnectedKubernetes/ConnectedKubernetes.Autorest/internal/ProxyCmdletDefinitions.ps1 @@ -660,8 +660,31 @@ API to register a new Kubernetes cluster and create a tracked resource in Azure .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 -GatewayResourceId gatewayResourceId +Set-AzConnectedKubernetes -ClusterName azps_test_cluster -ResourceGroupName azps_test_group -Location eastus -GatewayResourceId $gatewayResourceId +.Example +# Get an existing cluster first +$inputObject = Get-AzConnectedKubernetes -ClusterName azps_test_cluster -ResourceGroupName azps_test_group -SubscriptionId $subscriptionId +# Enable gateway and set gateway resource Id +$inputObject.GatewayEnabled=$true +$inputObject.GatewayResourceId=$gatewayResourceId +Set-AzConnectedKubernetes -InputObject $inputObject + +.Example +# Get an existing cluster first +$inputObject = Get-AzConnectedKubernetes -ClusterName azps_test_cluster -ResourceGroupName azps_test_group -SubscriptionId $subscriptionId +# Enable workload identity and OIDC issuer profile +$inputObject.WorkloadIdentityEnabled=$true +$inputObject.OidcIssuerProfileEnabled=$true +Set-AzConnectedKubernetes -InputObject $inputObject +.Example +# Get an existing cluster first +$inputObject = Get-AzConnectedKubernetes -ClusterName azps_test_cluster -ResourceGroupName azps_test_group -SubscriptionId $subscriptionId +# Disable workload identity +$inputObject.WorkloadIdentityEnabled=$falue +Set-AzConnectedKubernetes -InputObject $inputObject +.Example +Get-AzConnectedKubernetes -ClusterName azps_test_cluster -ResourceGroupName azps_test_group -SubscriptionId $subscriptionId | Set-AzConnectedKubernetes -WorkloadIdentityEnabled:$false .Outputs Microsoft.Azure.PowerShell.Cmdlets.ConnectedKubernetes.Models.Api20240715Preview.IConnectedCluster diff --git a/src/ConnectedKubernetes/ConnectedKubernetes.Autorest/internal/Set-AzConnectedKubernetes.ps1 b/src/ConnectedKubernetes/ConnectedKubernetes.Autorest/internal/Set-AzConnectedKubernetes.ps1 index 36d5aeb903e9..04fd8cbf44de 100644 --- a/src/ConnectedKubernetes/ConnectedKubernetes.Autorest/internal/Set-AzConnectedKubernetes.ps1 +++ b/src/ConnectedKubernetes/ConnectedKubernetes.Autorest/internal/Set-AzConnectedKubernetes.ps1 @@ -22,8 +22,31 @@ API to register a new Kubernetes cluster and create a tracked resource in Azure .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 -GatewayResourceId gatewayResourceId +Set-AzConnectedKubernetes -ClusterName azps_test_cluster -ResourceGroupName azps_test_group -Location eastus -GatewayResourceId $gatewayResourceId +.Example +# Get an existing cluster first +$inputObject = Get-AzConnectedKubernetes -ClusterName azps_test_cluster -ResourceGroupName azps_test_group -SubscriptionId $subscriptionId +# Enable gateway and set gateway resource Id +$inputObject.GatewayEnabled=$true +$inputObject.GatewayResourceId=$gatewayResourceId +Set-AzConnectedKubernetes -InputObject $inputObject + +.Example +# Get an existing cluster first +$inputObject = Get-AzConnectedKubernetes -ClusterName azps_test_cluster -ResourceGroupName azps_test_group -SubscriptionId $subscriptionId +# Enable workload identity and OIDC issuer profile +$inputObject.WorkloadIdentityEnabled=$true +$inputObject.OidcIssuerProfileEnabled=$true +Set-AzConnectedKubernetes -InputObject $inputObject +.Example +# Get an existing cluster first +$inputObject = Get-AzConnectedKubernetes -ClusterName azps_test_cluster -ResourceGroupName azps_test_group -SubscriptionId $subscriptionId +# Disable workload identity +$inputObject.WorkloadIdentityEnabled=$falue +Set-AzConnectedKubernetes -InputObject $inputObject +.Example +Get-AzConnectedKubernetes -ClusterName azps_test_cluster -ResourceGroupName azps_test_group -SubscriptionId $subscriptionId | Set-AzConnectedKubernetes -WorkloadIdentityEnabled:$false .Outputs Microsoft.Azure.PowerShell.Cmdlets.ConnectedKubernetes.Models.Api20240715Preview.IConnectedCluster diff --git a/src/ConnectedKubernetes/ConnectedKubernetes.Autorest/test/New-AzConnectedKubernetes.Tests.ps1 b/src/ConnectedKubernetes/ConnectedKubernetes.Autorest/test/New-AzConnectedKubernetes.Tests.ps1 index 76c3449bff21..d8944054731c 100644 --- a/src/ConnectedKubernetes/ConnectedKubernetes.Autorest/test/New-AzConnectedKubernetes.Tests.ps1 +++ b/src/ConnectedKubernetes/ConnectedKubernetes.Autorest/test/New-AzConnectedKubernetes.Tests.ps1 @@ -50,10 +50,13 @@ Describe 'Invoke-ConfigDPHealthCheck' { It 'Unhealthy (not 200 response)' { Mock Invoke-RestMethod { - $Script:StatusCode = 500 - return + Throw "Some error!" } - { Invoke-ConfigDPHealthCheck } | Should -Throw "Error while performing DP health check, StatusCode: 500" + # Actually expect the error message to be "Error while performing DP health check, StatusCode: $StatusCode" + # But we now Mock Invoke-RestMethod not Invoke-RestMethodWithUriParameters, and Invoke-RestMethod + # can only return unhealthy response with error thrown, which creates a terminating error and will be + # cauhgt by pester + { Invoke-ConfigDPHealthCheck } | Should -Throw Assert-MockCalled "Invoke-RestMethod" -Times 1 Assert-VerifiableMock } @@ -73,8 +76,6 @@ Describe 'Invoke-RestMethodWithUriParameters' { -Headers @{} ` -UriParameters $uriParameters ` -RequestBody @{} ` - -MaximumRetryCount 5 ` - -RetryIntervalSec 2 ` -StatusCodeVariable YesOrNo } | Should -Not -Throw Assert-MockCalled "Invoke-RestMethod" -Times 1 -ParameterFilter { $Uri.AbsoluteUri -eq "https://invalid.invalid/some/page/nowhere" } @@ -98,8 +99,6 @@ Describe 'Invoke-RestMethodWithUriParameters' { -Headers @{} ` -UriParameters $uriParameters ` -RequestBody @{} ` - -MaximumRetryCount 5 ` - -RetryIntervalSec 2 ` -StatusCodeVariable YesOrNo } | Should -Not -Throw Assert-MockCalled "Invoke-RestMethod" -Times 1 -ParameterFilter { $Uri.AbsoluteUri -eq "https://invalid.invalid/some/page/nowhere?key1=value1&key2=value2" } @@ -109,8 +108,7 @@ Describe 'Invoke-RestMethodWithUriParameters' { It 'request failed' { Mock Invoke-RestMethod { - $Script:StatusCode = 500 - return + throw "Some Error!" } { Invoke-RestMethodWithUriParameters ` @@ -119,12 +117,10 @@ Describe 'Invoke-RestMethodWithUriParameters' { -Headers @{} ` -UriParameters @{} ` -RequestBody @{} ` - -MaximumRetryCount 5 ` - -RetryIntervalSec 2 ` -StatusCodeVariable YesOrNo - } | Should -Not -Throw + } | Should -Throw "Error while issuing REST request: Some Error!" Assert-VerifiableMock - $YesOrNo | Should -Be 500 + $YesOrNo | Should -Be 400 } } @@ -327,17 +323,15 @@ Describe 'Get-HelmValuesFromConfigDP' { } id = "abcd" } - $rsp = $null Mock Invoke-RestMethod { - $Script:StatusCode = 500 - return $rsp + Throw "Some Error" } { $Script:helmValues = Get-HelmValuesFromConfigDP ` -ConfigDpEndpoint "https://helm.azure.com" ` -ReleaseTrainCustom $null ` -RequestBody $rq - } | Should -Throw "No content was found in helm registry path response, StatusCode: 500." + } | Should -Throw Assert-MockCalled "Invoke-RestMethod" -Times 1 Assert-VerifiableMock } @@ -381,7 +375,7 @@ Describe 'Get-HelmValuesFromConfigDP' { -ConfigDpEndpoint "https://helm.azure.com" ` -ReleaseTrainCustom $null ` -RequestBody $rq - } | Should -Throw "Error while fetching helm values from DP from JSON response: Failed!" + } | Should -Throw Assert-MockCalled "Invoke-RestMethod" -Times 1 Assert-VerifiableMock } @@ -410,8 +404,6 @@ Describe 'Get-HelmChartPath' { -Path $env:USERPROFILE ` -ChildPath ".azure" ` -AdditionalChildPath "AzureArcCharts", "azure-arc-k8sagents" - # Write-Error -Message "ChartPath: $ChartPath" -ErrorAction Continue - # Write-Error -Message "ExpectedChartPath: $ExpectedChartPath" -ErrorAction Continue $ChartPath | Should -eq $ExpectedChartPath } @@ -449,8 +441,6 @@ Describe 'Get-HelmChartPath' { -Path $env:USERPROFILE ` -ChildPath ".azure" ` -AdditionalChildPath "PreOnboardingChecksCharts", "azure-arc-k8sagents" - # Write-Error -Message "ChartPath: $ChartPath" -ErrorAction Continue - # Write-Error -Message "ExpectedChartPath: $ExpectedChartPath" -ErrorAction Continue $ChartPath | Should -eq $ExpectedChartPath $env:HELMCHART = $null } @@ -568,12 +558,6 @@ Describe 'Get-HelmChart' { -RegistryPath "SomePath:1.2.3" ` -ChartExportPath "c:\temp" ` -HelmClientLocation "fake-helm-client.exe" - # -KubeConfig ` - # -KubeContext ` - # -NewPath - # -ChartName = 'azure-arc-k8sagents' ` - # -RetryCount = 5 ` - # -RetryDelay = 3 } | Should -Not -Throw Assert-MockCalled "Invoke-ExternalCommand" -Times 3 Assert-VerifiableMock @@ -588,12 +572,6 @@ Describe 'Get-HelmChart' { -RegistryPath "SomePath:1.20.3" ` -ChartExportPath "c:\temp" ` -HelmClientLocation "fake-helm-client.exe" - # -KubeConfig ` - # -KubeContext ` - # -NewPath - # -ChartName = 'azure-arc-k8sagents' ` - # -RetryCount = 5 ` - # -RetryDelay = 3 } | Should -Throw "Unable to pull 'azure-arc-k8sagents' helm chart from the registry 'SomePath:1.20.3'." Assert-MockCalled "Invoke-ExternalCommand" -Times 5 Assert-VerifiableMock diff --git a/src/ConnectedKubernetes/ConnectedKubernetes.Autorest/test/Set-HelmModulesAndRepository.Tests.ps1 b/src/ConnectedKubernetes/ConnectedKubernetes.Autorest/test/Set-HelmModulesAndRepository.Tests.ps1 new file mode 100644 index 000000000000..12a8a3da4f9c --- /dev/null +++ b/src/ConnectedKubernetes/ConnectedKubernetes.Autorest/test/Set-HelmModulesAndRepository.Tests.ps1 @@ -0,0 +1,21 @@ +if(($null -eq $TestName) -or ($TestName -contains 'Set-HelmModulesAndRepository')) +{ + $loadEnvPath = Join-Path $PSScriptRoot 'loadEnv.ps1' + if (-Not (Test-Path -Path $loadEnvPath)) { + $loadEnvPath = Join-Path $PSScriptRoot '..\loadEnv.ps1' + } + . ($loadEnvPath) + $TestRecordingFile = Join-Path $PSScriptRoot 'Set-HelmModulesAndRepository.Recording.json' + $currentPath = $PSScriptRoot + while(-not $mockingPath) { + $mockingPath = Get-ChildItem -Path $currentPath -Recurse -Include 'HttpPipelineMocking.ps1' -File + $currentPath = Split-Path -Path $currentPath -Parent + } + . ($mockingPath | Select-Object -First 1).FullName +} + +Describe 'Set-HelmModulesAndRepository' { + It '__AllParameterSets' -skip { + { throw [System.NotImplementedException] } | Should -Not -Throw + } +} diff --git a/src/ConnectedKubernetes/ConnectedKubernetes/Az.ConnectedKubernetes.psd1 b/src/ConnectedKubernetes/ConnectedKubernetes/Az.ConnectedKubernetes.psd1 index 3b4b778e9746..8e60571e3031 100644 --- a/src/ConnectedKubernetes/ConnectedKubernetes/Az.ConnectedKubernetes.psd1 +++ b/src/ConnectedKubernetes/ConnectedKubernetes/Az.ConnectedKubernetes.psd1 @@ -3,7 +3,7 @@ # # Generated by: Microsoft Corporation # -# Generated on: 10/17/2024 +# Generated on: 11/7/2024 # @{ @@ -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 = @@ -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' @@ -126,7 +126,7 @@ PrivateData = @{ } # End of PSData hashtable - } # End of PrivateData hashtable +} # End of PrivateData hashtable # HelpInfo URI of this module # HelpInfoURI = '' diff --git a/src/ConnectedKubernetes/ConnectedKubernetes/ChangeLog.md b/src/ConnectedKubernetes/ConnectedKubernetes/ChangeLog.md index 7c8d4a797571..ea463bf66892 100644 --- a/src/ConnectedKubernetes/ConnectedKubernetes/ChangeLog.md +++ b/src/ConnectedKubernetes/ConnectedKubernetes/ChangeLog.md @@ -18,6 +18,8 @@ - Additional information about change #1 --> ## Upcoming Release +* Corrected function that only worked on Windows. +* Prevented unexpected value changes where parameters that were never set are unchanged but replayed back as part of Set-AzConnectedKubernetes processing. ## Version 0.11.1 * Fixed environment variable usage diff --git a/src/ConnectedKubernetes/ConnectedKubernetes/help/Get-AzConnectedKubernetes.md b/src/ConnectedKubernetes/ConnectedKubernetes/help/Get-AzConnectedKubernetes.md index e71eac216058..ede97042bea7 100644 --- a/src/ConnectedKubernetes/ConnectedKubernetes/help/Get-AzConnectedKubernetes.md +++ b/src/ConnectedKubernetes/ConnectedKubernetes/help/Get-AzConnectedKubernetes.md @@ -15,25 +15,25 @@ Returns the properties of the specified connected cluster, including name, ident ### List1 (Default) ``` Get-AzConnectedKubernetes [-SubscriptionId ] [-DefaultProfile ] - [] + [-ProgressAction ] [] ``` ### Get ``` Get-AzConnectedKubernetes -ClusterName -ResourceGroupName [-SubscriptionId ] - [-DefaultProfile ] [] + [-DefaultProfile ] [-ProgressAction ] [] ``` ### List ``` Get-AzConnectedKubernetes -ResourceGroupName [-SubscriptionId ] [-DefaultProfile ] - [] + [-ProgressAction ] [] ``` ### GetViaIdentity ``` Get-AzConnectedKubernetes -InputObject [-DefaultProfile ] - [] + [-ProgressAction ] [] ``` ## DESCRIPTION @@ -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. diff --git a/src/ConnectedKubernetes/ConnectedKubernetes/help/Get-AzConnectedKubernetesUserCredential.md b/src/ConnectedKubernetes/ConnectedKubernetes/help/Get-AzConnectedKubernetesUserCredential.md index 29236a32fb92..a637be44a2d9 100644 --- a/src/ConnectedKubernetes/ConnectedKubernetes/help/Get-AzConnectedKubernetesUserCredential.md +++ b/src/ConnectedKubernetes/ConnectedKubernetes/help/Get-AzConnectedKubernetesUserCredential.md @@ -16,14 +16,14 @@ Gets cluster user credentials of the connected cluster with a specified resource ``` Get-AzConnectedKubernetesUserCredential -ClusterName -ResourceGroupName [-SubscriptionId ] -AuthenticationMethod [-ClientProxy] - [-DefaultProfile ] [-WhatIf] [-Confirm] [] + [-DefaultProfile ] [-ProgressAction ] [-WhatIf] [-Confirm] [] ``` ### List ``` Get-AzConnectedKubernetesUserCredential -ClusterName -ResourceGroupName [-SubscriptionId ] -Property [-DefaultProfile ] - [-WhatIf] [-Confirm] [] + [-ProgressAction ] [-WhatIf] [-Confirm] [] ``` ## DESCRIPTION @@ -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. diff --git a/src/ConnectedKubernetes/ConnectedKubernetes/help/New-AzConnectedKubernetes.md b/src/ConnectedKubernetes/ConnectedKubernetes/help/New-AzConnectedKubernetes.md index 8b20dcb33233..089741860d62 100644 --- a/src/ConnectedKubernetes/ConnectedKubernetes/help/New-AzConnectedKubernetes.md +++ b/src/ConnectedKubernetes/ConnectedKubernetes/help/New-AzConnectedKubernetes.md @@ -22,7 +22,7 @@ New-AzConnectedKubernetes -ClusterName -ResourceGroupName [-Su [-CustomLocationsOid ] [-OidcIssuerProfileEnabled] [-OidcIssuerProfileSelfHostedIssuerUrl ] [-WorkloadIdentityEnabled] [-AcceptEULA] [-DefaultProfile ] [-AsJob] [-NoWait] [-ConfigurationSetting ] [-ConfigurationProtectedSetting ] [-GatewayResourceId ] - [-WhatIf] [-Confirm] [] + [-ProgressAction ] [-WhatIf] [-Confirm] [] ``` ## DESCRIPTION @@ -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. diff --git a/src/ConnectedKubernetes/ConnectedKubernetes/help/Remove-AzConnectedKubernetes.md b/src/ConnectedKubernetes/ConnectedKubernetes/help/Remove-AzConnectedKubernetes.md index 53da0f8dffd1..58ef17e2141a 100644 --- a/src/ConnectedKubernetes/ConnectedKubernetes/help/Remove-AzConnectedKubernetes.md +++ b/src/ConnectedKubernetes/ConnectedKubernetes/help/Remove-AzConnectedKubernetes.md @@ -16,14 +16,14 @@ Delete a connected cluster, removing the tracked resource in Azure Resource Mana ``` Remove-AzConnectedKubernetes -ClusterName -ResourceGroupName [-SubscriptionId ] [-KubeConfig ] [-KubeContext ] [-DefaultProfile ] [-AsJob] [-NoWait] [-PassThru] - [-WhatIf] [-Confirm] [] + [-ProgressAction ] [-WhatIf] [-Confirm] [] ``` ### DeleteViaIdentity ``` Remove-AzConnectedKubernetes -InputObject [-KubeConfig ] [-KubeContext ] [-DefaultProfile ] [-AsJob] [-NoWait] [-PassThru] - [-WhatIf] [-Confirm] [] + [-ProgressAction ] [-WhatIf] [-Confirm] [] ``` ## DESCRIPTION @@ -168,6 +168,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 +``` + ### -ResourceGroupName The name of the resource group. The name is case insensitive. diff --git a/src/ConnectedKubernetes/ConnectedKubernetes/help/Set-AzConnectedKubernetes.md b/src/ConnectedKubernetes/ConnectedKubernetes/help/Set-AzConnectedKubernetes.md index 51761d0e98c7..e4d554f9f145 100644 --- a/src/ConnectedKubernetes/ConnectedKubernetes/help/Set-AzConnectedKubernetes.md +++ b/src/ConnectedKubernetes/ConnectedKubernetes/help/Set-AzConnectedKubernetes.md @@ -22,8 +22,8 @@ Set-AzConnectedKubernetes -ClusterName -ResourceGroupName [-Su [-ProvisioningState ] [-Tag ] [-CustomLocationsOid ] [-OidcIssuerProfileEnabled] [-OidcIssuerProfileSelfHostedIssuerUrl ] [-WorkloadIdentityEnabled] [-AcceptEULA] [-ConfigurationSetting ] [-ConfigurationProtectedSetting ] - [-GatewayResourceId ] [-DefaultProfile ] [-AsJob] [-NoWait] - [-WhatIf] [-Confirm] [] + [-DefaultProfile ] [-AsJob] [-NoWait] [-ProgressAction ] [-WhatIf] [-Confirm] + [] ``` ### SetExpandedDisableGateway @@ -36,10 +36,38 @@ Set-AzConnectedKubernetes -ClusterName -ResourceGroupName [-Su [-ProvisioningState ] [-Tag ] [-CustomLocationsOid ] [-OidcIssuerProfileEnabled] [-OidcIssuerProfileSelfHostedIssuerUrl ] [-WorkloadIdentityEnabled] [-AcceptEULA] [-ConfigurationSetting ] [-ConfigurationProtectedSetting ] - [-GatewayResourceId ] [-DisableGateway] [-DefaultProfile ] [-AsJob] [-NoWait] + [-DisableGateway] [-DefaultProfile ] [-AsJob] [-NoWait] [-ProgressAction ] [-WhatIf] [-Confirm] [] ``` +### SetExpandedEnableGateway +``` +Set-AzConnectedKubernetes -ClusterName -ResourceGroupName [-SubscriptionId ] + [-HttpProxy ] [-HttpsProxy ] [-NoProxy ] [-ProxyCert ] [-DisableAutoUpgrade] + [-ContainerLogPath ] -Location [-KubeConfig ] [-KubeContext ] + [-AzureHybridBenefit ] [-Distribution ] [-DistributionVersion ] + [-Infrastructure ] [-PrivateLinkScopeResourceId ] [-PrivateLinkState ] + [-ProvisioningState ] [-Tag ] [-CustomLocationsOid ] + [-OidcIssuerProfileEnabled] [-OidcIssuerProfileSelfHostedIssuerUrl ] [-WorkloadIdentityEnabled] + [-AcceptEULA] [-ConfigurationSetting ] [-ConfigurationProtectedSetting ] + -GatewayResourceId [-DefaultProfile ] [-AsJob] [-NoWait] + [-ProgressAction ] [-WhatIf] [-Confirm] [] +``` + +### SetEnableGateway +``` +Set-AzConnectedKubernetes [-SubscriptionId ] [-HttpProxy ] [-HttpsProxy ] [-NoProxy ] + [-ProxyCert ] [-DisableAutoUpgrade] [-ContainerLogPath ] [-KubeConfig ] + [-KubeContext ] [-AzureHybridBenefit ] [-Distribution ] + [-DistributionVersion ] [-Infrastructure ] [-PrivateLinkScopeResourceId ] + [-PrivateLinkState ] [-ProvisioningState ] [-Tag ] + [-CustomLocationsOid ] [-OidcIssuerProfileEnabled] [-OidcIssuerProfileSelfHostedIssuerUrl ] + [-WorkloadIdentityEnabled] [-AcceptEULA] [-ConfigurationSetting ] + [-ConfigurationProtectedSetting ] -GatewayResourceId -InputObject + [-DefaultProfile ] [-AsJob] [-NoWait] [-ProgressAction ] [-WhatIf] [-Confirm] + [] +``` + ### SetDisableGateway ``` Set-AzConnectedKubernetes [-SubscriptionId ] [-HttpProxy ] [-HttpsProxy ] [-NoProxy ] @@ -49,9 +77,9 @@ Set-AzConnectedKubernetes [-SubscriptionId ] [-HttpProxy ] [-HttpsP [-PrivateLinkState ] [-ProvisioningState ] [-Tag ] [-CustomLocationsOid ] [-OidcIssuerProfileEnabled] [-OidcIssuerProfileSelfHostedIssuerUrl ] [-WorkloadIdentityEnabled] [-AcceptEULA] [-ConfigurationSetting ] - [-ConfigurationProtectedSetting ] [-GatewayResourceId ] [-DisableGateway] - -InputObject [-DefaultProfile ] [-AsJob] [-NoWait] - [-WhatIf] [-Confirm] [] + [-ConfigurationProtectedSetting ] [-DisableGateway] -InputObject + [-DefaultProfile ] [-AsJob] [-NoWait] [-ProgressAction ] [-WhatIf] [-Confirm] + [] ``` ### Set @@ -63,17 +91,17 @@ Set-AzConnectedKubernetes [-SubscriptionId ] [-HttpProxy ] [-HttpsP [-PrivateLinkState ] [-ProvisioningState ] [-Tag ] [-CustomLocationsOid ] [-OidcIssuerProfileEnabled] [-OidcIssuerProfileSelfHostedIssuerUrl ] [-WorkloadIdentityEnabled] [-AcceptEULA] [-ConfigurationSetting ] - [-ConfigurationProtectedSetting ] [-GatewayResourceId ] -InputObject - [-DefaultProfile ] [-AsJob] [-NoWait] [-WhatIf] [-Confirm] - [] + [-ConfigurationProtectedSetting ] -InputObject [-DefaultProfile ] + [-AsJob] [-NoWait] [-ProgressAction ] [-WhatIf] [-Confirm] [] ``` ## DESCRIPTION -API to set properties of the connected cluster resource +API to set properties of the connected cluster resource. +Replaces all configuration of an existing connected cluster; any properties not specified will be reset to their default values. ## EXAMPLES -### Example 1: Disable gateway feature of a connected kubernetes. +### Example 1: Disable gateway for a connected Kubernetes cluster ```powershell Set-AzConnectedKubernetes -ClusterName azps_test_cluster -ResourceGroupName azps_test_group -Location eastus -DisableGateway ``` @@ -84,11 +112,11 @@ Location Name ResourceGroupName eastus azps_test_cluster azps_test_group ``` -This command disable gateway feature of a connected kubernetes. +This command disable gateway feature of a connected kubernete cluster. -### Example 2: Enable gateway feature of connected kubernetes. +### Example 2: Enable gateway for a connected Kubernetes cluster ```powershell -Set-AzConnectedKubernetes -ClusterName azps_test_cluster -ResourceGroupName azps_test_group -Location eastus -GatewayResourceId gatewayResourceId +Set-AzConnectedKubernetes -ClusterName azps_test_cluster -ResourceGroupName azps_test_group -Location eastus -GatewayResourceId $gatewayResourceId ``` ```output @@ -97,7 +125,73 @@ Location Name ResourceGroupName eastus azps_test_cluster azps_test_group ``` -This command disable gateway feature of a connected kubernetes. +This command enables gateway feature of a connected kubernetes cluster. + +### Example 3: Enable gateway for a connected Kubernetes cluster with InputObject +```powershell +# Get an existing cluster first +$inputObject = Get-AzConnectedKubernetes -ClusterName azps_test_cluster -ResourceGroupName azps_test_group -SubscriptionId $subscriptionId +# Enable gateway and set gateway resource Id +$inputObject.GatewayEnabled=$true +$inputObject.GatewayResourceId=$gatewayResourceId +Set-AzConnectedKubernetes -InputObject $inputObject +``` + +```output +Location Name ResourceGroupName +-------- ---- ----------------- +eastus azps_test_cluster azps_test_group +``` + +This command enables gateway feature of a connected kubernetes cluster. + +### Example 4: Enable workload identity of a connected kubernetes cluster with InputObject +```powershell +# Get an existing cluster first +$inputObject = Get-AzConnectedKubernetes -ClusterName azps_test_cluster -ResourceGroupName azps_test_group -SubscriptionId $subscriptionId +# Enable workload identity and OIDC issuer profile +$inputObject.WorkloadIdentityEnabled=$true +$inputObject.OidcIssuerProfileEnabled=$true +Set-AzConnectedKubernetes -InputObject $inputObject +``` + +```output +Location Name ResourceGroupName +-------- ---- ----------------- +eastus azps_test_cluster azps_test_group +``` + +This command enables workload identity and OIDC Issuer Profile for a connected Kubernetes cluster + +### Example 5: Disable workload identity of a connected kubernetes cluster with InputOjbect +```powershell +# Get an existing cluster first +$inputObject = Get-AzConnectedKubernetes -ClusterName azps_test_cluster -ResourceGroupName azps_test_group -SubscriptionId $subscriptionId +# Disable workload identity +$inputObject.WorkloadIdentityEnabled=$falue +Set-AzConnectedKubernetes -InputObject $inputObject +``` + +```output +Location Name ResourceGroupName +-------- ---- ----------------- +eastus azps_test_cluster azps_test_group +``` + +This command disables workload identity of a connected kubernetes cluster + +### Example 6: Disable workload identity of a connected kubernetes cluster +```powershell +Get-AzConnectedKubernetes -ClusterName azps_test_cluster -ResourceGroupName azps_test_group -SubscriptionId $subscriptionId | Set-AzConnectedKubernetes -WorkloadIdentityEnabled:$false +``` + +```output +Location Name ResourceGroupName +-------- ---- ----------------- +eastus azps_test_cluster azps_test_group +``` + +This command disables workload identity of a connected kubernetes cluster ## PARAMETERS @@ -151,7 +245,7 @@ The name of the Kubernetes cluster on which get is called. ```yaml Type: System.String -Parameter Sets: SetExpanded, SetExpandedDisableGateway +Parameter Sets: SetExpanded, SetExpandedDisableGateway, SetExpandedEnableGateway Aliases: Name Required: True @@ -300,10 +394,10 @@ Arc Gateway resource Id, providing this will enable the gateway ```yaml Type: System.String -Parameter Sets: (All) +Parameter Sets: SetExpandedEnableGateway, SetEnableGateway Aliases: -Required: False +Required: True Position: Named Default value: None Accept pipeline input: False @@ -360,13 +454,13 @@ To construct, see NOTES section for INPUTOBJECT properties and create a hash tab ```yaml Type: Microsoft.Azure.PowerShell.Cmdlets.ConnectedKubernetes.Models.Api20240715Preview.IConnectedCluster -Parameter Sets: SetDisableGateway, Set +Parameter Sets: SetEnableGateway, SetDisableGateway, Set Aliases: Required: True Position: Named Default value: None -Accept pipeline input: False +Accept pipeline input: True (ByValue) Accept wildcard characters: False ``` @@ -405,7 +499,7 @@ The geo-location where the resource lives ```yaml Type: System.String -Parameter Sets: SetExpanded, SetExpandedDisableGateway +Parameter Sets: SetExpanded, SetExpandedDisableGateway, SetExpandedEnableGateway Aliases: Required: True @@ -505,6 +599,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. @@ -541,7 +650,7 @@ The name is case insensitive. ```yaml Type: System.String -Parameter Sets: SetExpanded, SetExpandedDisableGateway +Parameter Sets: SetExpanded, SetExpandedDisableGateway, SetExpandedEnableGateway Aliases: Required: True @@ -582,7 +691,7 @@ Accept wildcard characters: False ``` ### -WorkloadIdentityEnabled -Whether to enable or disable the workload identity Webhook +Enable the workload identity Webhook ```yaml Type: System.Management.Automation.SwitchParameter @@ -632,6 +741,8 @@ This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable ## INPUTS +### Microsoft.Azure.PowerShell.Cmdlets.ConnectedKubernetes.Models.Api20240715Preview.IConnectedCluster + ## OUTPUTS ### Microsoft.Azure.PowerShell.Cmdlets.ConnectedKubernetes.Models.Api20240715Preview.IConnectedCluster diff --git a/src/ConnectedKubernetes/ConnectedKubernetes/help/Update-AzConnectedKubernetes.md b/src/ConnectedKubernetes/ConnectedKubernetes/help/Update-AzConnectedKubernetes.md index 4ee40c351d11..8bb7e117f9db 100644 --- a/src/ConnectedKubernetes/ConnectedKubernetes/help/Update-AzConnectedKubernetes.md +++ b/src/ConnectedKubernetes/ConnectedKubernetes/help/Update-AzConnectedKubernetes.md @@ -17,7 +17,7 @@ API to update certain properties of the connected cluster resource Update-AzConnectedKubernetes -ClusterName -ResourceGroupName [-SubscriptionId ] [-AzureHybridBenefit ] [-AcceptEULA] [-Distribution ] [-DistributionVersion ] [-Tag ] [-DefaultProfile ] - [-WhatIf] [-Confirm] [] + [-ProgressAction ] [-WhatIf] [-Confirm] [] ``` ### UpdateViaIdentityExpanded @@ -25,7 +25,7 @@ Update-AzConnectedKubernetes -ClusterName -ResourceGroupName [ Update-AzConnectedKubernetes -InputObject [-AzureHybridBenefit ] [-AcceptEULA] [-Distribution ] [-DistributionVersion ] [-Tag ] [-DefaultProfile ] - [-WhatIf] [-Confirm] [] + [-ProgressAction ] [-WhatIf] [-Confirm] [] ``` ## DESCRIPTION @@ -196,6 +196,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.