From 9be8ceaa1788e82d6f855ad138ee52dcabe75533 Mon Sep 17 00:00:00 2001 From: Tyler Lloyd Date: Wed, 10 Jul 2024 00:32:46 -0400 Subject: [PATCH] chore: do not use network_plugin default from sdk (#7766) --- .../managed_cluster_decorator.py | 11 ++++++ .../tests/latest/test_aks_commands.py | 2 ++ .../latest/test_managed_cluster_decorator.py | 34 ++++++++++++++++++- 3 files changed, 46 insertions(+), 1 deletion(-) diff --git a/src/aks-preview/azext_aks_preview/managed_cluster_decorator.py b/src/aks-preview/azext_aks_preview/managed_cluster_decorator.py index 0a61da70791..43768c17b5d 100644 --- a/src/aks-preview/azext_aks_preview/managed_cluster_decorator.py +++ b/src/aks-preview/azext_aks_preview/managed_cluster_decorator.py @@ -2968,6 +2968,17 @@ def set_up_network_profile(self, mc: ManagedCluster) -> ManagedCluster: mc = super().set_up_network_profile(mc) network_profile = mc.network_profile + # network_plugin is typically defaulted to kubenet. AKS-RP is moving + # away from specifying this default in the API and making it based + # on the k8s version being used. The CLI should not be responsible + # for setting default values and should pass properties as empty + # unless specified by the user. + if ( + network_profile.network_plugin is not None and + self.context.raw_param.get("network_plugin") is None + ): + network_profile.network_plugin = None + # set up pod_cidrs, service_cidrs and ip_families ( pod_cidrs, diff --git a/src/aks-preview/azext_aks_preview/tests/latest/test_aks_commands.py b/src/aks-preview/azext_aks_preview/tests/latest/test_aks_commands.py index 7b5c14b2aa7..268287b3658 100644 --- a/src/aks-preview/azext_aks_preview/tests/latest/test_aks_commands.py +++ b/src/aks-preview/azext_aks_preview/tests/latest/test_aks_commands.py @@ -6117,6 +6117,7 @@ def test_aks_create_with_pod_identity_enabled( # create create_cmd = ( "aks create --resource-group={resource_group} --name={name} --location={location} " + "--network-plugin kubenet " "--enable-managed-identity " "--enable-pod-identity --enable-pod-identity-with-kubenet " "--ssh-key-value={ssh_key_value} " @@ -6417,6 +6418,7 @@ def test_aks_pod_identity_usage(self, resource_group, resource_group_location): # create create_cmd = ( "aks create --resource-group={resource_group} --name={name} --location={location} " + "--network-plugin kubenet " "--enable-managed-identity " "--enable-pod-identity --enable-pod-identity-with-kubenet " "--ssh-key-value={ssh_key_value} " diff --git a/src/aks-preview/azext_aks_preview/tests/latest/test_managed_cluster_decorator.py b/src/aks-preview/azext_aks_preview/tests/latest/test_managed_cluster_decorator.py index 42dfa70e252..42be6c93aed 100644 --- a/src/aks-preview/azext_aks_preview/tests/latest/test_managed_cluster_decorator.py +++ b/src/aks-preview/azext_aks_preview/tests/latest/test_managed_cluster_decorator.py @@ -4168,7 +4168,7 @@ def test_set_up_agentpool_profile(self): ground_truth_mc_1.agent_pool_profiles = [ground_truth_agentpool_profile_1] self.assertEqual(dec_mc_1, ground_truth_mc_1) - def test_set_up_network_profile(self): + def test_set_up_network_profile_preview(self): # custom value dec_1 = AKSPreviewManagedClusterCreateDecorator( self.cmd, @@ -4214,6 +4214,7 @@ def test_set_up_network_profile(self): network_profile_1.ip_families = ["IPv4", "IPv6"] network_profile_1.pod_cidrs = ["10.246.0.0/16", "2001:abcd::/64"] network_profile_1.service_cidrs = ["10.0.0.0/16", "2001:ffff::/108"] + network_profile_1.network_plugin = None load_balancer_profile_1 = self.models.load_balancer_models.ManagedClusterLoadBalancerProfile( managed_outbound_i_ps=self.models.load_balancer_models.ManagedClusterLoadBalancerProfileManagedOutboundIPs( @@ -4227,6 +4228,36 @@ def test_set_up_network_profile(self): ) self.assertEqual(dec_mc_1, ground_truth_mc_1) + # custom value + dec_2 = AKSPreviewManagedClusterCreateDecorator( + self.cmd, + self.client, + { + "network_plugin": "azure", + }, + CUSTOM_MGMT_AKS_PREVIEW, + ) + mc_2 = self.models.ManagedCluster(location="test_location") + dec_2.context.attach_mc(mc_2) + dec_mc_2 = dec_2.set_up_network_profile(mc_2) + + network_profile_2 = self.models.ContainerServiceNetworkProfile() + # TODO: remove this temp fix once aks-preview's dependency on core azure-cli is updated to 2.26.0 + for attr_name, attr_value in vars(network_profile_2).items(): + if ( + not attr_name.startswith("_") + and attr_name not in ["additional_properties", "outbound_type"] + and attr_value is not None + ): + setattr(network_profile_2, attr_name, None) + network_profile_2.network_plugin = "azure" + network_profile_2.load_balancer_sku = CONST_LOAD_BALANCER_SKU_STANDARD + + ground_truth_mc_2 = self.models.ManagedCluster( + location="test_location", network_profile=network_profile_2 + ) + self.assertEqual(dec_mc_2, ground_truth_mc_2) + def test_set_up_api_server_access_profile(self): dec_1 = AKSPreviewManagedClusterCreateDecorator( self.cmd, @@ -5359,6 +5390,7 @@ def test_construct_mc_profile_preview(self): ) network_profile_1 = self.models.ContainerServiceNetworkProfile( load_balancer_sku="standard", + network_plugin=None, ) identity_1 = self.models.ManagedClusterIdentity(type="SystemAssigned") storage_profile_1 = self.models.ManagedClusterStorageProfile(