Skip to content

Commit 016518e

Browse files
committed
init commit: add ip-families to az aks update GA
1 parent 73eb6dd commit 016518e

File tree

3 files changed

+122
-1
lines changed

3 files changed

+122
-1
lines changed

src/azure-cli/azure/cli/command_modules/acs/managed_cluster_decorator.py

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2124,7 +2124,12 @@ def get_ip_families(self) -> Union[List[str], None]:
21242124
# normalize
21252125
ip_families = extract_comma_separated_string(ip_families, keep_none=True, default_value=[])
21262126
# try to read the property value corresponding to the parameter from the `mc` object
2127-
if self.mc and self.mc.network_profile and self.mc.network_profile.ip_families is not None:
2127+
if (
2128+
not ip_families and
2129+
self.mc and
2130+
self.mc.network_profile and
2131+
self.mc.network_profile.ip_families is not None
2132+
):
21282133
ip_families = self.mc.network_profile.ip_families
21292134

21302135
# this parameter does not need dynamic completion
@@ -7283,6 +7288,21 @@ def update_auto_upgrade_profile(self, mc: ManagedCluster) -> ManagedCluster:
72837288

72847289
return mc
72857290

7291+
def update_network_profile(self, mc: ManagedCluster) -> ManagedCluster:
7292+
"""Update ip families settings for the ManagedCluster object.
7293+
7294+
:return: the ManagedCluster object
7295+
"""
7296+
self._ensure_mc(mc)
7297+
7298+
ip_families = self.context.get_ip_families()
7299+
if ip_families:
7300+
mc.network_profile.ip_families = ip_families
7301+
7302+
self.update_network_plugin_settings(mc)
7303+
7304+
return mc
7305+
72867306
def update_network_plugin_settings(self, mc: ManagedCluster) -> ManagedCluster:
72877307
"""Update network plugin settings of network profile for the ManagedCluster object.
72887308
@@ -8242,6 +8262,8 @@ def update_mc_profile_default(self) -> ManagedCluster:
82428262
mc = self.update_windows_profile(mc)
82438263
# update network plugin settings
82448264
mc = self.update_network_plugin_settings(mc)
8265+
# update network profile settings
8266+
mc = self.update_network_profile(mc)
82458267
# update aad profile
82468268
mc = self.update_aad_profile(mc)
82478269
# update oidc issuer profile

src/azure-cli/azure/cli/command_modules/acs/tests/latest/test_aks_commands.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9384,6 +9384,27 @@ def test_aks_create_dualstack_with_default_network(self, resource_group, resourc
93849384
self.check('networkProfile.ipFamilies', ['IPv4', 'IPv6'])
93859385
])
93869386

9387+
# update
9388+
update_cmd = 'aks update -g {resource_group} -n {name} --ip-families ipv4,ipv6 --load-balancer-managed-outbound-ipv6-count 4'
9389+
9390+
self.cmd(update_cmd, checks=[
9391+
self.check('provisioningState', 'Succeeded'),
9392+
self.check('networkProfile.podCidr', '172.126.0.0/16'),
9393+
self.check('networkProfile.podCidrs', [
9394+
'172.126.0.0/16', '2001:abcd:1234::/64']),
9395+
self.check('networkProfile.serviceCidr', '172.56.0.0/16'),
9396+
self.check('networkProfile.serviceCidrs', [
9397+
'172.56.0.0/16', '2001:ffff::/108']),
9398+
self.check('networkProfile.ipFamilies', ['IPv4', 'IPv6']),
9399+
self.check(
9400+
'networkProfile.loadBalancerProfile.managedOutboundIPs.countIpv6', 4),
9401+
self.check(
9402+
'networkProfile.loadBalancerProfile.managedOutboundIPs.count', 1),
9403+
self.check(
9404+
'networkProfile.loadBalancerProfile.effectiveOutboundIPs[] | length(@)', 5)
9405+
])
9406+
9407+
93879408
# delete
93889409
self.cmd(
93899410
'aks delete -g {resource_group} -n {name} --yes --no-wait', checks=[self.is_empty()])

src/azure-cli/azure/cli/command_modules/acs/tests/latest/test_managed_cluster_decorator.py

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2167,6 +2167,14 @@ def test_get_ip_families(self):
21672167
self.models,
21682168
decorator_mode=DecoratorMode.CREATE,
21692169
)
2170+
2171+
# test update
2172+
ctx_4 = AKSManagedClusterContext(
2173+
self.cmd,
2174+
AKSManagedClusterParamDict({"ip_families": "IPv4,IPv6"}),
2175+
self.models,
2176+
decorator_mode=DecoratorMode.UPDATE,
2177+
21702178
self.assertEqual(ctx_3.get_ip_families(), ["IPv4", "IPv6"])
21712179

21722180
def test_get_pod_cidr_and_service_cidr_and_dns_service_ip_and_docker_bridge_address_and_network_policy(
@@ -10385,6 +10393,76 @@ def test_update_network_plugin_settings(self):
1038510393

1038610394
self.assertEqual(dec_mc_9, ground_truth_mc_9)
1038710395

10396+
# update ip families
10397+
dec_10 = AKSManagedClusterUpdateDecorator(
10398+
self.cmd,
10399+
self.client,
10400+
{
10401+
"ip_families": "IPv4,IPv6",
10402+
},
10403+
ResourceType.MGMT_CONTAINERSERVICE,
10404+
)
10405+
10406+
mc_10 = self.models.ManagedCluster(
10407+
location="test_location",
10408+
network_profile=self.models.ContainerServiceNetworkProfile(
10409+
network_plugin="azure",
10410+
network_plugin_mode="overlay",
10411+
ip_families=["IPv4"],
10412+
),
10413+
)
10414+
10415+
dec_10.context.attach_mc(mc_10)
10416+
# fail on passing the wrong mc object
10417+
with self.assertRaises(CLIInternalError):
10418+
dec_10.update_network_profile(None)
10419+
dec_mc_10 = dec_10.update_network_profile(mc_10)
10420+
10421+
ground_truth_mc_10 = self.models.ManagedCluster(
10422+
location="test_location",
10423+
network_profile=self.models.ContainerServiceNetworkProfile(
10424+
network_plugin="azure",
10425+
network_plugin_mode="overlay",
10426+
ip_families=["IPv4", "IPv6"],
10427+
),
10428+
)
10429+
10430+
self.assertEqual(dec_mc_10, ground_truth_mc_10)
10431+
10432+
# ip families cannot be updated when other fields are updated
10433+
dec_11 = AKSManagedClusterUpdateDecorator(
10434+
self.cmd,
10435+
self.client,
10436+
{
10437+
"network_plugin_mode": "overlay",
10438+
},
10439+
ResourceType.MGMT_CONTAINERSERVICE,
10440+
)
10441+
10442+
mc_11 = self.models.ManagedCluster(
10443+
location="test_location",
10444+
network_profile=self.models.ContainerServiceNetworkProfile(
10445+
network_plugin="azure",
10446+
ip_families=["IPv4", "IPv6"],
10447+
),
10448+
)
10449+
10450+
dec_11.context.attach_mc(mc_11)
10451+
# fail on passing the wrong mc object
10452+
with self.assertRaises(CLIInternalError):
10453+
dec_11.update_network_profile(None)
10454+
dec_mc_11 = dec_11.update_network_profile(mc_11)
10455+
10456+
ground_truth_mc_11 = self.models.ManagedCluster(
10457+
location="test_location",
10458+
network_profile=self.models.ContainerServiceNetworkProfile(
10459+
network_plugin="azure",
10460+
network_plugin_mode="overlay",
10461+
ip_families=["IPv4", "IPv6"],
10462+
),
10463+
)
10464+
10465+
self.assertEqual(dec_mc_11, ground_truth_mc_11)
1038810466

1038910467
def _mock_get_keyvault_client(cli_ctx, subscription_id=None):
1039010468
free_mock_client = mock.MagicMock()

0 commit comments

Comments
 (0)