Skip to content

Commit

Permalink
{AKS} az aks update: Add --ip-families to support updating cluste…
Browse files Browse the repository at this point in the history
…r networking settings (#7040)
  • Loading branch information
tyler-lloyd authored Jan 12, 2024
1 parent 55c077c commit 935fb46
Show file tree
Hide file tree
Showing 6 changed files with 96 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/aks-preview/HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ To release a new version, please select a new version number (usually plus 1 to

Pending
+++++++
* Add `--ip-families` to the `az aks update` command.

0.5.174
+++++++
Expand Down
4 changes: 4 additions & 0 deletions src/aks-preview/azext_aks_preview/_help.py
Original file line number Diff line number Diff line change
Expand Up @@ -870,6 +870,10 @@
- name: --enable-disk-driver
type: bool
short-summary: Enable AzureDisk CSI Driver.
- name: --ip-families
type: string
short-summary: A comma separated list of IP versions to use for cluster networking.
long-summary: Each IP version should be in the format IPvN. For example, IPv4.
- name: --pod-cidr
type: string
short-summary: A CIDR notation IP range from which to assign pod IPs when kubenet is used.
Expand Down
1 change: 1 addition & 0 deletions src/aks-preview/azext_aks_preview/_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -851,6 +851,7 @@ def load_arguments(self, _):
c.argument("network_dataplane", arg_type=get_enum_type(network_dataplanes))
c.argument("network_policy")
c.argument("network_plugin", arg_type=get_enum_type(network_plugins))
c.argument("ip_families")
c.argument("kube_proxy_config")
c.argument(
"auto_upgrade_channel", arg_type=get_enum_type(auto_upgrade_channels)
Expand Down
1 change: 1 addition & 0 deletions src/aks-preview/azext_aks_preview/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -742,6 +742,7 @@ def aks_update(
network_plugin_mode=None,
network_policy=None,
network_dataplane=None,
ip_families=None,
pod_cidr=None,
enable_pod_security_policy=False,
disable_pod_security_policy=False,
Expand Down
22 changes: 20 additions & 2 deletions src/aks-preview/azext_aks_preview/managed_cluster_decorator.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,8 +278,15 @@ def get_ip_families(self) -> Union[List[str], None]:
ip_families = self.raw_param.get("ip_families")
# normalize
ip_families = extract_comma_separated_string(ip_families, keep_none=True, default_value=[])

# try to read the property value corresponding to the parameter from the `mc` object
if self.mc and self.mc.network_profile and self.mc.network_profile.ip_families is not None:
# when it wasn't provided as param.
if (
not ip_families and
self.mc and
self.mc.network_profile and
self.mc.network_profile.ip_families is not None
):
ip_families = self.mc.network_profile.ip_families

# this parameter does not need dynamic completion
Expand Down Expand Up @@ -3416,6 +3423,17 @@ def check_raw_parameters(self):
error_msg = f"Please specify one or more of {' or '.join(option_names)}."
raise RequiredArgumentMissingError(error_msg)

def update_network_profile(self, mc: ManagedCluster) -> ManagedCluster:
self._ensure_mc(mc)

ip_families = self.context.get_ip_families()
if ip_families:
mc.network_profile.ip_families = ip_families

self.update_network_plugin_settings(mc)

return mc

def update_network_plugin_settings(self, mc: ManagedCluster) -> ManagedCluster:
"""Update network plugin settings of network profile for the ManagedCluster object.
Expand Down Expand Up @@ -4344,7 +4362,7 @@ def update_mc_profile_preview(self) -> ManagedCluster:
# update linux profile
mc = self.update_linux_profile(mc)
# update network profile
mc = self.update_network_plugin_settings(mc)
mc = self.update_network_profile(mc)
# update outbound type
mc = self.update_outbound_type_in_network_profile(mc)
# update loadbalancer profile
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5539,6 +5539,75 @@ def test_update_network_plugin_settings(self):

self.assertEqual(dec_mc_7, ground_truth_mc_7)

# test update ip families
dec_8 = AKSPreviewManagedClusterUpdateDecorator(
self.cmd,
self.client,
{
"ip_families": "ipv4,ipv6"
},
CUSTOM_MGMT_AKS_PREVIEW,
)
mc_8 = self.models.ManagedCluster(
location="test_location",
network_profile=self.models.ContainerServiceNetworkProfile(
network_plugin="azure",
network_plugin_mode="overlay",
ip_families=["ipv4"]
),
)

dec_8.context.attach_mc(mc_8)
# fail on passing the wrong mc object
with self.assertRaises(CLIInternalError):
dec_8.update_network_profile(None)
dec_mc_8 = dec_8.update_network_profile(mc_8)

ground_truth_mc_8 = self.models.ManagedCluster(
location="test_location",
network_profile=self.models.ContainerServiceNetworkProfile(
network_plugin="azure",
network_plugin_mode="overlay",
ip_families=["ipv4", "ipv6"]
),
)

self.assertEqual(dec_mc_8, ground_truth_mc_8)

# test ip_families aren't updated when updating other fields
dec_9 = AKSPreviewManagedClusterUpdateDecorator(
self.cmd,
self.client,
{
"network_plugin_mode": "overlay"
},
CUSTOM_MGMT_AKS_PREVIEW,
)
mc_9 = self.models.ManagedCluster(
location="test_location",
network_profile=self.models.ContainerServiceNetworkProfile(
network_plugin="azure",
ip_families=["ipv6", "ipv4"]
),
)

dec_9.context.attach_mc(mc_9)
# fail on passing the wrong mc object
with self.assertRaises(CLIInternalError):
dec_9.update_network_profile(None)
dec_mc_9 = dec_9.update_network_profile(mc_9)

ground_truth_mc_9 = self.models.ManagedCluster(
location="test_location",
network_profile=self.models.ContainerServiceNetworkProfile(
network_plugin="azure",
network_plugin_mode="overlay",
ip_families=["ipv6", "ipv4"]
),
)

self.assertEqual(dec_mc_9, ground_truth_mc_9)

def test_update_api_server_access_profile(self):
dec_1 = AKSPreviewManagedClusterUpdateDecorator(
self.cmd,
Expand Down

0 comments on commit 935fb46

Please sign in to comment.