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

[Aks]Update the logic for -NodeImageOnly #18323

Merged
merged 2 commits into from
May 31, 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
3 changes: 2 additions & 1 deletion src/Aks/Aks.Test/ScenarioTests/AksTestRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,9 @@ protected AksTestRunner(ITestOutputHelper output)
AzureSession.Instance.DataStore = new MemoryDataStore();
var home = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);
var dir = Path.GetDirectoryName(new Uri(Assembly.GetExecutingAssembly().CodeBase).AbsolutePath);
var subscription = HttpMockServer.Variables["SubscriptionId"];

var currentEnvironment = TestEnvironmentFactory.GetTestEnvironment();
var subscription = currentEnvironment.ConnectionString.KeyValuePairs["SubscriptionId"];
string spn = null;
string spnSecret = null;
if (currentEnvironment.ConnectionString.KeyValuePairs.ContainsKey("ServicePrincipal"))
Expand Down
5 changes: 2 additions & 3 deletions src/Aks/Aks.Test/ScenarioTests/KubernetesTests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -229,20 +229,19 @@ function Test-UpgradeKubernetesVersion
$kubeClusterName = Get-RandomClusterName
$location = Get-ProviderLocation "Microsoft.ContainerService/managedClusters"
$nodeVmSize = "Standard_D2_v2"
$kubeVersion = "1.21.2"
$kubeVersion = "1.23.3"

try
{
New-AzResourceGroup -Name $resourceGroupName -Location 'eastus'

$credObject = $(createTestCredential "a6148f60-19b8-49b8-a5a5-54945aec926e" "uJa7Q~pyzJpxnv7it0f0Co~SL8qQWFL2t45DW")
$credObject = $(createTestCredential "a6148f60-19b8-49b8-a5a5-54945aec926e" "xde7Q~bVRBoBzggfXn3Zw1uCqzRuLduEFPJXw")
New-AzAksCluster -ResourceGroupName $resourceGroupName -Name $kubeClusterName -NodeVmSize $nodeVmSize -ServicePrincipalIdAndSecret $credObject -NodeVmSetType VirtualMachineScaleSets
#New-AzAksNodePool -ResourceGroupName $resourceGroupName -ClusterName $kubeClusterName -Name pool2 -VmSetType VirtualMachineScaleSets
Set-AzAksCluster -ResourceGroupName $resourceGroupName -Name $kubeClusterName -KubernetesVersion $kubeVersion -ControlPlaneOnly
Set-AzAksCluster -ResourceGroupName $resourceGroupName -Name $kubeClusterName -NodeImageOnly
$cluster = Get-AzAksCluster -ResourceGroupName $resourceGroupName -Name $kubeClusterName
Assert-AreEqual $kubeVersion $cluster.KubernetesVersion
Assert-AreEqual $kubeVersion $cluster.AgentPoolProfiles[0].OrchestratorVersion
}
finally
{
Expand Down

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions src/Aks/Aks/ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
- Additional information about change #1
-->
## Upcoming Release
* Updated the logic of `Set-AzAksCluster` for parameter `NodeImageOnly`.
* Added parameter `NodeImageOnly` for `Update-AzAksNodePool`.

## Version 4.1.0
* Removed these aliases:
Expand Down
1 change: 0 additions & 1 deletion src/Aks/Aks/Commands/GetAzureRmAks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@

namespace Microsoft.Azure.Commands.Aks
{
[GenericBreakingChange("Get-AzAks will be removed in the next major release. Please use Get-AzAksCluster instead of Get-AzAks")]
[Cmdlet("Get", ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "AksCluster", DefaultParameterSetName = ResourceGroupParameterSet)]
[OutputType(typeof(PSKubernetesCluster))]
public class GetAzureRmAks : KubeCmdletBase
Expand Down
1 change: 0 additions & 1 deletion src/Aks/Aks/Commands/NewAzureRmAks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@

namespace Microsoft.Azure.Commands.Aks
{
[GenericBreakingChange("New-AzAks will be removed in the next major release. Please use New-AzAksCluster instead of New-AzAks")]
[Cmdlet("New", ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "AksCluster", DefaultParameterSetName = DefaultParamSet, SupportsShouldProcess = true)]
[OutputType(typeof(PSKubernetesCluster))]
public class NewAzureRmAks : CreateOrUpdateKubeBase
Expand Down
1 change: 0 additions & 1 deletion src/Aks/Aks/Commands/RemoveAzureRmAks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@

namespace Microsoft.Azure.Commands.Aks
{
[GenericBreakingChange("Remove-AzAks will be removed in the next major release. Please use Remove-AzAksCluster instead of Remove-AzAks")]
[Cmdlet("Remove", ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "AksCluster", SupportsShouldProcess = true, DefaultParameterSetName = GroupNameParameterSet)]
[OutputType(typeof(bool))]
public class RemoveAzureRmAks : KubeCmdletBase
Expand Down
15 changes: 2 additions & 13 deletions src/Aks/Aks/Commands/SetAzureRmAks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@

namespace Microsoft.Azure.Commands.Aks
{
[GenericBreakingChange("Set-AzAks will be removed in the next major release. Please use Set-AzAksCluster instead of Set-AzAks")]
[Cmdlet("Set", ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "AksCluster", DefaultParameterSetName = DefaultParamSet, SupportsShouldProcess = true)]
[OutputType(typeof(PSKubernetesCluster))]
public class SetAzureRmAks : CreateOrUpdateKubeBase
Expand All @@ -59,7 +58,7 @@ public class SetAzureRmAks : CreateOrUpdateKubeBase
public string AcrNameToDetach { get; set; }


[Parameter(Mandatory = false, HelpMessage = "Will only upgrade node pool version to align control plane.")]
[Parameter(Mandatory = false, HelpMessage = "Will only upgrade the node image of agent pools.")]
public SwitchParameter NodeImageOnly { get; set; }

[Parameter(Mandatory = false, HelpMessage = "Will only upgrade control plane to target version.")]
Expand Down Expand Up @@ -290,17 +289,7 @@ public override void ExecuteCmdlet()
throw new AzPSApplicationException(Resources.NotUsingVirtualMachineScaleSets);
}
var agentPoolClient = Client.AgentPools.Get(ResourceGroupName, Name, agentPoolProfile.Name);
AgentPool parameter = new AgentPool
{
Count = agentPoolClient.Count,
VmSize = agentPoolClient.VmSize,
OsDiskSizeGB = agentPoolClient.OsDiskSizeGB,
MaxPods = agentPoolClient.MaxPods,
Mode = agentPoolClient.Mode,
OsType = agentPoolClient.OsType,
OrchestratorVersion = cluster.KubernetesVersion,
};
Client.AgentPools.CreateOrUpdate(ResourceGroupName, Name, agentPoolProfile.Name, parameter);
Client.AgentPools.UpgradeNodeImageVersion(ResourceGroupName, Name, agentPoolProfile.Name);
}
cluster = Client.ManagedClusters.Get(ResourceGroupName, Name);
WriteObject(PSMapper.Instance.Map<PSKubernetesCluster>(cluster));
Expand Down
20 changes: 20 additions & 0 deletions src/Aks/Aks/Commands/UpdateAzureRmAksNodePool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
using System.Management.Automation;
using Microsoft.Azure.Commands.Aks.Models;
using Microsoft.Azure.Commands.Aks.Properties;
using Microsoft.Azure.Commands.Common.Exceptions;
using Microsoft.Azure.Commands.ResourceManager.Common;
using Microsoft.Azure.Commands.ResourceManager.Common.ArgumentCompleters;
using Microsoft.Azure.Management.ContainerService;
Expand Down Expand Up @@ -64,6 +65,9 @@ public class UpdateAzureRmAksNodePool : NewOrUpdateAgentPoolBase
[Parameter(Mandatory = false, HelpMessage = "The number of nodes for the node pools.")]
public int NodeCount { get; set; }

[Parameter(Mandatory = false, HelpMessage = "Will only upgrade the node image of agent pools.")]
public SwitchParameter NodeImageOnly { get; set; }

[Parameter(Mandatory = false, HelpMessage = "Run cmdlet in the background")]
public SwitchParameter AsJob { get; set; }

Expand Down Expand Up @@ -140,6 +144,22 @@ public override void ExecuteCmdlet()
pool.Count = NodeCount;
}

if (this.IsParameterBound(c => c.NodeImageOnly))
{
if (this.IsParameterBound(c => c.KubernetesVersion))
{
throw new AzPSArgumentException(Resources.UpdateKubernetesVersionAndNodeImageOnlyConflict, "KubernetesVersion");
}
if (!ShouldProcess(Resources.ConfirmOnlyUpgradeNodeVersion, ""))
{
return;
}

var upgradedPool = Client.AgentPools.UpgradeNodeImageVersion(ResourceGroupName, ClusterName, Name);
WriteObject(PSMapper.Instance.Map<PSNodePool>(upgradedPool));
return;
}

var updatedPool = Client.AgentPools.CreateOrUpdate(ResourceGroupName, ClusterName, Name, pool);
WriteObject(PSMapper.Instance.Map<PSNodePool>(updatedPool));
});
Expand Down
2 changes: 1 addition & 1 deletion src/Aks/Aks/help/Set-AzAksCluster.md
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,7 @@ Accept wildcard characters: False
```

### -NodeImageOnly
Will only upgrade node pool version to align control plane.
Will only upgrade the node image of agent pools.

```yaml
Type: System.Management.Automation.SwitchParameter
Expand Down
34 changes: 25 additions & 9 deletions src/Aks/Aks/help/Update-AzAksNodePool.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,32 +15,33 @@ Update node pool in a managed cluster.
### defaultParameterSet (Default)
```
Update-AzAksNodePool -ResourceGroupName <String> -ClusterName <String> -Name <String> [-NodeCount <Int32>]
[-AsJob] [-Force] [-KubernetesVersion <String>] [-MinCount <Int32>] [-MaxCount <Int32>] [-EnableAutoScaling]
[-DefaultProfile <IAzureContextContainer>] [-WhatIf] [-Confirm] [-SubscriptionId <String>]
[<CommonParameters>]
[-NodeImageOnly] [-AsJob] [-Force] [-KubernetesVersion <String>] [-MinCount <Int32>] [-MaxCount <Int32>]
[-EnableAutoScaling] [-DefaultProfile <IAzureContextContainer>] [-WhatIf] [-Confirm]
[-SubscriptionId <String>] [<CommonParameters>]
```

### ParentObjectParameterSet
```
Update-AzAksNodePool -Name <String> -ClusterObject <PSKubernetesCluster> [-NodeCount <Int32>] [-AsJob] [-Force]
[-KubernetesVersion <String>] [-MinCount <Int32>] [-MaxCount <Int32>] [-EnableAutoScaling]
Update-AzAksNodePool -Name <String> -ClusterObject <PSKubernetesCluster> [-NodeCount <Int32>] [-NodeImageOnly]
[-AsJob] [-Force] [-KubernetesVersion <String>] [-MinCount <Int32>] [-MaxCount <Int32>] [-EnableAutoScaling]
[-DefaultProfile <IAzureContextContainer>] [-WhatIf] [-Confirm] [-SubscriptionId <String>]
[<CommonParameters>]
```

### InputObjectParameterSet
```
Update-AzAksNodePool -InputObject <PSNodePool> [-NodeCount <Int32>] [-AsJob] [-Force]
Update-AzAksNodePool -InputObject <PSNodePool> [-NodeCount <Int32>] [-NodeImageOnly] [-AsJob] [-Force]
[-KubernetesVersion <String>] [-MinCount <Int32>] [-MaxCount <Int32>] [-EnableAutoScaling]
[-DefaultProfile <IAzureContextContainer>] [-WhatIf] [-Confirm] [-SubscriptionId <String>]
[<CommonParameters>]
```

### IdParameterSet
```
Update-AzAksNodePool -Id <String> [-NodeCount <Int32>] [-AsJob] [-Force] [-KubernetesVersion <String>]
[-MinCount <Int32>] [-MaxCount <Int32>] [-EnableAutoScaling] [-DefaultProfile <IAzureContextContainer>]
[-WhatIf] [-Confirm] [-SubscriptionId <String>] [<CommonParameters>]
Update-AzAksNodePool -Id <String> [-NodeCount <Int32>] [-NodeImageOnly] [-AsJob] [-Force]
[-KubernetesVersion <String>] [-MinCount <Int32>] [-MaxCount <Int32>] [-EnableAutoScaling]
[-DefaultProfile <IAzureContextContainer>] [-WhatIf] [-Confirm] [-SubscriptionId <String>]
[<CommonParameters>]
```

## DESCRIPTION
Expand Down Expand Up @@ -250,6 +251,21 @@ Accept pipeline input: False
Accept wildcard characters: False
```

### -NodeImageOnly
Will only upgrade the node image of agent pools.

```yaml
Type: System.Management.Automation.SwitchParameter
Parameter Sets: (All)
Aliases:

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

### -ResourceGroupName
The name of the resource group.

Expand Down