Skip to content

Commit

Permalink
{AKS} az aks update: refactor pod_cidr and network_plugin_mode gett…
Browse files Browse the repository at this point in the history
…ers to check decorator mode (#6163)
  • Loading branch information
tyler-lloyd authored Apr 6, 2023
1 parent 3bc39be commit ace5218
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 23 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
+++++++
* Refactor: use decorator mode in pod_cidr and network_plugin_mode getters to read from mc only during CREATE

0.5.135
+++++++
Expand Down
44 changes: 21 additions & 23 deletions src/aks-preview/azext_aks_preview/managed_cluster_decorator.py
Original file line number Diff line number Diff line change
Expand Up @@ -477,18 +477,16 @@ def get_pod_cidr(self) -> Union[str, None]:
:return: str or None
"""
# try to read the property value corresponding to the parameter from the `mc` object
pod_cidr = None
# only read on CREATE as this property can be updated
pod_cidr = self.raw_param.get("pod_cidr")

if (
self.mc and
self.mc.network_profile and
self.mc.network_profile.pod_cidr is not None
):
pod_cidr = self.mc.network_profile.pod_cidr

# overwrite if provided by user
if self.raw_param.get("pod_cidr") is not None:
pod_cidr = self.raw_param.get("pod_cidr")
if self.decorator_mode == DecoratorMode.CREATE:
if (
self.mc and
self.mc.network_profile and
self.mc.network_profile.pod_cidr is not None
):
pod_cidr = self.mc.network_profile.pod_cidr

# this parameter does not need dynamic completion
# this parameter does not need validation
Expand All @@ -499,18 +497,18 @@ def get_network_plugin_mode(self) -> Union[str, None]:
:return: str or None
"""
network_plugin_mode = None
# 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.network_plugin_mode is not None
):
network_plugin_mode = self.mc.network_profile.network_plugin_mode

# overwrite if provided by user
if self.raw_param.get("network_plugin_mode") is not None:
network_plugin_mode = self.raw_param.get("network_plugin_mode")
network_plugin_mode = self.raw_param.get("network_plugin_mode")

# try to read the property value corresponding to the parameter from the `mc` object
# only read on CREATE as this property can be updated
if self.decorator_mode == DecoratorMode.CREATE:
if (
self.mc and
self.mc.network_profile and
self.mc.network_profile.network_plugin_mode is not None
):
network_plugin_mode = self.mc.network_profile.network_plugin_mode

# this parameter does not need dynamic completion
# this parameter does not need validation
Expand Down Expand Up @@ -3242,7 +3240,7 @@ def update_upgrade_settings(self, mc: ManagedCluster) -> ManagedCluster:
if override_until is not None:
try:
mc.upgrade_settings.override_settings.until = parse(override_until)
except Exception as ex: # pylint: disable=broad-except
except Exception: # pylint: disable=broad-except
raise InvalidArgumentValueError(
f"{override_until} is not a valid datatime format."
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4825,6 +4825,78 @@ def test_update_network_plugin_settings(self):

self.assertEqual(dec_mc_2, ground_truth_mc_2)

# test no updates made with same network plugin mode
dec_3 = AKSPreviewManagedClusterUpdateDecorator(
self.cmd,
self.client,
{
"network_plugin_mode": "overlay",
},
CUSTOM_MGMT_AKS_PREVIEW,
)
mc_3 = self.models.ManagedCluster(
location="test_location",
network_profile=self.models.ContainerServiceNetworkProfile(
network_plugin="azure",
network_plugin_mode="overlay",
pod_cidr="100.64.0.0/16",
service_cidr="192.168.0.0/16"
),
)

dec_3.context.attach_mc(mc_3)
# fail on passing the wrong mc object
with self.assertRaises(CLIInternalError):
dec_3.update_network_plugin_settings(None)
dec_mc_3 = dec_3.update_network_plugin_settings(mc_3)

ground_truth_mc_3 = self.models.ManagedCluster(
location="test_location",
network_profile=self.models.ContainerServiceNetworkProfile(
network_plugin="azure",
network_plugin_mode="overlay",
pod_cidr="100.64.0.0/16",
service_cidr="192.168.0.0/16",
),
)

self.assertEqual(dec_mc_3, ground_truth_mc_3)

# test no updates made with empty network plugin settings
dec_4 = AKSPreviewManagedClusterUpdateDecorator(
self.cmd,
self.client,
{},
CUSTOM_MGMT_AKS_PREVIEW,
)
mc_4 = self.models.ManagedCluster(
location="test_location",
network_profile=self.models.ContainerServiceNetworkProfile(
network_plugin="azure",
network_plugin_mode="overlay",
pod_cidr="100.64.0.0/16",
service_cidr="192.168.0.0/16"
),
)

dec_4.context.attach_mc(mc_4)
# fail on passing the wrong mc object
with self.assertRaises(CLIInternalError):
dec_4.update_network_plugin_settings(None)
dec_mc_4 = dec_4.update_network_plugin_settings(mc_4)

ground_truth_mc_4 = self.models.ManagedCluster(
location="test_location",
network_profile=self.models.ContainerServiceNetworkProfile(
network_plugin="azure",
network_plugin_mode="overlay",
pod_cidr="100.64.0.0/16",
service_cidr="192.168.0.0/16",
),
)

self.assertEqual(dec_mc_4, ground_truth_mc_4)

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

0 comments on commit ace5218

Please sign in to comment.