Skip to content
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
7 changes: 7 additions & 0 deletions src/Aks/Aks.Test/ScenarioTests/KubernetesTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,12 @@ public void TestAzureKubernetes()
{
TestController.NewInstance.RunPowerShellTest(_logger, "Test-NewAzAks");
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void TestAzureKubernetesAddons()
{
TestController.NewInstance.RunPowerShellTest(_logger, "Test-NewAzAksAddons");
}
}
}
28 changes: 28 additions & 0 deletions src/Aks/Aks.Test/ScenarioTests/KubernetesTests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -145,3 +145,31 @@ function Test-NewAzAks
Remove-AzResourceGroup -Name $resourceGroupName -Force
}
}

function Test-NewAzAksAddons
{
# Setup
$resourceGroupName = Get-RandomResourceGroupName
$kubeClusterName = Get-RandomClusterName
$location = Get-ProviderLocation "Microsoft.ContainerService/managedClusters"

try
{
New-AzResourceGroup -Name $resourceGroupName -Location $location

New-AzAks -ResourceGroupName $resourceGroupName -Name $kubeClusterName -AddOnNameToBeEnabled KubeDashboard,HttpApplicationRouting
$cluster = Get-AzAks -ResourceGroupName $resourceGroupName -Name $kubeClusterName
Assert-AreEqual $true $cluster.AddonProfiles['httpapplicationrouting'].Enabled
Assert-AreEqual $true $cluster.AddonProfiles['httpapplicationrouting'].Enabled

$cluster = $cluster | Disable-AzAksAddon -Name HttpApplicationRouting
Assert-AreEqual $false $cluster.AddonProfiles['httpapplicationrouting'].Enabled
$cluster = $cluster | Enable-AzAksAddon -Name HttpApplicationRouting
Assert-AreEqual $true $cluster.AddonProfiles['httpapplicationrouting'].Enabled
$cluster | Remove-AzAks -Force
}
finally
{
Remove-AzResourceGroup -Name $resourceGroupName -Force
}
}

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/Aks/Aks/Az.Aks.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ CmdletsToExport = 'Get-AzAksCluster', 'New-AzAksCluster', 'Remove-AzAksCluster',
'Import-AzAksCredential', 'Start-AzAksDashboard',
'Stop-AzAksDashboard', 'Set-AzAksCluster', 'New-AzAksNodePool',
'Update-AzAksNodePool', 'Remove-AzAksNodePool', 'Get-AzAksNodePool',
'Install-AzAksKubectl', 'Get-AzAksVersion'
'Install-AzAksKubectl', 'Get-AzAksVersion', 'Enable-AzAksAddOn', 'Disable-AzAksAddOn'

# Variables to export from this module
# VariablesToExport = @()
Expand Down
6 changes: 4 additions & 2 deletions src/Aks/Aks/ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@
- Additional information about change #1
-->
## Upcoming Release
* Added client side parameter validation logic for `New-AzAksCluster`, `Set-AzAksCluster` and `New-AzAksNodePool`.
* Added parameter `GenerateSshKey` for `New-AzAksCluster`.
* Added client side parameter validation logic for `New-AzAksCluster`, `Set-AzAksCluster` and `New-AzAksNodePool`. [#12372]
* Added support for add-ons in `New-AzAksCluster`. [#11239]
* Added cmdlets `Enable-AzAksAddOn` and `Disable-AzAksAddOn` for add-ons. [#11239]
* Added parameter `GenerateSshKey` for `New-AzAksCluster`. [#12371]
* Updated api version to 2020-06-01.

## Version 1.2.0
Expand Down
14 changes: 14 additions & 0 deletions src/Aks/Aks/Commands/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
// limitations under the License.
// ----------------------------------------------------------------------------------

using System.Collections.Generic;

namespace Microsoft.Azure.Commands.Aks
{
public static class Constants
Expand All @@ -27,5 +29,17 @@ public static class Constants
public const string ParentObjectParameterSet = "ParentObjectParameterSet";

public const string NodePool = "AksNodePool";


public readonly static IDictionary<string, string> AddOnUserReadNameToServiceNameMapper = new Dictionary<string, string>
{
{ "HttpApplicationRouting", "httpapplicationrouting" },
{ "Monitoring", "omsagent" },
{ "VirtualNode", "aciConnector" },
{ "AzurePolicy", "azurepolicy " },
{ "KubeDashboard", "kubeDashboard" },
};
public const string AddOnNameMonitoring = "Monitoring";
public const string AddOnNameVirtualNode = "VirtualNode";
}
}
55 changes: 55 additions & 0 deletions src/Aks/Aks/Commands/DisableAzureRmAddons.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// ----------------------------------------------------------------------------------
//
// Copyright Microsoft Corporation
// 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,
// 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.
// ----------------------------------------------------------------------------------


using Microsoft.Azure.Commands.Aks.Models;
using Microsoft.Azure.Commands.Aks.Properties;
using Microsoft.Azure.Commands.Aks.Utils;
using Microsoft.Azure.Management.ContainerService.Models;
using Microsoft.WindowsAzure.Commands.Utilities.Common;

using System;
using System.Collections.Generic;
using System.Management.Automation;
using System.Runtime.ExceptionServices;
using System.Text;

namespace Microsoft.Azure.Commands.Aks.Commands
{
[Cmdlet(VerbsLifecycle.Disable, ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "AksAddOn", DefaultParameterSetName = DefaultParamSet, SupportsShouldProcess = true)]
[OutputType(typeof(PSKubernetesCluster))]
public class DisableAzureRmAddons : UpdateAddonsBase
{
protected override IDictionary<string, ManagedClusterAddonProfile> UpdateAddonsProfile(IDictionary<string, ManagedClusterAddonProfile> addonProfiles)
{
foreach (var addOn in Name)
{
string addonServiceName = Constants.AddOnUserReadNameToServiceNameMapper.GetValueOrDefault(addOn, null);
if (addonServiceName == null)
{
throw new ArgumentException(string.Format(Resources.AddonNotDefined, addOn));
}
if (!addonProfiles.ContainsKey(addonServiceName))
{
throw new ArgumentException(string.Format(Resources.AddonIsNotInstalled, addOn));
}
ManagedClusterAddonProfile addonProfile = addonProfiles[addonServiceName];
addonProfile.Config = null;
addonProfile.Enabled = false;
}

return addonProfiles;
}
}
}
50 changes: 50 additions & 0 deletions src/Aks/Aks/Commands/EnableAzureRmAddons.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// ----------------------------------------------------------------------------------
//
// Copyright Microsoft Corporation
// 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,
// 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.
// ----------------------------------------------------------------------------------


using Microsoft.Azure.Commands.Aks.Models;
using Microsoft.Azure.Commands.Aks.Properties;
using Microsoft.Azure.Commands.Aks.Utils;
using Microsoft.Azure.Management.ContainerService.Models;
using Microsoft.WindowsAzure.Commands.Utilities.Common;

using System;
using System.Collections.Generic;
using System.Management.Automation;
using System.Text;

namespace Microsoft.Azure.Commands.Aks.Commands
{
[Cmdlet(VerbsLifecycle.Enable, ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "AksAddOn", DefaultParameterSetName = DefaultParamSet, SupportsShouldProcess = true)]
[OutputType(typeof(PSKubernetesCluster))]
public class EnableAzureRmAddons : UpdateAddonsBase
{
[Parameter(Mandatory = false,
ValueFromPipelineByPropertyName = true,
HelpMessage = "Resource Id of the workspace of Monitoring.")]
[ValidateNotNullOrEmpty]
public string WorkspaceResourceId { get; set; }

[Parameter(Mandatory = false,
ValueFromPipelineByPropertyName = true,
HelpMessage = "Subnet name of VirtualNode.")]
[ValidateNotNullOrEmpty]
public string SubnetName { get; set; }

protected override IDictionary<string, ManagedClusterAddonProfile> UpdateAddonsProfile(IDictionary<string, ManagedClusterAddonProfile> addonProfiles)
{
return AddonUtils.EnableAddonsProfile(addonProfiles, Name, WorkspaceResourceId, SubnetName);
}
}
}
36 changes: 35 additions & 1 deletion src/Aks/Aks/Commands/NewKubeBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
// ----------------------------------------------------------------------------------


using System;
using System.Collections.Generic;
using System.IO;
using System.Management.Automation;
using System.Security;
using Microsoft.Azure.Commands.Aks.Properties;
Expand Down Expand Up @@ -61,6 +63,23 @@ public abstract class NewKubeBase : CreateOrUpdateKubeBase
[PSArgumentCompleter("Delete", "Deallocate")]
public string NodeScaleSetEvictionPolicy { get; set; }

[Parameter(Mandatory = false, HelpMessage = "Add-on names to be enabled when cluster is created.")]
[ValidateNotNullOrEmpty()]
[PSArgumentCompleter("HttpApplicationRouting", "Monitoring", "VirtualNode", "AzurePolicy", "KubeDashboard")]
public string[] AddOnNameToBeEnabled { get; set; }

[Parameter(Mandatory = false,
ValueFromPipelineByPropertyName = true,
HelpMessage = "Resource Id of the workspace of Monitoring addon.")]
[ValidateNotNullOrEmpty]
public string WorkspaceResourceId { get; set; }

[Parameter(Mandatory = false,
ValueFromPipelineByPropertyName = true,
HelpMessage = "Subnet name of VirtualNode addon.")]
[ValidateNotNullOrEmpty]
public string SubnetName { get; set; }

///// <summary>The client AAD application ID.</summary>
//[Parameter(Mandatory = false, HelpMessage = "The client AAD application ID.")]
//public string AadProfileClientAppId { get; set; }
Expand All @@ -72,7 +91,7 @@ public abstract class NewKubeBase : CreateOrUpdateKubeBase
///// <summary>The server AAD application secret.</summary>
//[Parameter(Mandatory = false, HelpMessage = "The server AAD application secret.")]
//public string AadProfileServerAppSecret { get; set; }

//// <summary> The AAD tenant ID to use for authentication. If not specified, will use the tenant of the deployment subscription. </summary>
//[Parameter(Mandatory = false,
// HelpMessage =
Expand Down Expand Up @@ -135,6 +154,8 @@ protected override ManagedCluster BuildNewCluster()

var networkProfile = GetNetworkProfile();

var addonProfiles = CreateAddonsProfiles();

WriteVerbose(string.Format(Resources.DeployingYourManagedKubeCluster, AcsSpFilePath));

var managedCluster = new ManagedCluster(
Expand All @@ -148,6 +169,7 @@ protected override ManagedCluster BuildNewCluster()
windowsProfile: windowsProfile,
servicePrincipalProfile: spProfile,
aadProfile: aadProfile,
addonProfiles: addonProfiles,
networkProfile: networkProfile);

if(EnableRbac.IsPresent)
Expand Down Expand Up @@ -245,5 +267,17 @@ private ManagedClusterAADProfile GetAadProfile()
//}
return aadProfile;
}

private IDictionary<string, ManagedClusterAddonProfile> CreateAddonsProfiles()
{
if (this.IsParameterBound(c => c.AddOnNameToBeEnabled))
{
Dictionary<string, ManagedClusterAddonProfile> addonProfiles = new Dictionary<string, ManagedClusterAddonProfile>();
return AddonUtils.EnableAddonsProfile(addonProfiles, AddOnNameToBeEnabled, WorkspaceResourceId, SubnetName);
} else
{
return null;
}
}
}
}
116 changes: 116 additions & 0 deletions src/Aks/Aks/Commands/UpdateAddonsBase.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
// ----------------------------------------------------------------------------------
//
// Copyright Microsoft Corporation
// 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,
// 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.
// ----------------------------------------------------------------------------------

using Microsoft.Azure.Commands.Aks.Models;
using Microsoft.Azure.Commands.Aks.Properties;
using Microsoft.Azure.Commands.ResourceManager.Common.ArgumentCompleters;
using Microsoft.Azure.Management.ContainerService;
using Microsoft.Azure.Management.ContainerService.Models;
using Microsoft.Azure.Management.Internal.Resources.Utilities.Models;
using Microsoft.Rest.Azure;

using System;
using System.Collections.Generic;
using System.Management.Automation;
using System.Text;

namespace Microsoft.Azure.Commands.Aks.Commands
{
public abstract class UpdateAddonsBase : KubeCmdletBase
{
private const string IdParameterSet = "IdParameterSet";
private const string InputObjectParameterSet = "InputObjectParameterSet";
protected const string DefaultParamSet = "defaultParameterSet";

[Parameter(
Position = 0,
Mandatory = true,
ParameterSetName = DefaultParamSet,
HelpMessage = "Resource Group Name.")]
[ResourceGroupCompleter()]
[ValidateNotNullOrEmpty]
public string ResourceGroupName { get; set; }

[Parameter(
Position = 1,
Mandatory = true,
ParameterSetName = DefaultParamSet,
HelpMessage = "Kubernetes managed cluster Name.")]
[ValidateNotNullOrEmpty]
public string ClusterName { get; set; }

[Parameter(Mandatory = true,
ParameterSetName = InputObjectParameterSet,
ValueFromPipeline = true,
HelpMessage = "A PSKubernetesCluster object, normally passed through the pipeline.")]
[ValidateNotNullOrEmpty]
public PSKubernetesCluster ClusterObject { get; set; }

[Parameter(Mandatory = false, HelpMessage = "Add-on names to be enabled when cluster is created.")]
[ValidateNotNullOrEmpty()]
[PSArgumentCompleter("HttpApplicationRouting", "Monitoring", "VirtualNode", "AzurePolicy", "KubeDashboard")]
public string[] Name { get; set; }

public override void ExecuteCmdlet()
{
ManagedCluster cluster = null;
switch (ParameterSetName)
{
case InputObjectParameterSet:
{
WriteVerbose(Resources.UsingClusterFromPipeline);
cluster = PSMapper.Instance.Map<ManagedCluster>(ClusterObject);
var resource = new ResourceIdentifier(cluster.Id);
ResourceGroupName = resource.ResourceGroupName;
ClusterName = resource.ResourceName;
break;
}
}

var msg = $"{Name} in {ResourceGroupName}";

if (ShouldProcess(msg, Resources.UpdateOrCreateAManagedKubernetesCluster))
{
if (cluster == null)
{
cluster = GetManagedClusterWithResourceGroupNameAndName();
}
cluster.AddonProfiles = UpdateAddonsProfile(cluster.AddonProfiles);
cluster.ServicePrincipalProfile = null;
cluster.AadProfile = null;
cluster.AgentPoolProfiles = null;
var kubeCluster = Client.ManagedClusters.CreateOrUpdate(ResourceGroupName, ClusterName, cluster);
WriteObject(PSMapper.Instance.Map<PSKubernetesCluster>(kubeCluster));
}
}

protected abstract IDictionary<string, ManagedClusterAddonProfile> UpdateAddonsProfile(IDictionary<string, ManagedClusterAddonProfile> addonProfiles);

private ManagedCluster GetManagedClusterWithResourceGroupNameAndName()
{
try
{
var cluster = Client.ManagedClusters.Get(ResourceGroupName, ClusterName);
WriteVerbose(string.Format(Resources.ClusterExists, cluster.Id));
return cluster;
}
catch (CloudException exception)
{
// Write exception out to error channel.
WriteError(new ErrorRecord(exception, Resources.ClusterDoesNotExist, ErrorCategory.CloseError, null));
return null;
}
}
}
}
Loading