Skip to content

add dns name label support for container instance #5477

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

Merged
merged 5 commits into from
Feb 9, 2018
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
2 changes: 2 additions & 0 deletions src/ResourceManager/ContainerInstance/ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
- Additional information about change #1
-->
## Current Release
* Apply Azure Container Instance SDK 2018-02-01
- Support DNS name label

## Version 0.2.2
* Added Location Completer to -Location parameters allowing tab completion through valid Locations
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
<HintPath>..\..\..\packages\Microsoft.Azure.Common.2.1.0\lib\net45\Microsoft.Azure.Common.NetFramework.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Azure.Management.ContainerInstance, Version=0.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\..\..\packages\Microsoft.Azure.Management.ContainerInstance.1.0.1-preview\lib\net452\Microsoft.Azure.Management.ContainerInstance.dll</HintPath>
<HintPath>..\..\..\packages\Microsoft.Azure.Management.ContainerInstance.1.0.2-preview\lib\net452\Microsoft.Azure.Management.ContainerInstance.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Microsoft.Azure.Management.ResourceManager, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
Expand Down Expand Up @@ -193,6 +193,9 @@
<None Include="SessionRecords\Microsoft.Azure.Commands.ContainerInstance.Test.ScenarioTests.ContainerInstanceTests\TestCreateContainerGroup.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="SessionRecords\Microsoft.Azure.Commands.ContainerInstance.Test.ScenarioTests.ContainerInstanceTests\TestCreateContainerGroupWithDnsNameLabel.json" >
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="SessionRecords\Microsoft.Azure.Commands.ContainerInstance.Test.ScenarioTests.ContainerInstanceTests\TestCreateContainerGroupWithVolume.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,12 @@ public void TestCreateContainerGroupWithVolume()
{
TestController.NewInstance.RunPowerShellTest("Test-AzureRmContainerGroupWithVolumeMount");
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void TestCreateContainerGroupWithDnsNameLabel()
{
TestController.NewInstance.RunPowerShellTest("Test-AzureRmContainerGroupWithDnsNameLabel");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,57 @@ function Test-AzureRmContainerGroupWithVolumeMount
}
}

<#
.SYNOPSIS
Test New-AzureRmContainerGroup with DNS name label.
#>
function Test-AzureRmContainerGroupWithDnsNameLabel
{
$resourceGroupName = Get-RandomResourceGroupName
$containerGroupName = Get-RandomContainerGroupName
$fqdn = $containerGroupName + ".westus.azurecontainer.io"
$location = Get-ProviderLocation "Microsoft.ContainerInstance/ContainerGroups"
$image = "nginx"
$osType = "Linux"
$restartPolicy = "Never"
$port1 = 8000
$port2 = 8001

try
{
New-AzureRmResourceGroup -Name $resourceGroupName -Location $location
$containerGroupCreated = New-AzureRmContainerGroup -ResourceGroupName $resourceGroupName -Name $containerGroupName -Image $image -OsType $osType -RestartPolicy $restartPolicy -DnsNameLabel $containerGroupName -Port @($port1, $port2) -Cpu 1 -Memory 1.5

Assert-AreEqual $containerGroupCreated.ResourceGroupName $resourceGroupName
Assert-AreEqual $containerGroupCreated.Name $containerGroupName
Assert-AreEqual $containerGroupCreated.Location $location
Assert-AreEqual $containerGroupCreated.OsType $osType
Assert-AreEqual $containerGroupCreated.RestartPolicy $restartPolicy
Assert-NotNull $containerGroupCreated.IpAddress
Assert-AreEqual $containerGroupCreated.DnsNameLabel $containerGroupName
Assert-AreEqual $containerGroupCreated.Fqdn $fqdn
Assert-AreEqual $containerGroupCreated.Ports.Count 2
Assert-NotNull $containerGroupCreated.Containers
Assert-AreEqual $containerGroupCreated.Containers[0].Image $image
Assert-AreEqual $containerGroupCreated.Containers[0].Cpu 1
Assert-AreEqual $containerGroupCreated.Containers[0].MemoryInGb 1.5

$retrievedContainerGroup = Get-AzureRmContainerGroup -ResourceGroupName $resourceGroupName -Name $containerGroupName
Assert-ContainerGroup $containerGroupCreated $retrievedContainerGroup

$retrievedContainerGroupList = Get-AzureRmContainerGroup -ResourceGroupName $resourceGroupName
Assert-AreEqual $retrievedContainerGroupList.Count 1
Assert-ContainerGroup $containerGroupCreated $retrievedContainerGroupList[0]

$retrievedContainerGroup | Remove-AzureRmContainerGroup
}
finally
{
# Cleanup
Clean-ResourceGroup $resourceGroupName
}
}

<#
.SYNOPSIS
Assert a container group object.
Expand Down Expand Up @@ -155,6 +206,7 @@ function Assert-ContainerGroup
Assert-AreEqual $Actual.RestartPolicy $Expected.RestartPolicy
Assert-NotNull $Actual.IpAddress
Assert-AreEqual $Actual.Ports.Count $Expected.Ports.Count
Assert-AreEqual $Actual.DnsNameLabel $Expected.DnsNameLabel
Assert-NotNull $Actual.Containers
Assert-AreEqual $Actual.Containers[0].Image $Expected.Containers[0].Image
Assert-AreEqual $Actual.Containers[0].Cpu $Expected.Containers[0].Cpu
Expand Down

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
</ItemGroup>
<ItemGroup>
<Reference Include="Microsoft.Azure.Management.ContainerInstance, Version=0.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\..\..\packages\Microsoft.Azure.Management.ContainerInstance.1.0.1-preview\lib\net452\Microsoft.Azure.Management.ContainerInstance.dll</HintPath>
<HintPath>..\..\..\packages\Microsoft.Azure.Management.ContainerInstance.1.0.2-preview\lib\net452\Microsoft.Azure.Management.ContainerInstance.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,10 +143,13 @@ public ContainerGroup CreateContainerGroup(ContainerGroupCreationParameters para
RestartPolicy = parameters.RestartPolicy
};

if (string.Equals(IpAddress.Type, parameters.IpAddressType, StringComparison.OrdinalIgnoreCase))
if (string.Equals(IpAddress.Type, parameters.IpAddressType, StringComparison.OrdinalIgnoreCase) ||
!string.IsNullOrEmpty(parameters.DnsNameLabel))
{
container.Ports = parameters.Ports.Select(p => new ContainerPort(p)).ToList();
containerGroup.IpAddress = new IpAddress(parameters.Ports.Select(p => new Port(p)).ToList());
containerGroup.IpAddress = new IpAddress(
ports: parameters.Ports.Select(p => new Port(p)).ToList(),
dnsNameLabel: parameters.DnsNameLabel);
}

if (!string.IsNullOrEmpty(parameters.RegistryServer))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,12 @@ public class NewAzureContainerGroupCommand : ContainerInstanceCmdletBase
IgnoreCase = true)]
public string IpAddressType { get; set; }

[Parameter(
Mandatory = false,
HelpMessage = "The DNS name label for the IP address.")]
[ValidateNotNullOrEmpty]
public string DnsNameLabel { get; set; }

[Parameter(
Mandatory = false,
HelpMessage = "The port(s) to open. Default: [80]")]
Expand Down Expand Up @@ -183,6 +189,7 @@ public override void ExecuteCmdlet()
OsType = this.OsType ?? ContainerGroupCreationParameters.DefaultOsType,
RestartPolicy = this.RestartPolicy ?? ContainerGroupRestartPolicy.Always,
IpAddressType = this.IpAddressType,
DnsNameLabel = this.DnsNameLabel,
Ports = this.Port ?? ContainerGroupCreationParameters.DefaultPorts,
ContainerImage = this.Image,
EnvironmentVariables = this.ConvertHashtableToDictionary(this.EnvironmentVariable),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,11 @@ public class ContainerGroupCreationParameters
/// </summary>
public string IpAddressType { get; set; }

/// <summary>
/// Gets or sets the DNS name label.
/// </summary>
public string DnsNameLabel { get; set; }

/// <summary>
/// Gets or sets the ports.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,16 @@ public string ResourceGroupName
/// </summary>
public string IpAddress { get; set; }

/// <summary>
/// Gets or sets the DNS name label.
/// </summary>
public string DnsNameLabel { get; set; }

/// <summary>
/// Gets the FQDN.
/// </summary>
public string Fqdn { get; set; }

/// <summary>
/// Gets or sets the ports.
/// </summary>
Expand Down Expand Up @@ -131,6 +141,8 @@ public static PSContainerGroup FromContainerGroup(ContainerGroup containerGroup)
ImageRegistryCredentials = containerGroup?.ImageRegistryCredentials,
RestartPolicy = containerGroup?.RestartPolicy,
IpAddress = containerGroup?.IpAddress?.Ip,
DnsNameLabel = containerGroup?.IpAddress?.DnsNameLabel,
Fqdn = containerGroup?.IpAddress?.Fqdn,
Ports = containerGroup?.IpAddress?.Ports?.Select(p => ContainerInstanceAutoMapperProfile.Mapper.Map<PSPort>(p)).ToList(),
OsType = containerGroup?.OsType,
Volumes = containerGroup?.Volumes,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ The container group Name.
```yaml
Type: String
Parameter Sets: GetContainerGroupInResourceGroupParamSet
Aliases:
Aliases:

Required: True
Position: 1
Expand All @@ -144,7 +144,7 @@ The resource Group Name.
```yaml
Type: String
Parameter Sets: ListContainerGroupParamSet
Aliases:
Aliases:

Required: False
Position: 0
Expand All @@ -156,7 +156,7 @@ Accept wildcard characters: False
```yaml
Type: String
Parameter Sets: GetContainerGroupInResourceGroupParamSet
Aliases:
Aliases:

Required: True
Position: 0
Expand All @@ -171,7 +171,7 @@ The resource id.
```yaml
Type: String
Parameter Sets: GetContainerGroupByResourceIdParamSet
Aliases:
Aliases:

Required: True
Position: Named
Expand All @@ -194,4 +194,3 @@ This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable
## NOTES

## RELATED LINKS

Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ The container group name.
```yaml
Type: String
Parameter Sets: GetContainerInstanceLogByNamesParamSet
Aliases:
Aliases:

Required: True
Position: Named
Expand Down Expand Up @@ -119,7 +119,7 @@ The input container group object.
```yaml
Type: PSContainerGroup
Parameter Sets: GetContainerInstanceLogByPSContainerGroupParamSet
Aliases:
Aliases:

Required: True
Position: Named
Expand All @@ -135,7 +135,7 @@ Default: the same as the container group name
```yaml
Type: String
Parameter Sets: (All)
Aliases:
Aliases:

Required: False
Position: Named
Expand All @@ -150,7 +150,7 @@ The resource group name.
```yaml
Type: String
Parameter Sets: GetContainerInstanceLogByNamesParamSet
Aliases:
Aliases:

Required: True
Position: 0
Expand All @@ -165,7 +165,7 @@ The resource id.
```yaml
Type: String
Parameter Sets: GetContainerInstanceLogByResourceIdParamSet
Aliases:
Aliases:

Required: True
Position: Named
Expand All @@ -181,7 +181,7 @@ If not specify, the cmdlet will return up to 4MB tailed log
```yaml
Type: Int32
Parameter Sets: (All)
Aliases:
Aliases:

Required: False
Position: Named
Expand All @@ -204,4 +204,3 @@ This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable
## NOTES

## RELATED LINKS

Loading