Skip to content

Commit 85aa474

Browse files
committed
{AKS} Support reset default value for loadbalancer profile and natgateway profile
1 parent 2983a85 commit 85aa474

8 files changed

+1092
-328
lines changed

src/aks-preview/HISTORY.rst

+1
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ Pending
5151
* Add `--enable-ai-toolchain-operator` to `az aks create` and `az aks update`.
5252
* Add `--disable-ai-toolchain-operator` to the `az aks update` command.
5353
* Refactor azure service mesh related code to meet cli style requirements.
54+
* Support reset default value for loadbalancer profile and natgateway profile
5455

5556
1.0.0b4
5657
+++++++

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
@@ -43,6 +43,10 @@
4343
from azext_aks_preview._loadbalancer import (
4444
update_load_balancer_profile as _update_load_balancer_profile,
4545
)
46+
from azext_aks_preview._natgateway import create_nat_gateway_profile
47+
from azext_aks_preview._natgateway import (
48+
update_nat_gateway_profile as _update_nat_gateway_profile
49+
)
4650
from azext_aks_preview._podidentity import (
4751
_fill_defaults_for_pod_identity_profile,
4852
_is_pod_identity_addon_enabled,
@@ -2739,6 +2743,13 @@ def set_up_network_profile(self, mc: ManagedCluster) -> ManagedCluster:
27392743
models=self.models.load_balancer_models,
27402744
)
27412745

2746+
if self.context.get_nat_gateway_managed_outbound_ip_count() is not None:
2747+
network_profile.nat_gateway_profile = create_nat_gateway_profile(
2748+
self.context.get_nat_gateway_managed_outbound_ip_count(),
2749+
self.context.get_nat_gateway_idle_timeout(),
2750+
models=self.models.nat_gateway_models,
2751+
)
2752+
27422753
network_profile.network_plugin_mode = self.context.get_network_plugin_mode()
27432754

27442755
if self.context.get_enable_cilium_dataplane():
@@ -3574,6 +3585,10 @@ def get_special_parameter_default_value_pairs_list(self) -> List[Tuple[Any, Any]
35743585
(self.context.get_nodepool_labels(), None),
35753586
(self.context.get_nodepool_taints(), None),
35763587
(self.context.raw_param.get("upgrade_settings"), None),
3588+
(self.context.get_load_balancer_managed_outbound_ip_count(), None),
3589+
(self.context.get_load_balancer_managed_outbound_ipv6_count(), None),
3590+
(self.context.get_load_balancer_outbound_ports(), None),
3591+
(self.context.get_nat_gateway_managed_outbound_ip_count(), None),
35773592
]
35783593

35793594
def check_raw_parameters(self):
@@ -3601,7 +3616,6 @@ def check_raw_parameters(self):
36013616
if pair[0] != pair[1]:
36023617
is_different_from_special_default = True
36033618
break
3604-
36053619
if is_changed or is_different_from_special_default:
36063620
return
36073621

@@ -3817,6 +3831,29 @@ def update_load_balancer_profile(self, mc: ManagedCluster) -> ManagedCluster:
38173831
)
38183832
return mc
38193833

3834+
def update_nat_gateway_profile(self, mc: ManagedCluster) -> ManagedCluster:
3835+
"""Update nat gateway profile for the ManagedCluster object.
3836+
3837+
:return: the ManagedCluster object
3838+
"""
3839+
self._ensure_mc(mc)
3840+
3841+
if not mc.network_profile:
3842+
raise UnknownError(
3843+
"Unexpectedly get an empty network profile in the process of updating nat gateway profile."
3844+
)
3845+
outbound_type = self.context.get_outbound_type()
3846+
if outbound_type and outbound_type != CONST_OUTBOUND_TYPE_MANAGED_NAT_GATEWAY:
3847+
mc.network_profile.nat_gateway_profile = None
3848+
else:
3849+
mc.network_profile.nat_gateway_profile = _update_nat_gateway_profile(
3850+
self.context.get_nat_gateway_managed_outbound_ip_count(),
3851+
self.context.get_nat_gateway_idle_timeout(),
3852+
mc.network_profile.nat_gateway_profile,
3853+
models=self.models.nat_gateway_models,
3854+
)
3855+
return mc
3856+
38203857
def update_outbound_type_in_network_profile(self, mc: ManagedCluster) -> ManagedCluster:
38213858
"""Update outbound type of network profile for the ManagedCluster object.
38223859
:return: the ManagedCluster object
@@ -4657,6 +4694,8 @@ def update_mc_profile_preview(self) -> ManagedCluster:
46574694
mc = self.update_outbound_type_in_network_profile(mc)
46584695
# update loadbalancer profile
46594696
mc = self.update_load_balancer_profile(mc)
4697+
# update natgateway profile
4698+
mc = self.update_nat_gateway_profile(mc)
46604699
# update kube proxy config
46614700
mc = self.update_kube_proxy_config(mc)
46624701
# update custom ca trust certificates

0 commit comments

Comments
 (0)