Skip to content

Commit d8ab059

Browse files
LukeSlevVeryEarly
andauthored
Add tag support to managed cluster cmdlets (Azure#18473)
* Add tag support to managed cluster cmdlets * Add changelog and examples * Update ChangeLog.md Co-authored-by: Yabo Hu <yabhu@microsoft.com>
1 parent d40078c commit d8ab059

File tree

8 files changed

+1616
-8519
lines changed

8 files changed

+1616
-8519
lines changed

src/ServiceFabric/ServiceFabric.Test/ScenarioTests/ServiceFabricManagedClustersTests.ps1

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,10 @@ function Test-CreateBasicCluster
2121
$testClientTp = "123BDACDCDFB2C7B250192C6078E47D1E1DB119B"
2222
Assert-ThrowsContains { Get-AzServiceFabricManagedCluster -ResourceGroupName $resourceGroupName -Name $clusterName } "NotFound"
2323

24+
$tags = @{"test"="tag"}
25+
2426
$cluster = New-AzServiceFabricManagedCluster -ResourceGroupName $resourceGroupName -ClusterName $clusterName -Location $location `
25-
-AdminPassword $pass -Sku Basic -ClientCertThumbprint $testClientTp -Verbose
27+
-AdminPassword $pass -Sku Basic -ClientCertThumbprint $testClientTp -Tag $tags -Verbose
2628
Assert-AreEqual "Succeeded" $cluster.ProvisioningState
2729
Assert-AreEqual "Automatic" $cluster.ClusterUpgradeMode
2830
Assert-AreEqual "Wave0" $cluster.ClusterUpgradeCadence
@@ -34,14 +36,15 @@ function Test-CreateBasicCluster
3436
# shouldn't be allowed to remove the only primary node type in the cluster
3537
Assert-ThrowsContains { $pnt | Remove-AzServiceFabricManagedNodeType } "InvalidParameter"
3638

37-
$cluster = Get-AzServiceFabricManagedCluster -ResourceGroupName $resourceGroupName -Name $clusterName
38-
Assert-AreEqual "Deploying" $cluster.ClusterState
39+
$clusterFromGet = Get-AzServiceFabricManagedCluster -ResourceGroupName $resourceGroupName -Name $clusterName
40+
Assert-AreEqual "Ready" $clusterFromGet.ClusterState
41+
Assert-HashtableEqual $cluster.Tags $clusterFromGet.Tags
3942

4043
# scale primary node type
4144
$pnt = Set-AzServiceFabricManagedNodeType -ResourceGroupName $resourceGroupName -ClusterName $clusterName -Name pnt -InstanceCount 6
4245
Assert-AreEqual 6 $pnt.VmInstanceCount
4346

44-
$removeResponse = $cluster | Remove-AzServiceFabricManagedCluster -PassThru
47+
$removeResponse = $clusterFromGet | Remove-AzServiceFabricManagedCluster -PassThru
4548
Assert-True { $removeResponse }
4649

4750
Assert-ThrowsContains { Get-AzServiceFabricManagedCluster -ResourceGroupName $resourceGroupName -ClusterName $clusterName } "NotFound"

src/ServiceFabric/ServiceFabric.Test/SessionRecords/Microsoft.Azure.Commands.ServiceFabric.Test.ScenarioTests.ServiceFabricManagedClustersTests/TestCreateBasicCluster.json

Lines changed: 1544 additions & 8504 deletions
Large diffs are not rendered by default.

src/ServiceFabric/ServiceFabric/ChangeLog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
-->
2020
## Upcoming Release
2121
* Fixed typo in verbose log message.
22+
* Added Tag support for managed cluster create and update
2223

2324
## Version 3.0.2
2425
* Added support for Ubuntu 20.04 vm image.

src/ServiceFabric/ServiceFabric/Commands/ManagedClusters/ManagedClusters/NewAzServiceFabricManagedCluster.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@
1212
// ----------------------------------------------------------------------------------
1313

1414
using System;
15+
using System.Collections;
1516
using System.Collections.Generic;
17+
using System.Linq;
1618
using System.Management.Automation;
1719
using System.Security;
1820
using Microsoft.Azure.Commands.ResourceManager.Common.ArgumentCompleters;
@@ -141,6 +143,10 @@ public class NewAzServiceFabricManagedCluster : ServiceFabricManagedCmdletBase
141143
[Parameter(Mandatory = false, HelpMessage = "Run cmdlet in the background and return a Job to track progress.")]
142144
public SwitchParameter AsJob { get; set; }
143145

146+
[Parameter(Mandatory = false, ParameterSetName = ClientCertByTp, HelpMessage = "Specify the tags as key/value pairs.")]
147+
[Parameter(Mandatory = false, ParameterSetName = ClientCertByCn, HelpMessage = "Specify the tags as key/value pairs.")]
148+
public Hashtable Tag { get; set; }
149+
144150
#endregion
145151

146152
public override void ExecuteCmdlet()
@@ -229,7 +235,8 @@ private ManagedCluster GetNewManagedClusterParameters()
229235
sku: new Sku(name: this.Sku.ToString()),
230236
clusterUpgradeMode: this.UpgradeMode.ToString(),
231237
clusterUpgradeCadence: this.UpgradeCadence.ToString(),
232-
zonalResiliency: this.ZonalResiliency.IsPresent
238+
zonalResiliency: this.ZonalResiliency.IsPresent,
239+
tags: this.Tag?.Cast<DictionaryEntry>().ToDictionary(d => d.Key as string, d => d.Value as string)
233240
);
234241

235242
if (this.UpgradeMode == Models.ClusterUpgradeMode.Manual)

src/ServiceFabric/ServiceFabric/Commands/ManagedClusters/ManagedClusters/SetAzServiceFabricManagedCluster.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
// ----------------------------------------------------------------------------------
1313

1414
using System;
15+
using System.Collections;
16+
using System.Linq;
1517
using System.Management.Automation;
1618
using Microsoft.Azure.Commands.ResourceManager.Common.ArgumentCompleters;
1719
using Microsoft.Azure.Commands.ServiceFabric.Common;
@@ -20,6 +22,7 @@
2022
using Microsoft.Azure.Management.ServiceFabricManagedClusters;
2123
using Microsoft.Azure.Management.ServiceFabricManagedClusters.Models;
2224
using Microsoft.WindowsAzure.Commands.Common.CustomAttributes;
25+
using Microsoft.WindowsAzure.Commands.Utilities.Common;
2326

2427
namespace Microsoft.Azure.Commands.ServiceFabric.Commands
2528
{
@@ -82,6 +85,11 @@ public class SetAzServiceFabricManagedCluster : ServiceFabricManagedCmdletBase
8285
[Parameter(Mandatory = false, HelpMessage = "Run cmdlet in the background and return a Job to track progress.")]
8386
public SwitchParameter AsJob { get; set; }
8487

88+
89+
[Parameter(Mandatory = false, ParameterSetName = WithParamsByName, HelpMessage = "Specify the tags as key/value pairs.")]
90+
[Parameter(Mandatory = false, ParameterSetName = WithParamsById, HelpMessage = "Specify the tags as key/value pairs.")]
91+
public Hashtable Tag { get; set; }
92+
8593
#endregion
8694

8795
public override void ExecuteCmdlet()
@@ -140,6 +148,11 @@ private ManagedCluster GetUpdatedClusterParams()
140148
currentCluster.DnsName = DnsName;
141149
}
142150

151+
if (this.IsParameterBound(c => c.Tag))
152+
{
153+
currentCluster.Tags = this.Tag?.Cast<DictionaryEntry>().ToDictionary(d => d.Key as string, d => d.Value as string);
154+
}
155+
143156
return currentCluster;
144157
}
145158

src/ServiceFabric/ServiceFabric/help/New-AzServiceFabricManagedCluster.md

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ New-AzServiceFabricManagedCluster [-ResourceGroupName] <String> [-Name] <String>
1818
[-UpgradeMode <ClusterUpgradeMode>] [-CodeVersion <String>] [-UpgradeCadence <PSClusterUpgradeCadence>]
1919
[-ClientCertIsAdmin] -ClientCertThumbprint <String> -AdminPassword <SecureString> [-AdminUserName <String>]
2020
[-HttpGatewayConnectionPort <Int32>] [-ClientConnectionPort <Int32>] [-DnsName <String>]
21-
[-Sku <ManagedClusterSku>] [-UseTestExtension] [-ZonalResiliency] [-AsJob]
21+
[-Sku <ManagedClusterSku>] [-UseTestExtension] [-ZonalResiliency] [-AsJob] [-Tag <Hashtable>]
2222
[-DefaultProfile <IAzureContextContainer>] [-WhatIf] [-Confirm] [<CommonParameters>]
2323
```
2424

@@ -29,7 +29,7 @@ New-AzServiceFabricManagedCluster [-ResourceGroupName] <String> [-Name] <String>
2929
[-ClientCertIsAdmin] -ClientCertCommonName <String> [-ClientCertIssuerThumbprint <String[]>]
3030
-AdminPassword <SecureString> [-AdminUserName <String>] [-HttpGatewayConnectionPort <Int32>]
3131
[-ClientConnectionPort <Int32>] [-DnsName <String>] [-Sku <ManagedClusterSku>] [-UseTestExtension]
32-
[-ZonalResiliency] [-AsJob] [-DefaultProfile <IAzureContextContainer>] [-WhatIf] [-Confirm]
32+
[-ZonalResiliency] [-AsJob] [-Tag <Hashtable>] [-DefaultProfile <IAzureContextContainer>] [-WhatIf] [-Confirm]
3333
[<CommonParameters>]
3434
```
3535

@@ -43,7 +43,9 @@ This cmdlet will create a managed cluster resource without node types. To bootst
4343
$rgName = "testRG"
4444
$clusterName = "testCluster"
4545
$password = ConvertTo-SecureString -AsPlainText -Force "testpass1234!@#$"
46-
New-AzServiceFabricManagedCluster -ResourceGroupName $rgName -Location centraluseuap -ClusterName $clusterName -AdminPassword $password -Verbose
46+
$tags = @{"test"="tag"}
47+
48+
New-AzServiceFabricManagedCluster -ResourceGroupName $rgName -Location centraluseuap -ClusterName $clusterName -AdminPassword $password -Tag $tags -Verbose
4749
```
4850

4951
This command creates a cluster resource with default basic sku.
@@ -326,6 +328,21 @@ Accept pipeline input: False
326328
Accept wildcard characters: False
327329
```
328330
331+
### -Tag
332+
Specify the tags as key/value pairs.
333+
334+
```yaml
335+
Type: System.Collections.Hashtable
336+
Parameter Sets: (All)
337+
Aliases:
338+
339+
Required: False
340+
Position: Named
341+
Default value: None
342+
Accept pipeline input: False
343+
Accept wildcard characters: False
344+
```
345+
329346
### -UpgradeCadence
330347
Indicates when new cluster runtime version upgrades will be applied after they are released. By default is Wave0.
331348

src/ServiceFabric/ServiceFabric/help/Set-AzServiceFabricManagedCluster.md

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,20 @@ Set-AzServiceFabricManagedCluster [-InputObject] <PSManagedCluster> [-AsJob]
1818
[-DefaultProfile <IAzureContextContainer>] [-WhatIf] [-Confirm] [<CommonParameters>]
1919
```
2020

21-
### WithPramsByName
21+
### WithParamsByName
2222
```
2323
Set-AzServiceFabricManagedCluster [-ResourceGroupName] <String> [-Name] <String>
2424
[-UpgradeMode <ClusterUpgradeMode>] [-CodeVersion <String>] [-HttpGatewayConnectionPort <Int32>]
25-
[-ClientConnectionPort <Int32>] [-DnsName <String>] [-AsJob] [-DefaultProfile <IAzureContextContainer>]
26-
[-WhatIf] [-Confirm] [<CommonParameters>]
25+
[-ClientConnectionPort <Int32>] [-DnsName <String>] [-AsJob] [-Tag <Hashtable>]
26+
[-DefaultProfile <IAzureContextContainer>] [-WhatIf] [-Confirm] [<CommonParameters>]
2727
```
2828

2929
### ByNameById
3030
```
3131
Set-AzServiceFabricManagedCluster [-ResourceId] <String> [-UpgradeMode <ClusterUpgradeMode>]
3232
[-CodeVersion <String>] [-HttpGatewayConnectionPort <Int32>] [-ClientConnectionPort <Int32>]
33-
[-DnsName <String>] [-AsJob] [-DefaultProfile <IAzureContextContainer>] [-WhatIf] [-Confirm]
34-
[<CommonParameters>]
33+
[-DnsName <String>] [-AsJob] [-Tag <Hashtable>] [-DefaultProfile <IAzureContextContainer>] [-WhatIf]
34+
[-Confirm] [<CommonParameters>]
3535
```
3636

3737
## DESCRIPTION
@@ -43,7 +43,8 @@ Set cluster resource properties.
4343
```powershell
4444
$rgName = "testRG"
4545
$clusterName = "testCluster"
46-
Set-AzServiceFabricManagedCluster -ResourceGroupName $rgName -Name $clusterName -DnsName testnewdns -ClientConnectionPort 50000 -Verbose
46+
$tags = @{"test"="tag"}
47+
Set-AzServiceFabricManagedCluster -ResourceGroupName $rgName -Name $clusterName -DnsName testnewdns -ClientConnectionPort 50000 -Tag $tags -Verbose
4748
```
4849

4950
Update dns name and client connection port for the cluster.
@@ -213,6 +214,21 @@ Accept pipeline input: True (ByValue)
213214
Accept wildcard characters: False
214215
```
215216
217+
### -Tag
218+
Specify the tags as key/value pairs.
219+
220+
```yaml
221+
Type: System.Collections.Hashtable
222+
Parameter Sets: WithPramsByName, ByNameById
223+
Aliases:
224+
225+
Required: False
226+
Position: Named
227+
Default value: None
228+
Accept pipeline input: False
229+
Accept wildcard characters: False
230+
```
231+
216232
### -UpgradeMode
217233
Cluster code version upgrade mode. Automatic or Manual.
218234

src/ServiceFabric/ServiceFabric/help/Update-AzServiceFabricVmImage.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ Specify common target vmImage to be used for the cluster.
9393
Type: Microsoft.Azure.Commands.ServiceFabric.Models.VmImageKind
9494
Parameter Sets: (All)
9595
Aliases:
96-
Accepted values: Windows, Linux, Ubuntu, Ubuntu18_04
96+
Accepted values: Windows, Linux, Ubuntu, Ubuntu18_04, Ubuntu20_04
9797

9898
Required: True
9999
Position: Named

0 commit comments

Comments
 (0)