Skip to content

Commit f0d5411

Browse files
committed
{AKS} Support reset default value for loadbalancer profile and natgateway profile
1 parent 5f28485 commit f0d5411

8 files changed

+1091
-327
lines changed

src/aks-preview/HISTORY.rst

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ Pending
1313
+++++++
1414
* Deprecate the alias "-r" of parameter --source-resource-id in `az aks trustedaccess rolebinding create`
1515
* Refactor azure service mesh related code to meet cli style requirements.
16+
* Support reset default value for loadbalancer profile and natgateway profile
1617

1718
1.0.0b4
1819
+++++++

src/aks-preview/azext_aks_preview/_loadbalancer.py

+9-9
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,8 @@ def configure_load_balancer_profile(
111111
"""configure a load balancer with customer supplied values"""
112112
if any(
113113
[
114-
managed_outbound_ip_count,
115-
managed_outbound_ipv6_count,
114+
managed_outbound_ip_count is not None,
115+
managed_outbound_ipv6_count is not None,
116116
outbound_ips,
117117
outbound_ip_prefixes,
118118
]
@@ -152,7 +152,7 @@ def configure_load_balancer_profile(
152152
)
153153
else:
154154
profile.outbound_ip_prefixes = None
155-
if managed_outbound_ip_count or managed_outbound_ipv6_count:
155+
if managed_outbound_ip_count is not None or managed_outbound_ipv6_count is not None:
156156
if profile.managed_outbound_i_ps is None:
157157
if isinstance(models, SimpleNamespace):
158158
ManagedClusterLoadBalancerProfileManagedOutboundIPs = (
@@ -165,14 +165,14 @@ def configure_load_balancer_profile(
165165
profile.managed_outbound_i_ps = (
166166
ManagedClusterLoadBalancerProfileManagedOutboundIPs()
167167
)
168-
if managed_outbound_ip_count:
168+
if managed_outbound_ip_count is not None:
169169
profile.managed_outbound_i_ps.count = managed_outbound_ip_count
170-
if managed_outbound_ipv6_count:
170+
if managed_outbound_ipv6_count is not None:
171171
profile.managed_outbound_i_ps.count_ipv6 = managed_outbound_ipv6_count
172172
else:
173173
profile.managed_outbound_i_ps = None
174174

175-
if outbound_ports:
175+
if outbound_ports is not None:
176176
profile.allocated_outbound_ports = outbound_ports
177177
if idle_timeout:
178178
profile.idle_timeout_in_minutes = idle_timeout
@@ -191,11 +191,11 @@ def is_load_balancer_profile_provided(
191191
):
192192
return any(
193193
[
194-
managed_outbound_ip_count,
195-
managed_outbound_ipv6_count,
194+
managed_outbound_ip_count is not None,
195+
managed_outbound_ipv6_count is not None,
196196
outbound_ips,
197197
ip_prefixes,
198-
outbound_ports,
198+
outbound_ports is not None,
199199
idle_timeout,
200200
]
201201
)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# --------------------------------------------------------------------------------------------
2+
# Copyright (c) Microsoft Corporation. All rights reserved.
3+
# Licensed under the MIT License. See License.txt in the project root for license information.
4+
# --------------------------------------------------------------------------------------------
5+
6+
from types import SimpleNamespace
7+
8+
9+
def create_nat_gateway_profile(managed_outbound_ip_count, idle_timeout, models: SimpleNamespace):
10+
"""parse and build NAT gateway profile"""
11+
if not is_nat_gateway_profile_provided(managed_outbound_ip_count, idle_timeout):
12+
return None
13+
14+
profile = models.ManagedClusterNATGatewayProfile()
15+
return configure_nat_gateway_profile(managed_outbound_ip_count, idle_timeout, profile, models)
16+
17+
18+
def update_nat_gateway_profile(managed_outbound_ip_count, idle_timeout, profile, models: SimpleNamespace):
19+
"""parse and update an existing NAT gateway profile"""
20+
if not is_nat_gateway_profile_provided(managed_outbound_ip_count, idle_timeout):
21+
return profile
22+
if not profile:
23+
profile = models.ManagedClusterNATGatewayProfile()
24+
return configure_nat_gateway_profile(managed_outbound_ip_count, idle_timeout, profile, models)
25+
26+
27+
def is_nat_gateway_profile_provided(managed_outbound_ip_count, idle_timeout):
28+
return any([managed_outbound_ip_count is not None, idle_timeout])
29+
30+
31+
def configure_nat_gateway_profile(managed_outbound_ip_count, idle_timeout, profile, models: SimpleNamespace):
32+
"""configure a NAT Gateway with customer supplied values"""
33+
if managed_outbound_ip_count is not None:
34+
ManagedClusterManagedOutboundIPProfile = models.ManagedClusterManagedOutboundIPProfile
35+
profile.managed_outbound_ip_profile = ManagedClusterManagedOutboundIPProfile(
36+
count=managed_outbound_ip_count
37+
)
38+
39+
if idle_timeout:
40+
profile.idle_timeout_in_minutes = idle_timeout
41+
42+
return profile

src/aks-preview/azext_aks_preview/managed_cluster_decorator.py

+40-1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@
4141
from azext_aks_preview._loadbalancer import (
4242
update_load_balancer_profile as _update_load_balancer_profile,
4343
)
44+
from azext_aks_preview._natgateway import create_nat_gateway_profile
45+
from azext_aks_preview._natgateway import (
46+
update_nat_gateway_profile as _update_nat_gateway_profile
47+
)
4448
from azext_aks_preview._podidentity import (
4549
_fill_defaults_for_pod_identity_profile,
4650
_is_pod_identity_addon_enabled,
@@ -2691,6 +2695,13 @@ def set_up_network_profile(self, mc: ManagedCluster) -> ManagedCluster:
26912695
models=self.models.load_balancer_models,
26922696
)
26932697

2698+
if self.context.get_nat_gateway_managed_outbound_ip_count() is not None:
2699+
network_profile.nat_gateway_profile = create_nat_gateway_profile(
2700+
self.context.get_nat_gateway_managed_outbound_ip_count(),
2701+
self.context.get_nat_gateway_idle_timeout(),
2702+
models=self.models.nat_gateway_models,
2703+
)
2704+
26942705
network_profile.network_plugin_mode = self.context.get_network_plugin_mode()
26952706

26962707
if self.context.get_enable_cilium_dataplane():
@@ -3499,6 +3510,10 @@ def get_special_parameter_default_value_pairs_list(self) -> List[Tuple[Any, Any]
34993510
(self.context.get_nodepool_labels(), None),
35003511
(self.context.get_nodepool_taints(), None),
35013512
(self.context.raw_param.get("upgrade_settings"), None),
3513+
(self.context.get_load_balancer_managed_outbound_ip_count(), None),
3514+
(self.context.get_load_balancer_managed_outbound_ipv6_count(), None),
3515+
(self.context.get_load_balancer_outbound_ports(), None),
3516+
(self.context.get_nat_gateway_managed_outbound_ip_count(), None),
35023517
]
35033518

35043519
def check_raw_parameters(self):
@@ -3526,7 +3541,6 @@ def check_raw_parameters(self):
35263541
if pair[0] != pair[1]:
35273542
is_different_from_special_default = True
35283543
break
3529-
35303544
if is_changed or is_different_from_special_default:
35313545
return
35323546

@@ -3742,6 +3756,29 @@ def update_load_balancer_profile(self, mc: ManagedCluster) -> ManagedCluster:
37423756
)
37433757
return mc
37443758

3759+
def update_nat_gateway_profile(self, mc: ManagedCluster) -> ManagedCluster:
3760+
"""Update nat gateway profile for the ManagedCluster object.
3761+
3762+
:return: the ManagedCluster object
3763+
"""
3764+
self._ensure_mc(mc)
3765+
3766+
if not mc.network_profile:
3767+
raise UnknownError(
3768+
"Unexpectedly get an empty network profile in the process of updating nat gateway profile."
3769+
)
3770+
outbound_type = self.context.get_outbound_type()
3771+
if outbound_type and outbound_type != CONST_OUTBOUND_TYPE_MANAGED_NAT_GATEWAY:
3772+
mc.network_profile.nat_gateway_profile = None
3773+
else:
3774+
mc.network_profile.nat_gateway_profile = _update_nat_gateway_profile(
3775+
self.context.get_nat_gateway_managed_outbound_ip_count(),
3776+
self.context.get_nat_gateway_idle_timeout(),
3777+
mc.network_profile.nat_gateway_profile,
3778+
models=self.models.nat_gateway_models,
3779+
)
3780+
return mc
3781+
37453782
def update_outbound_type_in_network_profile(self, mc: ManagedCluster) -> ManagedCluster:
37463783
"""Update outbound type of network profile for the ManagedCluster object.
37473784
:return: the ManagedCluster object
@@ -4538,6 +4575,8 @@ def update_mc_profile_preview(self) -> ManagedCluster:
45384575
mc = self.update_outbound_type_in_network_profile(mc)
45394576
# update loadbalancer profile
45404577
mc = self.update_load_balancer_profile(mc)
4578+
# update natgateway profile
4579+
mc = self.update_nat_gateway_profile(mc)
45414580
# update kube proxy config
45424581
mc = self.update_kube_proxy_config(mc)
45434582
# update custom ca trust certificates

0 commit comments

Comments
 (0)