Skip to content

Commit 326be59

Browse files
{AKS} Support reset default value for loadbalancer profile and natgateway profile (#28273)
1 parent 246725e commit 326be59

File tree

7 files changed

+820
-370
lines changed

7 files changed

+820
-370
lines changed

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

+9-9
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@ def configure_load_balancer_profile(managed_outbound_ip_count, managed_outbound_
6060
outbound_ip_prefixes, outbound_ports, idle_timeout,
6161
backend_pool_type, profile, models):
6262
"""configure a load balancer with customer supplied values"""
63-
if any([managed_outbound_ip_count,
64-
managed_outbound_ipv6_count,
63+
if any([managed_outbound_ip_count is not None,
64+
managed_outbound_ipv6_count is not None,
6565
outbound_ips,
6666
outbound_ip_prefixes]):
6767
outbound_ip_resources = _get_load_balancer_outbound_ips(outbound_ips, models)
@@ -93,7 +93,7 @@ def configure_load_balancer_profile(managed_outbound_ip_count, managed_outbound_
9393
)
9494
elif profile.outbound_ip_prefixes is not None:
9595
profile.outbound_ip_prefixes = None
96-
if managed_outbound_ip_count or managed_outbound_ipv6_count:
96+
if managed_outbound_ip_count is not None or managed_outbound_ipv6_count is not None:
9797
if profile.managed_outbound_i_ps is None:
9898
if isinstance(models, SimpleNamespace):
9999
ManagedClusterLoadBalancerProfileManagedOutboundIPs = (
@@ -104,13 +104,13 @@ def configure_load_balancer_profile(managed_outbound_ip_count, managed_outbound_
104104
"ManagedClusterLoadBalancerProfileManagedOutboundIPs"
105105
)
106106
profile.managed_outbound_i_ps = ManagedClusterLoadBalancerProfileManagedOutboundIPs()
107-
if managed_outbound_ip_count:
107+
if managed_outbound_ip_count is not None:
108108
profile.managed_outbound_i_ps.count = managed_outbound_ip_count
109-
if managed_outbound_ipv6_count:
109+
if managed_outbound_ipv6_count is not None:
110110
profile.managed_outbound_i_ps.count_ipv6 = managed_outbound_ipv6_count
111111
elif profile.managed_outbound_i_ps is not None:
112112
profile.managed_outbound_i_ps = None
113-
if outbound_ports:
113+
if outbound_ports is not None:
114114
profile.allocated_outbound_ports = outbound_ports
115115
if idle_timeout:
116116
profile.idle_timeout_in_minutes = idle_timeout
@@ -121,11 +121,11 @@ def configure_load_balancer_profile(managed_outbound_ip_count, managed_outbound_
121121

122122
def is_load_balancer_profile_provided(managed_outbound_ip_count, managed_outbound_ipv6_count, outbound_ips, ip_prefixes,
123123
outbound_ports, backend_pool_type, idle_timeout):
124-
return any([managed_outbound_ip_count,
125-
managed_outbound_ipv6_count,
124+
return any([managed_outbound_ip_count is not None,
125+
managed_outbound_ipv6_count is not None,
126126
outbound_ips,
127127
ip_prefixes,
128-
outbound_ports,
128+
outbound_ports is not None,
129129
idle_timeout,
130130
backend_pool_type])
131131

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,12 @@ def update_nat_gateway_profile(managed_outbound_ip_count, idle_timeout, profile,
2525

2626

2727
def is_nat_gateway_profile_provided(managed_outbound_ip_count, idle_timeout):
28-
return any([managed_outbound_ip_count, idle_timeout])
28+
return any([managed_outbound_ip_count is not None, idle_timeout])
2929

3030

3131
def configure_nat_gateway_profile(managed_outbound_ip_count, idle_timeout, profile, models: SimpleNamespace):
3232
"""configure a NAT Gateway with customer supplied values"""
33-
if managed_outbound_ip_count:
33+
if managed_outbound_ip_count is not None:
3434
ManagedClusterManagedOutboundIPProfile = models.ManagedClusterManagedOutboundIPProfile
3535
profile.managed_outbound_ip_profile = ManagedClusterManagedOutboundIPProfile(
3636
count=managed_outbound_ip_count

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

+7-1
Original file line numberDiff line numberDiff line change
@@ -6576,7 +6576,13 @@ def check_raw_parameters(self):
65766576
self.context.get_cluster_autoscaler_profile() is None and
65776577
self.context.get_api_server_authorized_ip_ranges() is None and
65786578
self.context.get_nodepool_labels() is None and
6579-
self.context.get_nodepool_taints() is None
6579+
self.context.get_nodepool_taints() is None and
6580+
self.context.get_load_balancer_managed_outbound_ip_count() is None and
6581+
self.context.get_load_balancer_managed_outbound_ipv6_count() is None and
6582+
self.context.get_load_balancer_idle_timeout() is None and
6583+
self.context.get_load_balancer_outbound_ports() is None and
6584+
self.context.get_nat_gateway_managed_outbound_ip_count() is None and
6585+
self.context.get_nat_gateway_idle_timeout() is None
65806586
)
65816587

65826588
if not is_changed and is_default:

src/azure-cli/azure/cli/command_modules/acs/tests/latest/recordings/test_aks_create_loadbalancer_then_update.yaml

+746-358
Large diffs are not rendered by default.

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

+9
Original file line numberDiff line numberDiff line change
@@ -6208,6 +6208,15 @@ def test_aks_create_loadbalancer_then_update(self, resource_group, resource_grou
62086208
self.check('networkProfile.loadBalancerProfile.idleTimeoutInMinutes', 10)
62096209
])
62106210

6211+
# update
6212+
update_cmd = 'aks update --resource-group={resource_group} --name={name} ' \
6213+
'--load-balancer-outbound-ports 0'
6214+
self.cmd(update_cmd, checks=[
6215+
self.check('provisioningState', 'Succeeded'),
6216+
self.check('networkProfile.loadBalancerProfile.allocatedOutboundPorts', 0),
6217+
self.check('networkProfile.loadBalancerProfile.idleTimeoutInMinutes', 10)
6218+
])
6219+
62116220
# delete
62126221
self.cmd(
62136222
'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_loadbalancer.py

+44
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,50 @@ def test_update_load_balancer_profile(self):
116116
self.assertEqual(p.idle_timeout_in_minutes, 3600)
117117
self.assertEqual(p.backend_pool_type, "nodeIP")
118118

119+
def test_update_load_balancer_profile_reset_empty(self):
120+
cmd = MockCmd(MockCLI())
121+
managed_outbound_ip_count = 0
122+
managed_outbound_ipv6_count = None
123+
outbound_ips = None
124+
outbound_ip_prefixes = None
125+
outbound_ports = 0
126+
idle_timeout = 3600
127+
backend_pool_type = "nodeIP"
128+
129+
# store all the models used by load balancer
130+
load_balancer_models = AKSManagedClusterModels(cmd, ResourceType.MGMT_CONTAINERSERVICE).load_balancer_models
131+
ManagedClusterLoadBalancerProfile = (
132+
load_balancer_models.ManagedClusterLoadBalancerProfile
133+
)
134+
ManagedClusterLoadBalancerProfileManagedOutboundIPs = (
135+
load_balancer_models.ManagedClusterLoadBalancerProfileManagedOutboundIPs
136+
)
137+
ManagedClusterLoadBalancerProfileOutboundIPs = (
138+
load_balancer_models.ManagedClusterLoadBalancerProfileOutboundIPs
139+
)
140+
profile = ManagedClusterLoadBalancerProfile()
141+
profile.managed_outbound_i_ps = ManagedClusterLoadBalancerProfileManagedOutboundIPs(
142+
count=2,
143+
count_ipv6=3
144+
)
145+
146+
p = loadbalancer.configure_load_balancer_profile(
147+
managed_outbound_ip_count,
148+
managed_outbound_ipv6_count,
149+
outbound_ips,
150+
outbound_ip_prefixes,
151+
outbound_ports,
152+
idle_timeout,
153+
backend_pool_type,
154+
profile,
155+
load_balancer_models,
156+
)
157+
158+
self.assertEqual(p.managed_outbound_i_ps.count, 0)
159+
self.assertEqual(p.allocated_outbound_ports, 0)
160+
self.assertEqual(p.idle_timeout_in_minutes, 3600)
161+
self.assertEqual(p.backend_pool_type, "nodeIP")
162+
119163
def test_configure_load_balancer_profile_error(self):
120164
cmd = MockCmd(MockCLI())
121165
managed_outbound_ip_count = 5

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

+3
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,9 @@ def test_nonempty_arguments(self):
8686
result = natgateway.is_nat_gateway_profile_provided(1, 4)
8787
self.assertTrue(result)
8888

89+
def test_nonempty_arguments(self):
90+
result = natgateway.is_nat_gateway_profile_provided(0, None)
91+
self.assertTrue(result)
8992

9093
if __name__ == "__main__":
9194
unittest.main()

0 commit comments

Comments
 (0)