Skip to content

Commit 7eb813d

Browse files
xw-zhang24Paul D.SmithBenhur JohnsonLei jin
authored
Update cmdlet to support arc gateway (#26026)
* move changes in custom folders * Confirm new branch created. * Initial UTs. * More testing. * Get Azure Metadata improved. * Improve endpoint handling. * Clean up some jsonifiction * Testing getting DP to work. * It does create an ARC proxy now. * Removed 'debugging' error logs. * replace param names * Handle runing tests in autorest Docker. * Always use default config DP endpoint. * save work before pull * Hide internal functions. * Hide intenal functions. * Hide intenal functions. * Remove unused AD resource ID. * Remove last of !!PDS markers. * removing unnecessary option * Get unit tests working again and rename internal functions back. * add verbose logging to New command * add verbose logging to helmhelper * add set block * put inputobject back * work on comments * work on comments * Name mismatch. * regenerate files after merge * Internal function name mismatch. * Add some development notes. * fixes * Updates from suggestions from Xiwen. * verbose markups * Revert "verbose markups" This reverts commit 72f4bb9. * actual verbose markups * get helm before upgrade * now we have set scripts * remove ConnectionType * why connectiontype is still here? * why connectiontype is still here? * verbose logging for Set command * regenerate files * remove comments * remove extraction comments * remove comments * remove set with inputobject again * extract common code from New and Set * new helper file with common code * Rename common file. * Should work for New now. * move common code to helm helper * return hashtable * only parse when not provided * set DisableGateway to not EnableGatway * introduce extra paramtersets for enable/disable gateway * move parameters up * Typo in parameter set name. * Placeholder comment. * Generalize ConfigDP mapping support in New - DOES NOT WORK yet. * deal with protected settings * Updated comments on ConfigDP and name matching. * Comment string describing the configuration settings check. * Updated comments for configuration settings parameters. * Only pass settings to CCRP. * Create empty hash tables not null if no values. * deal with protected setting in Set- * Commonalize some methods. * Commonalize some methods. * Add ShouldProcess support for New-... * fix 1 * fix: exclude indices in function return * should process set * Cannot manipulate PSBoundParameters in sub-function. * Initialize health DP status code. * What-If processing. Use approved verb for Confim-HelmVersion. * Enable helm debugging if -Debug is set. * Make tests work again Move method to ConfigDP helper. * what if on Set * remove some comments * remove commented code * Use old ClientKnown redacted variant. * Use old ClientKnown redacted variant. * Remove feature warnings Correct bug setting helm debug option. * use colon as delimiter in configration setting * clean up * rename helper file * Make docs autogen work. * renaming AZCloudMetadataHelper to AzCloudMetadataHelper * fix url * add examples * singular nouns * add exception * send protected settings * fix index in Set and string finding in both Set and New * reorder options --------- Co-authored-by: Paul D.Smith <pauldsmith@microsoft.com> Co-authored-by: Benhur Johnson <benhur.johnson@metaswitch.com> Co-authored-by: Lei jin <leijin@microsoft.com>
1 parent 34cac1e commit 7eb813d

38 files changed

+5420
-1133
lines changed

src/ConnectedKubernetes/ConnectedKubernetes.Autorest/Az.ConnectedKubernetes.psd1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
DotNetFrameworkVersion = '4.7.2'
1212
RequiredAssemblies = './bin/Az.ConnectedKubernetes.private.dll'
1313
FormatsToProcess = './Az.ConnectedKubernetes.format.ps1xml'
14-
FunctionsToExport = 'Get-AzConnectedKubernetes', 'Get-AzConnectedKubernetesUserCredential', 'New-AzConnectedKubernetes', 'Remove-AzConnectedKubernetes', 'Update-AzConnectedKubernetes', '*'
14+
FunctionsToExport = 'Get-AzConnectedKubernetes', 'Get-AzConnectedKubernetesUserCredential', 'New-AzConnectedKubernetes', 'Remove-AzConnectedKubernetes', 'Set-AzConnectedKubernetes', 'Update-AzConnectedKubernetes', '*'
1515
AliasesToExport = '*'
1616
PrivateData = @{
1717
PSData = @{
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# Develpoing ConnectedKubernetes Powershell Cmdlets
2+
> 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.
3+
4+
# Overview
5+
## Why Custom Cmdlets?
6+
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].
7+
8+
For this reason, the ConnectedKubernetes cmdlets have two or more steps such as:
9+
- Interact with Azure using the REST APIs; this often involves just calling the autogenerated cmdlets
10+
- Now interact with Kubernetes using [helm].
11+
12+
## (Part) Autogeneration Process
13+
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:
14+
15+
1. Carefully craft your [Swagger] definition of the REST API
16+
1. Read the [Quickstart for Azure PowerShell development using code generator]
17+
1. Clone the [azure-powershell] repo
18+
1. Create a develpoment branch based on the `generate` branch **and not based on `main`**!
19+
1. Run the [autorest] Docker image; if you have no local image for [autorest], refer to
20+
1. Run [autorest] to generate configuration and files that will result in the autogenerated cmdlets
21+
1. Run the build process (`pwsh build-module.ps1`) which completes the build process.
22+
23+
### Building the [autorest] Docker image
24+
> 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!
25+
26+
- Clone the [autorest.powershell] repo
27+
- Navigate to the `tools/docker` directory
28+
- Follow the instructions in the README file in that directory
29+
30+
## Special Aspects for ConnectedKubernetes
31+
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.
32+
> As described earlier, the custom versions often call-through to the autogenerated version to perform the ARM REST API portion of their work.
33+
34+
### Gotchas
35+
#### You Want a New Cmdlet?
36+
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.
37+
38+
When we tried to add the `Set-` cmdlet, we found it never appeared but eventually we discovered these nuggets of knowledge.
39+
- [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
40+
- The `internal` cmdlets are really just Powershell wrappers but these are not created until the `pwsh build-module-ps1` step
41+
- Between the steps above sits the [autorest] configuration found in the XML at the end of [README.md]. This does stuff like:
42+
- Stops the generation of various versions of cmdlets that are not required
43+
- **hides** the autogenerated cmdlets, which is what causes them to be created in `internal`; we had to add `set` to the list of cmdlets so hidden before the `internal` `Set-` cmdlet appeared.
44+
45+
[autorest.powershell]: https://github.com/Azure/autorest.powershell
46+
[autorest]: https://github.com/Azure/autorest
47+
[helm]: https://helm.sh/
48+
[Swagger]: https://swagger.io/
49+
[README.md]: ./README.md
50+
[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
51+
[azure-powershell]: https://github.com/azure/azure-powershell

src/ConnectedKubernetes/ConnectedKubernetes.Autorest/README.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,11 @@ In this directory, run AutoRest:
4444
> see https://aka.ms/autorest
4545
4646
``` yaml
47-
commit: 0ce2859b2f018adcea3d14346951ff4270dcff3d
47+
commit: b67274cc1916170502f17ffabac0b46c4620918e
4848
require:
4949
- $(this-folder)/../../readme.azure.noprofile.md
5050
input-file:
51-
- $(repo)/specification/hybridkubernetes/resource-manager/Microsoft.Kubernetes/preview/2024-07-01-preview/connectedClusters.json
51+
- $(repo)/specification/hybridkubernetes/resource-manager/Microsoft.Kubernetes/preview/2024-07-15-preview/connectedClusters.json
5252

5353
title: ConnectedKubernetes
5454
module-version: 0.1.0
@@ -82,8 +82,7 @@ directive:
8282
parameter-name: Property
8383
hide: true
8484
- where:
85-
verb: New|Update|Remove
85+
verb: New|Update|Remove|Set
8686
subject-prefix: ConnectedKubernetes
8787
hide: true
88-
8988
```

src/ConnectedKubernetes/ConnectedKubernetes.Autorest/UX/Microsoft.Kubernetes/connectedClusters.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"resourceType": "connectedClusters",
3-
"apiVersion": "2024-07-01-preview",
3+
"apiVersion": "2024-07-15-preview",
44
"learnMore": {
55
"url": "https://learn.microsoft.com/powershell/module/az.connectedkubernetes"
66
},

src/ConnectedKubernetes/ConnectedKubernetes.Autorest/custom/Az.ConnectedKubernetes.custom.psm1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
# region Generated
22
# Load the private module dll
3-
$null = Import-Module -PassThru -Name (Join-Path $PSScriptRoot '..\bin\Az.ConnectedKubernetes.private.dll')
3+
$null = Import-Module -PassThru -Name (Join-Path $PSScriptRoot '../bin/Az.ConnectedKubernetes.private.dll')
44

55
# Load the internal module
6-
$internalModulePath = Join-Path $PSScriptRoot '..\internal\Az.ConnectedKubernetes.internal.psm1'
6+
$internalModulePath = Join-Path $PSScriptRoot '../internal/Az.ConnectedKubernetes.internal.psm1'
77
if(Test-Path $internalModulePath) {
88
$null = Import-Module -Name $internalModulePath
99
}

0 commit comments

Comments
 (0)