Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

{AKS} Support reset default value for loadbalancer profile and natgateway profile #7230

Merged
merged 1 commit into from
Mar 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/aks-preview/HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ To release a new version, please select a new version number (usually plus 1 to

Pending
+++++++
* Support reset default value for loadbalancer profile and natgateway profile

2.0.0b6
+++++++
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 @@ -43,6 +43,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 @@ -2739,6 +2743,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,
)

Comment on lines +2746 to +2752
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps this part can be omitted as it's part of the create process, even if setting it to 0 is ignored, the default value will be backfilled to 0?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The default value is 1

network_profile.network_plugin_mode = self.context.get_network_plugin_mode()

if self.context.get_enable_cilium_dataplane():
Expand Down Expand Up @@ -3574,6 +3585,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 @@ -3601,7 +3616,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 @@ -3902,6 +3916,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 @@ -4742,6 +4779,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