Skip to content

Commit 5650f5c

Browse files
{AKS} az aks create/update: Outbound type should not be updated if it is not set (#30539)
1 parent 3c540df commit 5650f5c

File tree

2 files changed

+57
-29
lines changed

2 files changed

+57
-29
lines changed

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

+14-20
Original file line numberDiff line numberDiff line change
@@ -2161,7 +2161,6 @@ def _get_outbound_type(
21612161
self,
21622162
enable_validation: bool = False,
21632163
read_only: bool = False,
2164-
load_balancer_profile: ManagedClusterLoadBalancerProfile = None,
21652164
) -> Union[str, None]:
21662165
"""Internal function to dynamically obtain the value of outbound_type according to the context.
21672166
@@ -2202,6 +2201,7 @@ def _get_outbound_type(
22022201

22032202
# dynamic completion
22042203
if (
2204+
self.decorator_mode == DecoratorMode.CREATE and
22052205
not read_from_mc and
22062206
outbound_type != CONST_OUTBOUND_TYPE_MANAGED_NAT_GATEWAY and
22072207
outbound_type != CONST_OUTBOUND_TYPE_USER_ASSIGNED_NAT_GATEWAY and
@@ -2232,33 +2232,29 @@ def _get_outbound_type(
22322232
"be pre-configured with a route table with egress rules"
22332233
)
22342234

2235-
if outbound_type == CONST_OUTBOUND_TYPE_USER_DEFINED_ROUTING:
2236-
if load_balancer_profile:
2237-
if (
2238-
load_balancer_profile.managed_outbound_i_ps or
2239-
load_balancer_profile.outbound_i_ps or
2240-
load_balancer_profile.outbound_ip_prefixes
2241-
):
2242-
raise MutuallyExclusiveArgumentError(
2243-
"userDefinedRouting doesn't support customizing \
2244-
a standard load balancer with IP addresses"
2245-
)
2235+
if outbound_type != CONST_OUTBOUND_TYPE_LOAD_BALANCER:
22462236
if (
22472237
self.get_load_balancer_managed_outbound_ip_count() or
22482238
self.get_load_balancer_managed_outbound_ipv6_count() or
22492239
self.get_load_balancer_outbound_ips() or
22502240
self.get_load_balancer_outbound_ip_prefixes()
22512241
):
22522242
raise MutuallyExclusiveArgumentError(
2253-
"userDefinedRouting doesn't support customizing \
2254-
a standard load balancer with IP addresses"
2243+
outbound_type + " doesn't support customizing "
2244+
"a standard load balancer with IP addresses"
2245+
)
2246+
if outbound_type != CONST_OUTBOUND_TYPE_MANAGED_NAT_GATEWAY:
2247+
if (
2248+
self.get_nat_gateway_managed_outbound_ip_count()
2249+
):
2250+
raise MutuallyExclusiveArgumentError(
2251+
outbound_type + " doesn't support customizing "
2252+
"a standard nat gateway with IP addresses"
22552253
)
2256-
22572254
return outbound_type
22582255

22592256
def get_outbound_type(
22602257
self,
2261-
load_balancer_profile: ManagedClusterLoadBalancerProfile = None
22622258
) -> Union[str, None]:
22632259
"""Dynamically obtain the value of outbound_type according to the context.
22642260
@@ -2280,7 +2276,7 @@ def get_outbound_type(
22802276
:return: string or None
22812277
"""
22822278
return self._get_outbound_type(
2283-
enable_validation=True, load_balancer_profile=load_balancer_profile
2279+
enable_validation=True
22842280
)
22852281

22862282
def _get_network_plugin_mode(self, enable_validation: bool = False) -> Union[str, None]:
@@ -5694,9 +5690,7 @@ def set_up_network_profile(self, mc: ManagedCluster) -> ManagedCluster:
56945690
# verify outbound type
56955691
# Note: Validation internally depends on load_balancer_sku, which is a temporary value that is
56965692
# dynamically completed.
5697-
outbound_type = self.context.get_outbound_type(
5698-
load_balancer_profile=load_balancer_profile
5699-
)
5693+
outbound_type = self.context.get_outbound_type()
57005694

57015695
# verify load balancer sku
57025696
load_balancer_sku = safe_lower(self.context.get_load_balancer_sku())

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

+43-9
Original file line numberDiff line numberDiff line change
@@ -1757,7 +1757,7 @@ def test_get_outbound_type(self):
17571757
DecoratorMode.UPDATE,
17581758
)
17591759
self.assertEqual(ctx_1._get_outbound_type(read_only=True), None)
1760-
self.assertEqual(ctx_1.get_outbound_type(), "loadBalancer")
1760+
self.assertEqual(ctx_1.get_outbound_type(), None)
17611761
network_profile_1 = self.models.ContainerServiceNetworkProfile(outbound_type="test_outbound_type")
17621762
mc = self.models.ManagedCluster(location="test_location", network_profile=network_profile_1)
17631763
ctx_1.attach_mc(mc)
@@ -1835,6 +1835,7 @@ def test_get_outbound_type(self):
18351835
{
18361836
"outbound_type": CONST_OUTBOUND_TYPE_USER_DEFINED_ROUTING,
18371837
"vnet_subnet_id": "test_vnet_subnet_id",
1838+
"nat_gateway_managed_outbound_ip_count": 10
18381839
}
18391840
),
18401841
self.models,
@@ -1848,17 +1849,10 @@ def test_get_outbound_type(self):
18481849
AgentPoolDecoratorMode.MANAGED_CLUSTER,
18491850
)
18501851
ctx_5.attach_agentpool_context(agentpool_ctx_5)
1851-
load_balancer_profile = self.models.load_balancer_models.ManagedClusterLoadBalancerProfile(
1852-
outbound_ip_prefixes=self.models.load_balancer_models.ManagedClusterLoadBalancerProfileOutboundIPPrefixes(
1853-
public_ip_prefixes=[self.models.load_balancer_models.ResourceReference(id="test_public_ip_prefix")]
1854-
)
1855-
)
18561852
# fail on mutually exclusive outbound_type and managed_outbound_ip_count/outbound_ips/outbound_ip_prefixes of
18571853
# load balancer
18581854
with self.assertRaises(MutuallyExclusiveArgumentError):
1859-
ctx_5.get_outbound_type(
1860-
load_balancer_profile=load_balancer_profile,
1861-
)
1855+
ctx_5.get_outbound_type()
18621856

18631857
# invalid parameter
18641858
ctx_6 = AKSManagedClusterContext(
@@ -1885,6 +1879,46 @@ def test_get_outbound_type(self):
18851879
# load balancer
18861880
with self.assertRaises(MutuallyExclusiveArgumentError):
18871881
ctx_6.get_outbound_type()
1882+
ctx_7 = AKSManagedClusterContext(
1883+
self.cmd,
1884+
AKSManagedClusterParamDict(
1885+
{
1886+
"outbound_type": CONST_OUTBOUND_TYPE_USER_DEFINED_ROUTING,
1887+
"vnet_subnet_id": "test_vnet_subnet_id",
1888+
"nat_gateway_managed_outbound_ip_count": 10,
1889+
}
1890+
),
1891+
self.models,
1892+
DecoratorMode.CREATE,
1893+
)
1894+
agentpool_ctx_7 = AKSAgentPoolContext(
1895+
self.cmd,
1896+
AKSAgentPoolParamDict({"vnet_subnet_id": "test_vnet_subnet_id"}),
1897+
self.models,
1898+
DecoratorMode.CREATE,
1899+
AgentPoolDecoratorMode.MANAGED_CLUSTER,
1900+
)
1901+
ctx_7.attach_agentpool_context(agentpool_ctx_7)
1902+
# fail on mutually exclusive outbound_type and nat_gateway_managed_outbound_ip_count on
1903+
# nat gateway
1904+
with self.assertRaises(MutuallyExclusiveArgumentError):
1905+
ctx_7.get_outbound_type()
1906+
1907+
network_profile_1 = self.models.ContainerServiceNetworkProfile(outbound_type="test_outbound_type")
1908+
mc = self.models.ManagedCluster(location="test_location", network_profile=network_profile_1)
1909+
# existing value should not be validated
1910+
ctx_8 = AKSManagedClusterContext(
1911+
self.cmd,
1912+
AKSManagedClusterParamDict(
1913+
{
1914+
}
1915+
),
1916+
self.models,
1917+
DecoratorMode.UPDATE,
1918+
)
1919+
ctx_8.attach_mc(mc)
1920+
existingOutboundType = ctx_8.get_outbound_type()
1921+
self.assertEqual(existingOutboundType, "test_outbound_type")
18881922

18891923
def test_get_network_plugin_mode(self):
18901924
# default

0 commit comments

Comments
 (0)