Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tag support to managed cluster cmdlets #18473

Merged
merged 3 commits into from
Jun 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@ function Test-CreateBasicCluster
$testClientTp = "123BDACDCDFB2C7B250192C6078E47D1E1DB119B"
Assert-ThrowsContains { Get-AzServiceFabricManagedCluster -ResourceGroupName $resourceGroupName -Name $clusterName } "NotFound"

$tags = @{"test"="tag"}

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

$cluster = Get-AzServiceFabricManagedCluster -ResourceGroupName $resourceGroupName -Name $clusterName
Assert-AreEqual "Deploying" $cluster.ClusterState
$clusterFromGet = Get-AzServiceFabricManagedCluster -ResourceGroupName $resourceGroupName -Name $clusterName
Assert-AreEqual "Ready" $clusterFromGet.ClusterState
Assert-HashtableEqual $cluster.Tags $clusterFromGet.Tags

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

$removeResponse = $cluster | Remove-AzServiceFabricManagedCluster -PassThru
$removeResponse = $clusterFromGet | Remove-AzServiceFabricManagedCluster -PassThru
Assert-True { $removeResponse }

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

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions src/ServiceFabric/ServiceFabric/ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
-->
## Upcoming Release
* Fixed typo in verbose log message.
* Added Tag support for managed cluster create and update

## Version 3.0.2
* Added support for Ubuntu 20.04 vm image.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@
// ----------------------------------------------------------------------------------

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

[Parameter(Mandatory = false, ParameterSetName = ClientCertByTp, HelpMessage = "Specify the tags as key/value pairs.")]
[Parameter(Mandatory = false, ParameterSetName = ClientCertByCn, HelpMessage = "Specify the tags as key/value pairs.")]
public Hashtable Tag { get; set; }

#endregion

public override void ExecuteCmdlet()
Expand Down Expand Up @@ -229,7 +235,8 @@ private ManagedCluster GetNewManagedClusterParameters()
sku: new Sku(name: this.Sku.ToString()),
clusterUpgradeMode: this.UpgradeMode.ToString(),
clusterUpgradeCadence: this.UpgradeCadence.ToString(),
zonalResiliency: this.ZonalResiliency.IsPresent
zonalResiliency: this.ZonalResiliency.IsPresent,
tags: this.Tag?.Cast<DictionaryEntry>().ToDictionary(d => d.Key as string, d => d.Value as string)
);

if (this.UpgradeMode == Models.ClusterUpgradeMode.Manual)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
// ----------------------------------------------------------------------------------

using System;
using System.Collections;
using System.Linq;
using System.Management.Automation;
using Microsoft.Azure.Commands.ResourceManager.Common.ArgumentCompleters;
using Microsoft.Azure.Commands.ServiceFabric.Common;
Expand All @@ -20,6 +22,7 @@
using Microsoft.Azure.Management.ServiceFabricManagedClusters;
using Microsoft.Azure.Management.ServiceFabricManagedClusters.Models;
using Microsoft.WindowsAzure.Commands.Common.CustomAttributes;
using Microsoft.WindowsAzure.Commands.Utilities.Common;

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


[Parameter(Mandatory = false, ParameterSetName = WithParamsByName, HelpMessage = "Specify the tags as key/value pairs.")]
[Parameter(Mandatory = false, ParameterSetName = WithParamsById, HelpMessage = "Specify the tags as key/value pairs.")]
public Hashtable Tag { get; set; }

#endregion

public override void ExecuteCmdlet()
Expand Down Expand Up @@ -140,6 +148,11 @@ private ManagedCluster GetUpdatedClusterParams()
currentCluster.DnsName = DnsName;
}

if (this.IsParameterBound(c => c.Tag))
{
currentCluster.Tags = this.Tag?.Cast<DictionaryEntry>().ToDictionary(d => d.Key as string, d => d.Value as string);
}

return currentCluster;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ New-AzServiceFabricManagedCluster [-ResourceGroupName] <String> [-Name] <String>
[-UpgradeMode <ClusterUpgradeMode>] [-CodeVersion <String>] [-UpgradeCadence <PSClusterUpgradeCadence>]
[-ClientCertIsAdmin] -ClientCertThumbprint <String> -AdminPassword <SecureString> [-AdminUserName <String>]
[-HttpGatewayConnectionPort <Int32>] [-ClientConnectionPort <Int32>] [-DnsName <String>]
[-Sku <ManagedClusterSku>] [-UseTestExtension] [-ZonalResiliency] [-AsJob]
[-Sku <ManagedClusterSku>] [-UseTestExtension] [-ZonalResiliency] [-AsJob] [-Tag <Hashtable>]
LukeSlev marked this conversation as resolved.
Show resolved Hide resolved
[-DefaultProfile <IAzureContextContainer>] [-WhatIf] [-Confirm] [<CommonParameters>]
```

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

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

New-AzServiceFabricManagedCluster -ResourceGroupName $rgName -Location centraluseuap -ClusterName $clusterName -AdminPassword $password -Tag $tags -Verbose
```

This command creates a cluster resource with default basic sku.
Expand Down Expand Up @@ -326,6 +328,21 @@ Accept pipeline input: False
Accept wildcard characters: False
```

### -Tag
Specify the tags as key/value pairs.

```yaml
Type: System.Collections.Hashtable
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```

### -UpgradeCadence
Indicates when new cluster runtime version upgrades will be applied after they are released. By default is Wave0.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,20 @@ Set-AzServiceFabricManagedCluster [-InputObject] <PSManagedCluster> [-AsJob]
[-DefaultProfile <IAzureContextContainer>] [-WhatIf] [-Confirm] [<CommonParameters>]
```

### WithPramsByName
### WithParamsByName
```
Set-AzServiceFabricManagedCluster [-ResourceGroupName] <String> [-Name] <String>
[-UpgradeMode <ClusterUpgradeMode>] [-CodeVersion <String>] [-HttpGatewayConnectionPort <Int32>]
[-ClientConnectionPort <Int32>] [-DnsName <String>] [-AsJob] [-DefaultProfile <IAzureContextContainer>]
[-WhatIf] [-Confirm] [<CommonParameters>]
[-ClientConnectionPort <Int32>] [-DnsName <String>] [-AsJob] [-Tag <Hashtable>]
LukeSlev marked this conversation as resolved.
Show resolved Hide resolved
[-DefaultProfile <IAzureContextContainer>] [-WhatIf] [-Confirm] [<CommonParameters>]
```

### ByNameById
```
Set-AzServiceFabricManagedCluster [-ResourceId] <String> [-UpgradeMode <ClusterUpgradeMode>]
[-CodeVersion <String>] [-HttpGatewayConnectionPort <Int32>] [-ClientConnectionPort <Int32>]
[-DnsName <String>] [-AsJob] [-DefaultProfile <IAzureContextContainer>] [-WhatIf] [-Confirm]
[<CommonParameters>]
[-DnsName <String>] [-AsJob] [-Tag <Hashtable>] [-DefaultProfile <IAzureContextContainer>] [-WhatIf]
[-Confirm] [<CommonParameters>]
```

## DESCRIPTION
Expand All @@ -43,7 +43,8 @@ Set cluster resource properties.
```powershell
$rgName = "testRG"
$clusterName = "testCluster"
Set-AzServiceFabricManagedCluster -ResourceGroupName $rgName -Name $clusterName -DnsName testnewdns -ClientConnectionPort 50000 -Verbose
$tags = @{"test"="tag"}
Set-AzServiceFabricManagedCluster -ResourceGroupName $rgName -Name $clusterName -DnsName testnewdns -ClientConnectionPort 50000 -Tag $tags -Verbose
```

Update dns name and client connection port for the cluster.
Expand Down Expand Up @@ -213,6 +214,21 @@ Accept pipeline input: True (ByValue)
Accept wildcard characters: False
```

### -Tag
Specify the tags as key/value pairs.

```yaml
Type: System.Collections.Hashtable
Parameter Sets: WithPramsByName, ByNameById
Aliases:

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```

### -UpgradeMode
Cluster code version upgrade mode. Automatic or Manual.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ Specify common target vmImage to be used for the cluster.
Type: Microsoft.Azure.Commands.ServiceFabric.Models.VmImageKind
Parameter Sets: (All)
Aliases:
Accepted values: Windows, Linux, Ubuntu, Ubuntu18_04
Accepted values: Windows, Linux, Ubuntu, Ubuntu18_04, Ubuntu20_04

Required: True
Position: Named
Expand Down