Skip to content

Commit

Permalink
{AKS} Support reset default value for loadbalancer profile and natgat…
Browse files Browse the repository at this point in the history
…eway profile
  • Loading branch information
MartinForReal committed Jan 31, 2024
1 parent 5f28485 commit f0d5411
Show file tree
Hide file tree
Showing 8 changed files with 1,091 additions and 327 deletions.
1 change: 1 addition & 0 deletions src/aks-preview/HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Pending
+++++++
* Deprecate the alias "-r" of parameter --source-resource-id in `az aks trustedaccess rolebinding create`
* Refactor azure service mesh related code to meet cli style requirements.
* Support reset default value for loadbalancer profile and natgateway profile

1.0.0b4
+++++++
Expand Down
18 changes: 9 additions & 9 deletions src/aks-preview/azext_aks_preview/_loadbalancer.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,8 @@ def configure_load_balancer_profile(
"""configure a load balancer with customer supplied values"""
if any(
[
managed_outbound_ip_count,
managed_outbound_ipv6_count,
managed_outbound_ip_count is not None,
managed_outbound_ipv6_count is not None,
outbound_ips,
outbound_ip_prefixes,
]
Expand Down Expand Up @@ -152,7 +152,7 @@ def configure_load_balancer_profile(
)
else:
profile.outbound_ip_prefixes = None
if managed_outbound_ip_count or managed_outbound_ipv6_count:
if managed_outbound_ip_count is not None or managed_outbound_ipv6_count is not None:
if profile.managed_outbound_i_ps is None:
if isinstance(models, SimpleNamespace):
ManagedClusterLoadBalancerProfileManagedOutboundIPs = (
Expand All @@ -165,14 +165,14 @@ def configure_load_balancer_profile(
profile.managed_outbound_i_ps = (
ManagedClusterLoadBalancerProfileManagedOutboundIPs()
)
if managed_outbound_ip_count:
if managed_outbound_ip_count is not None:
profile.managed_outbound_i_ps.count = managed_outbound_ip_count
if managed_outbound_ipv6_count:
if managed_outbound_ipv6_count is not None:
profile.managed_outbound_i_ps.count_ipv6 = managed_outbound_ipv6_count
else:
profile.managed_outbound_i_ps = None

if outbound_ports:
if outbound_ports is not None:
profile.allocated_outbound_ports = outbound_ports
if idle_timeout:
profile.idle_timeout_in_minutes = idle_timeout
Expand All @@ -191,11 +191,11 @@ def is_load_balancer_profile_provided(
):
return any(
[
managed_outbound_ip_count,
managed_outbound_ipv6_count,
managed_outbound_ip_count is not None,
managed_outbound_ipv6_count is not None,
outbound_ips,
ip_prefixes,
outbound_ports,
outbound_ports is not None,
idle_timeout,
]
)
Expand Down
42 changes: 42 additions & 0 deletions src/aks-preview/azext_aks_preview/_natgateway.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# --------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------

from types import SimpleNamespace


def create_nat_gateway_profile(managed_outbound_ip_count, idle_timeout, models: SimpleNamespace):
"""parse and build NAT gateway profile"""
if not is_nat_gateway_profile_provided(managed_outbound_ip_count, idle_timeout):
return None

profile = models.ManagedClusterNATGatewayProfile()
return configure_nat_gateway_profile(managed_outbound_ip_count, idle_timeout, profile, models)


def update_nat_gateway_profile(managed_outbound_ip_count, idle_timeout, profile, models: SimpleNamespace):
"""parse and update an existing NAT gateway profile"""
if not is_nat_gateway_profile_provided(managed_outbound_ip_count, idle_timeout):
return profile
if not profile:
profile = models.ManagedClusterNATGatewayProfile()
return configure_nat_gateway_profile(managed_outbound_ip_count, idle_timeout, profile, models)


def is_nat_gateway_profile_provided(managed_outbound_ip_count, idle_timeout):
return any([managed_outbound_ip_count is not None, idle_timeout])


def configure_nat_gateway_profile(managed_outbound_ip_count, idle_timeout, profile, models: SimpleNamespace):
"""configure a NAT Gateway with customer supplied values"""
if managed_outbound_ip_count is not None:
ManagedClusterManagedOutboundIPProfile = models.ManagedClusterManagedOutboundIPProfile
profile.managed_outbound_ip_profile = ManagedClusterManagedOutboundIPProfile(
count=managed_outbound_ip_count
)

if idle_timeout:
profile.idle_timeout_in_minutes = idle_timeout

return profile
41 changes: 40 additions & 1 deletion src/aks-preview/azext_aks_preview/managed_cluster_decorator.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@
from azext_aks_preview._loadbalancer import (
update_load_balancer_profile as _update_load_balancer_profile,
)
from azext_aks_preview._natgateway import create_nat_gateway_profile
from azext_aks_preview._natgateway import (
update_nat_gateway_profile as _update_nat_gateway_profile
)
from azext_aks_preview._podidentity import (
_fill_defaults_for_pod_identity_profile,
_is_pod_identity_addon_enabled,
Expand Down Expand Up @@ -2691,6 +2695,13 @@ def set_up_network_profile(self, mc: ManagedCluster) -> ManagedCluster:
models=self.models.load_balancer_models,
)

if self.context.get_nat_gateway_managed_outbound_ip_count() is not None:
network_profile.nat_gateway_profile = create_nat_gateway_profile(
self.context.get_nat_gateway_managed_outbound_ip_count(),
self.context.get_nat_gateway_idle_timeout(),
models=self.models.nat_gateway_models,
)

network_profile.network_plugin_mode = self.context.get_network_plugin_mode()

if self.context.get_enable_cilium_dataplane():
Expand Down Expand Up @@ -3499,6 +3510,10 @@ def get_special_parameter_default_value_pairs_list(self) -> List[Tuple[Any, Any]
(self.context.get_nodepool_labels(), None),
(self.context.get_nodepool_taints(), None),
(self.context.raw_param.get("upgrade_settings"), None),
(self.context.get_load_balancer_managed_outbound_ip_count(), None),
(self.context.get_load_balancer_managed_outbound_ipv6_count(), None),
(self.context.get_load_balancer_outbound_ports(), None),
(self.context.get_nat_gateway_managed_outbound_ip_count(), None),
]

def check_raw_parameters(self):
Expand Down Expand Up @@ -3526,7 +3541,6 @@ def check_raw_parameters(self):
if pair[0] != pair[1]:
is_different_from_special_default = True
break

if is_changed or is_different_from_special_default:
return

Expand Down Expand Up @@ -3742,6 +3756,29 @@ def update_load_balancer_profile(self, mc: ManagedCluster) -> ManagedCluster:
)
return mc

def update_nat_gateway_profile(self, mc: ManagedCluster) -> ManagedCluster:
"""Update nat gateway profile for the ManagedCluster object.
:return: the ManagedCluster object
"""
self._ensure_mc(mc)

if not mc.network_profile:
raise UnknownError(
"Unexpectedly get an empty network profile in the process of updating nat gateway profile."
)
outbound_type = self.context.get_outbound_type()
if outbound_type and outbound_type != CONST_OUTBOUND_TYPE_MANAGED_NAT_GATEWAY:
mc.network_profile.nat_gateway_profile = None
else:
mc.network_profile.nat_gateway_profile = _update_nat_gateway_profile(
self.context.get_nat_gateway_managed_outbound_ip_count(),
self.context.get_nat_gateway_idle_timeout(),
mc.network_profile.nat_gateway_profile,
models=self.models.nat_gateway_models,
)
return mc

def update_outbound_type_in_network_profile(self, mc: ManagedCluster) -> ManagedCluster:
"""Update outbound type of network profile for the ManagedCluster object.
:return: the ManagedCluster object
Expand Down Expand Up @@ -4538,6 +4575,8 @@ def update_mc_profile_preview(self) -> ManagedCluster:
mc = self.update_outbound_type_in_network_profile(mc)
# update loadbalancer profile
mc = self.update_load_balancer_profile(mc)
# update natgateway profile
mc = self.update_nat_gateway_profile(mc)
# update kube proxy config
mc = self.update_kube_proxy_config(mc)
# update custom ca trust certificates
Expand Down
Loading

0 comments on commit f0d5411

Please sign in to comment.