From f569394b9f27a164dc83aa24a7e664b567e8d850 Mon Sep 17 00:00:00 2001 From: Beisi Zhou Date: Thu, 14 Apr 2022 15:48:39 +0800 Subject: [PATCH 1/2] Supported empty directory volume and secret volume for creating container group --- src/ContainerInstance/README.md | 13 +++- .../custom/New-AzContainerGroup.ps1 | 2 +- .../New-AzContainerGroupVolumeObject.ps1 | 70 +++++++++++------ .../SpecialHandlerToRemoveDefaultValue.cs | 11 ++- .../docs/Az.ContainerInstance.md | 2 +- .../docs/New-AzContainerGroup.md | 5 +- .../docs/New-AzContainerGroupVolumeObject.md | 75 +++++++++++++++++-- .../docs/New-AzContainerInstanceObject.md | 1 + .../New-AzContainerGroupVolumeObject.md | 26 ++++++- ...-AzContainerInstanceVolumeObject.Tests.ps1 | 21 ++++++ 10 files changed, 185 insertions(+), 41 deletions(-) create mode 100644 src/ContainerInstance/test/New-AzContainerInstanceVolumeObject.Tests.ps1 diff --git a/src/ContainerInstance/README.md b/src/ContainerInstance/README.md index 5f7d8e9df5e7..864dd0bedc05 100644 --- a/src/ContainerInstance/README.md +++ b/src/ContainerInstance/README.md @@ -17,7 +17,7 @@ This directory contains the PowerShell module for the ContainerInstance service. This module was primarily generated via [AutoRest](https://github.com/Azure/autorest) using the [PowerShell](https://github.com/Azure/autorest.powershell) extension. ## Module Requirements -- [Az.Accounts module](https://www.powershellgallery.com/packages/Az.Accounts/), version 2.2.3 or greater +- [Az.Accounts module](https://www.powershellgallery.com/packages/Az.Accounts/), version 2.7.5 or greater ## Authentication AutoRest does not generate authentication code for the module. Authentication is handled via Az.Accounts by altering the HTTP payload before it is sent. @@ -140,4 +140,15 @@ directive: $["204"] = { "description": "No content" } + # Change the type of EmptyDir from IAny() to VolumeEmptyDir + - from: swagger-document + where: $.definitions.Volume.properties.emptyDir + transform: >- + return { + "description": "The empty directory volume.", + "type": "object", + "additionalProperties": true + } + # - model-cmdlet: + # - Volume # Hide to customize AzureFileStorageAccountKey from string to securestring ``` diff --git a/src/ContainerInstance/custom/New-AzContainerGroup.ps1 b/src/ContainerInstance/custom/New-AzContainerGroup.ps1 index 727387934995..f55d116302a8 100644 --- a/src/ContainerInstance/custom/New-AzContainerGroup.ps1 +++ b/src/ContainerInstance/custom/New-AzContainerGroup.ps1 @@ -18,7 +18,7 @@ .Synopsis Create or update container groups with specified configurations. .Description -Create or update container groups with specified configurations. For property Volume, we support mounting Azure File share as a volume or specifying git repository as volume directory. The empty directory volume and secret volume are not supported yet. +Create or update container groups with specified configurations. .Link https://docs.microsoft.com/powershell/module/az.containerinstance/new-azcontainergroup #> diff --git a/src/ContainerInstance/custom/New-AzContainerGroupVolumeObject.ps1 b/src/ContainerInstance/custom/New-AzContainerGroupVolumeObject.ps1 index e9c8d8c7140d..7ce312ffe5eb 100644 --- a/src/ContainerInstance/custom/New-AzContainerGroupVolumeObject.ps1 +++ b/src/ContainerInstance/custom/New-AzContainerGroupVolumeObject.ps1 @@ -1,23 +1,27 @@ # ---------------------------------------------------------------------------------- -# -# Copyright Microsoft Corporation -# Licensed under the Apache License, Version 2.0 (the \"License\"); +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # http://www.apache.org/licenses/LICENSE-2.0 # Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an \"AS IS\" BASIS, +# distributed under the License is distributed on an "AS IS" BASIS, # 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. # ---------------------------------------------------------------------------------- <# .Synopsis -Create a in-memory object for Volume +Create an in-memory object for Volume. .Description -Create a in-memory object for Volume. Currently, we support mounting Azure File share as a volume or specifying git repository as volume directory. The empty directory volume and secret volume are not supported yet. +Create an in-memory object for Volume. + +.Outputs +Microsoft.Azure.PowerShell.Cmdlets.ContainerInstance.Models.Api20210901.Volume .Link https://docs.microsoft.com/powershell/module/az.ContainerInstance/new-AzContainerGroupVolumeObject #> @@ -38,9 +42,9 @@ function New-AzContainerGroupVolumeObject { [Parameter(HelpMessage="The name of the storage account that contains the Azure File share.")] [string] $AzureFileStorageAccountName, - # [Parameter(HelpMessage="The empty directory volume.")] - # [Microsoft.Azure.PowerShell.Cmdlets.ContainerInstance.Models.IAny] - # $EmptyDir, + [Parameter(HelpMessage="The empty directory volume.")] + [Microsoft.Azure.PowerShell.Cmdlets.ContainerInstance.Models.Api20210901.IVolumeEmptyDir] + $EmptyDir, [Parameter(HelpMessage="Target directory name. Must not contain or start with '..'. If '.' is supplied, the volume directory will be the git repository. Otherwise, if specified, the volume will contain the git repository in the subdirectory with the given name.")] [string] $GitRepoDirectoryName, @@ -52,28 +56,46 @@ function New-AzContainerGroupVolumeObject { $GitRepoRevision, [Parameter(Mandatory, HelpMessage="The name of the volume.")] [string] - $Name - # , - # [Parameter(HelpMessage="The secret volume.")] - # [Microsoft.Azure.PowerShell.Cmdlets.ContainerInstance.Models.Api20210901.ISecretVolume] - # $Secret + $Name, + [Parameter(HelpMessage="The secret volume.")] + [Microsoft.Azure.PowerShell.Cmdlets.ContainerInstance.Models.Api20210901.ISecretVolume] + $Secret ) process { $Object = [Microsoft.Azure.PowerShell.Cmdlets.ContainerInstance.Models.Api20210901.Volume]::New() - $Object.AzureFileShareName = $AzureFileShareName + if ($PSBoundParameters.ContainsKey('AzureFileReadOnly')) { + $Object.AzureFileReadOnly = $AzureFileReadOnly + } + if ($PSBoundParameters.ContainsKey('AzureFileShareName')) { + $Object.AzureFileShareName = $AzureFileShareName + } if ($PSBoundParameters.ContainsKey('AzureFileStorageAccountKey')) { - $psTxt = . "$PSScriptRoot/../utils/Unprotect-SecureString.ps1" $PSBoundParameters['AzureFileStorageAccountKey'] + $psTxt = . "$PSScriptRoot/../utils/Unprotect-SecureString.ps1" $PSBoundParameters['AzureFileStorageAccountKey'] + $Object.AzureFileStorageAccountKey = $psTxt + } + if ($PSBoundParameters.ContainsKey('AzureFileStorageAccountName')) { + $Object.AzureFileStorageAccountName = $AzureFileStorageAccountName + } + if ($PSBoundParameters.ContainsKey('EmptyDir')) { + $Object.EmptyDir = $EmptyDir + } + if ($PSBoundParameters.ContainsKey('GitRepoDirectoryName')) { + $Object.GitRepoDirectory = $GitRepoDirectoryName + } + if ($PSBoundParameters.ContainsKey('GitRepoRepositoryUrl')) { + $Object.GitRepoRepository = $GitRepoRepositoryUrl + } + if ($PSBoundParameters.ContainsKey('GitRepoRevision')) { + $Object.GitRepoRevision = $GitRepoRevision + } + if ($PSBoundParameters.ContainsKey('Name')) { + $Object.Name = $Name + } + if ($PSBoundParameters.ContainsKey('Secret')) { + $Object.Secret = $Secret } - $Object.AzureFileStorageAccountKey = $psTxt - $Object.AzureFileStorageAccountName = $AzureFileStorageAccountName - # $Object.EmptyDir = $EmptyDir - $Object.GitRepoDirectory = $GitRepoDirectoryName - $Object.GitRepoRepository = $GitRepoRepositoryUrl - $Object.GitRepoRevision = $GitRepoRevision - $Object.Name = $Name - # $Object.Secret = $Secret return $Object } } diff --git a/src/ContainerInstance/custom/SpecialHandlerToRemoveDefaultValue.cs b/src/ContainerInstance/custom/SpecialHandlerToRemoveDefaultValue.cs index d3f3a0aef125..34170e18f42e 100644 --- a/src/ContainerInstance/custom/SpecialHandlerToRemoveDefaultValue.cs +++ b/src/ContainerInstance/custom/SpecialHandlerToRemoveDefaultValue.cs @@ -243,10 +243,15 @@ partial void BeforeToJson(ref Microsoft.Azure.PowerShell.Cmdlets.ContainerInstan this._gitRepo = null; } - this._emptyDir = null; - - this._secret = null; } + + partial void AfterToJson(ref Microsoft.Azure.PowerShell.Cmdlets.ContainerInstance.Runtime.Json.JsonObject container) + { + if (this._emptyDir != null && this._emptyDir.Count == 0) { + container.Add("emptyDir", new Microsoft.Azure.PowerShell.Cmdlets.ContainerInstance.Runtime.Json.JsonObject()); + } + } + } } diff --git a/src/ContainerInstance/docs/Az.ContainerInstance.md b/src/ContainerInstance/docs/Az.ContainerInstance.md index 4af52f30df9e..a8c15dcd0d41 100644 --- a/src/ContainerInstance/docs/Az.ContainerInstance.md +++ b/src/ContainerInstance/docs/Az.ContainerInstance.md @@ -47,7 +47,7 @@ Create a in-memory object for ImageRegistryCredential Create a in-memory object for Port ### [New-AzContainerGroupVolumeObject](New-AzContainerGroupVolumeObject.md) -Create a in-memory object for Volume +Create an in-memory object for Volume. ### [New-AzContainerInstanceEnvironmentVariableObject](New-AzContainerInstanceEnvironmentVariableObject.md) Create a in-memory object for EnvironmentVariable diff --git a/src/ContainerInstance/docs/New-AzContainerGroup.md b/src/ContainerInstance/docs/New-AzContainerGroup.md index 432fafc5975f..4afd911ee20d 100644 --- a/src/ContainerInstance/docs/New-AzContainerGroup.md +++ b/src/ContainerInstance/docs/New-AzContainerGroup.md @@ -29,7 +29,7 @@ New-AzContainerGroup -Name -ResourceGroupName -Container : The list of volumes that can be mounted by containers in thi - `[AzureFileShareName ]`: The name of the Azure File share to be mounted as a volume. - `[AzureFileStorageAccountKey ]`: The storage account access key used to access the Azure File share. - `[AzureFileStorageAccountName ]`: The name of the storage account that contains the Azure File share. - - `[EmptyDir ]`: The empty directory volume. + - `[EmptyDir ]`: The empty directory volume. + - `[(Any) ]`: This indicates any property can be added to this object. - `[GitRepoDirectory ]`: Target directory name. Must not contain or start with '..'. If '.' is supplied, the volume directory will be the git repository. Otherwise, if specified, the volume will contain the git repository in the subdirectory with the given name. - `[GitRepoRepository ]`: Repository URL - `[GitRepoRevision ]`: Commit hash for the specified revision. diff --git a/src/ContainerInstance/docs/New-AzContainerGroupVolumeObject.md b/src/ContainerInstance/docs/New-AzContainerGroupVolumeObject.md index 2bcebc1ba29c..7e1ddcdccb2e 100644 --- a/src/ContainerInstance/docs/New-AzContainerGroupVolumeObject.md +++ b/src/ContainerInstance/docs/New-AzContainerGroupVolumeObject.md @@ -8,19 +8,19 @@ schema: 2.0.0 # New-AzContainerGroupVolumeObject ## SYNOPSIS -Create a in-memory object for Volume. Currently, we support mounting Azure File share as a volume or specifying git repository as volume directory. The empty directory volume and secret volume are not supported yet. +Create an in-memory object for Volume. ## SYNTAX ``` New-AzContainerGroupVolumeObject -Name [-AzureFileReadOnly] [-AzureFileShareName ] [-AzureFileStorageAccountKey ] [-AzureFileStorageAccountName ] - [-GitRepoDirectoryName ] [-GitRepoRepositoryUrl ] [-GitRepoRevision ] - [] + [-EmptyDir ] [-GitRepoDirectoryName ] [-GitRepoRepositoryUrl ] + [-GitRepoRevision ] [-Secret ] [] ``` ## DESCRIPTION -Create a in-memory object for Volume +Create an in-memory object for Volume. ## EXAMPLES @@ -30,8 +30,6 @@ New-AzContainerGroupVolumeObject -Name "myvolume" -AzureFileShareName "myshare" ``` ```output -****** - Name ---- myvolume @@ -39,6 +37,28 @@ myvolume This command creates a Azure File volume. +### Example 2: Create an empty directory volume +```powershell +New-AzContainerGroupVolumeObject -Name "emptyvolume" -EmptyDir @{} | fl +``` + +```output +AzureFileReadOnly : +AzureFileShareName : +AzureFileStorageAccountKey : +AzureFileStorageAccountName : +EmptyDir : { + } +GitRepoDirectory : +GitRepoRepository : +GitRepoRevision : +Name : emptyvolume +Secret : { + } +``` + +This command creates an empty directory volume. + ## PARAMETERS ### -AzureFileReadOnly @@ -101,6 +121,22 @@ Accept pipeline input: False Accept wildcard characters: False ``` +### -EmptyDir +The empty directory volume. +To construct, see NOTES section for EMPTYDIR properties and create a hash table. + +```yaml +Type: Microsoft.Azure.PowerShell.Cmdlets.ContainerInstance.Models.Api20210901.IVolumeEmptyDir +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + ### -GitRepoDirectoryName Target directory name. Must not contain or start with '..'. @@ -164,6 +200,22 @@ Accept pipeline input: False Accept wildcard characters: False ``` +### -Secret +The secret volume. +To construct, see NOTES section for SECRET properties and create a hash table. + +```yaml +Type: Microsoft.Azure.PowerShell.Cmdlets.ContainerInstance.Models.Api20210901.ISecretVolume +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + ### CommonParameters This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). @@ -177,5 +229,16 @@ This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable ALIASES +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. + + +EMPTYDIR : The empty directory volume. + - `[(Any) ]`: This indicates any property can be added to this object. + +SECRET : The secret volume. + - `[(Any) ]`: This indicates any property can be added to this object. + ## RELATED LINKS diff --git a/src/ContainerInstance/docs/New-AzContainerInstanceObject.md b/src/ContainerInstance/docs/New-AzContainerInstanceObject.md index 4022d01c78d1..92c39a0e2c29 100644 --- a/src/ContainerInstance/docs/New-AzContainerInstanceObject.md +++ b/src/ContainerInstance/docs/New-AzContainerInstanceObject.md @@ -71,6 +71,7 @@ Location Name Zone ResourceGroupName -------- ---- ---- ----------------- eastus test-cg test-rg ``` + Create a container group with a container instance ## PARAMETERS diff --git a/src/ContainerInstance/examples/New-AzContainerGroupVolumeObject.md b/src/ContainerInstance/examples/New-AzContainerGroupVolumeObject.md index 88df4e1f2e8c..cd61eb14fecd 100644 --- a/src/ContainerInstance/examples/New-AzContainerGroupVolumeObject.md +++ b/src/ContainerInstance/examples/New-AzContainerGroupVolumeObject.md @@ -4,11 +4,31 @@ New-AzContainerGroupVolumeObject -Name "myvolume" -AzureFileShareName "myshare" ``` ```output -****** - Name ---- myvolume ``` -This command creates a Azure File volume. \ No newline at end of file +This command creates a Azure File volume. + +### Example 2: Create an empty directory volume +```powershell +New-AzContainerGroupVolumeObject -Name "emptyvolume" -EmptyDir @{} | fl +``` + +```output +AzureFileReadOnly : +AzureFileShareName : +AzureFileStorageAccountKey : +AzureFileStorageAccountName : +EmptyDir : { + } +GitRepoDirectory : +GitRepoRepository : +GitRepoRevision : +Name : emptyvolume +Secret : { + } +``` + +This command creates an empty directory volume. \ No newline at end of file diff --git a/src/ContainerInstance/test/New-AzContainerInstanceVolumeObject.Tests.ps1 b/src/ContainerInstance/test/New-AzContainerInstanceVolumeObject.Tests.ps1 new file mode 100644 index 000000000000..58dc4600090a --- /dev/null +++ b/src/ContainerInstance/test/New-AzContainerInstanceVolumeObject.Tests.ps1 @@ -0,0 +1,21 @@ +if(($null -eq $TestName) -or ($TestName -contains 'New-AzContainerInstanceVolumeObject')) +{ + $loadEnvPath = Join-Path $PSScriptRoot 'loadEnv.ps1' + if (-Not (Test-Path -Path $loadEnvPath)) { + $loadEnvPath = Join-Path $PSScriptRoot '..\loadEnv.ps1' + } + . ($loadEnvPath) + $TestRecordingFile = Join-Path $PSScriptRoot 'New-AzContainerInstanceVolumeObject.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 'New-AzContainerInstanceVolumeObject' { + It '__AllParameterSets' -skip { + { throw [System.NotImplementedException] } | Should -Not -Throw + } +} From d175ca45eef2051c32a82f44652cec9cd4eba492 Mon Sep 17 00:00:00 2001 From: Beisi Zhou Date: Mon, 18 Apr 2022 10:11:18 +0800 Subject: [PATCH 2/2] Suppress breaking changes --- .../Exceptions/Az.ContainerInstance/BreakingChangeIssues.csv | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 tools/StaticAnalysis/Exceptions/Az.ContainerInstance/BreakingChangeIssues.csv diff --git a/tools/StaticAnalysis/Exceptions/Az.ContainerInstance/BreakingChangeIssues.csv b/tools/StaticAnalysis/Exceptions/Az.ContainerInstance/BreakingChangeIssues.csv new file mode 100644 index 000000000000..b6efd26a8ed9 --- /dev/null +++ b/tools/StaticAnalysis/Exceptions/Az.ContainerInstance/BreakingChangeIssues.csv @@ -0,0 +1,3 @@ +"AssemblyFileName","ClassName","Target","Severity","ProblemId","Description","Remediation" +"Az.ContainerInstance","Get-AzContainerGroup","Get-AzContainerGroup","0","3000","The type of property 'EmptyDir' of type 'Microsoft.Azure.PowerShell.Cmdlets.ContainerInstance.Models.Api20210901.IVolume' has changed from 'Microsoft.Azure.PowerShell.Cmdlets.ContainerInstance.Models.IAny' to 'Microsoft.Azure.PowerShell.Cmdlets.ContainerInstance.Models.IVolumeEmptyDir'.","Change the type of property 'EmptyDir' back to 'Microsoft.Azure.PowerShell.Cmdlets.ContainerInstance.Models.IAny'." +"Az.ContainerInstance","New-AzContainerGroupVolumeObject","New-AzContainerGroupVolumeObject","0","3000","The type of property 'EmptyDir' of type 'Microsoft.Azure.PowerShell.Cmdlets.ContainerInstance.Models.Api20210901.Volume' has changed from 'Microsoft.Azure.PowerShell.Cmdlets.ContainerInstance.Models.IAny' to 'Microsoft.Azure.PowerShell.Cmdlets.ContainerInstance.Models.IVolumeEmptyDir'.","Change the type of property 'EmptyDir' back to 'Microsoft.Azure.PowerShell.Cmdlets.ContainerInstance.Models.IAny'." \ No newline at end of file