Skip to content

Commit

Permalink
feat: add load-balancer-backend-pool-type to create and update api (#…
Browse files Browse the repository at this point in the history
…5355)

* feat: add load-balancer-backend-pool-type to create and update api

* chore: update version

Co-authored-by: Qi Ni <[email protected]>
  • Loading branch information
nilo19 and Qi Ni authored Sep 23, 2022
1 parent 7bfb799 commit 373cc11
Show file tree
Hide file tree
Showing 14 changed files with 1,271 additions and 14 deletions.
6 changes: 6 additions & 0 deletions linter_exclusions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ aks create:
load_balancer_outbound_ports:
rule_exclusions:
- option_length_too_long
load_balancer_backend_pool_type:
rule_exclusions:
- option_length_too_long
nat_gateway_idle_timeout:
rule_exclusions:
- option_length_too_long
Expand Down Expand Up @@ -176,6 +179,9 @@ aks update:
load_balancer_outbound_ports:
rule_exclusions:
- option_length_too_long
load_balancer_backend_pool_type:
rule_exclusions:
- option_length_too_long
nat_gateway_idle_timeout:
rule_exclusions:
- option_length_too_long
Expand Down
5 changes: 5 additions & 0 deletions src/aks-preview/HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ To release a new version, please select a new version number (usually plus 1 to
Pending
+++++++

0.5.103
+++++++

* Add load-balancer-backend-pool-type to create and update api.

0.5.102
+++++++

Expand Down
4 changes: 4 additions & 0 deletions src/aks-preview/azext_aks_preview/_consts.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@
CONST_OUTBOUND_TYPE_MANAGED_NAT_GATEWAY = "managedNATGateway"
CONST_OUTBOUND_TYPE_USER_ASSIGNED_NAT_GATEWAY = "userAssignedNATGateway"

# load balancer backend pool type
CONST_LOAD_BALANCER_BACKEND_POOL_TYPE_NODE_IP = "nodeIP"
CONST_LOAD_BALANCER_BACKEND_POOL_TYPE_NODE_IPCONFIGURATION = "nodeIPConfiguration"

# private dns zone mode
CONST_PRIVATE_DNS_ZONE_SYSTEM = "system"
CONST_PRIVATE_DNS_ZONE_NONE = "none"
Expand Down
8 changes: 8 additions & 0 deletions src/aks-preview/azext_aks_preview/_help.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,10 @@
type: int
short-summary: Load balancer idle timeout in minutes.
long-summary: Desired idle timeout for load balancer outbound flows, default is 30 minutes. Please specify a value in the range of [4, 100].
- name: --load-balancer-backend-pool-type
type: string
short-summary: Load balancer backend pool type.
long-summary: Load balancer backend pool type, supported values are nodeIP and nodeIPConfiguration.
- name: --nat-gateway-managed-outbound-ip-count
type: int
short-summary: NAT gateway managed outbound IP count.
Expand Down Expand Up @@ -620,6 +624,10 @@
type: int
short-summary: Load balancer idle timeout in minutes.
long-summary: Desired idle timeout for load balancer outbound flows, default is 30 minutes. Please specify a value in the range of [4, 100].
- name: --load-balancer-backend-pool-type
type: string
short-summary: Load balancer backend pool type.
long-summary: Load balancer backend pool type, supported values are nodeIP and nodeIPConfiguration.
- name: --nat-gateway-managed-outbound-ip-count
type: int
short-summary: NAT gateway managed outbound IP count.
Expand Down
21 changes: 12 additions & 9 deletions src/aks-preview/azext_aks_preview/_loadbalancer.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,20 @@ def set_load_balancer_sku(sku, kubernetes_version):


def update_load_balancer_profile(managed_outbound_ip_count, managed_outbound_ipv6_count, outbound_ips,
outbound_ip_prefixes, outbound_ports, idle_timeout, profile, models):
outbound_ip_prefixes, outbound_ports, idle_timeout, backend_pool_type, profile, models):
"""parse and update an existing load balancer profile"""
if not is_load_balancer_profile_provided(managed_outbound_ip_count, managed_outbound_ipv6_count, outbound_ips,
outbound_ip_prefixes, outbound_ports, idle_timeout):
outbound_ip_prefixes, outbound_ports, backend_pool_type, idle_timeout):
return profile
return configure_load_balancer_profile(managed_outbound_ip_count, managed_outbound_ipv6_count, outbound_ips,
outbound_ip_prefixes, outbound_ports, idle_timeout, profile, models)
outbound_ip_prefixes, outbound_ports, idle_timeout, backend_pool_type, profile, models)


def create_load_balancer_profile(managed_outbound_ip_count, managed_outbound_ipv6_count, outbound_ips,
outbound_ip_prefixes, outbound_ports, idle_timeout, models):
outbound_ip_prefixes, outbound_ports, idle_timeout, backend_pool_type, models):
"""parse and build load balancer profile"""
if not is_load_balancer_profile_provided(managed_outbound_ip_count, managed_outbound_ipv6_count, outbound_ips,
outbound_ip_prefixes, outbound_ports, idle_timeout):
outbound_ip_prefixes, outbound_ports, backend_pool_type, idle_timeout):
return None

if isinstance(models, SimpleNamespace):
Expand All @@ -45,11 +45,11 @@ def create_load_balancer_profile(managed_outbound_ip_count, managed_outbound_ipv
ManagedClusterLoadBalancerProfile = models.get("ManagedClusterLoadBalancerProfile")
profile = ManagedClusterLoadBalancerProfile()
return configure_load_balancer_profile(managed_outbound_ip_count, managed_outbound_ipv6_count, outbound_ips,
outbound_ip_prefixes, outbound_ports, idle_timeout, profile, models)
outbound_ip_prefixes, outbound_ports, idle_timeout, backend_pool_type, profile, models)


def configure_load_balancer_profile(managed_outbound_ip_count, managed_outbound_ipv6_count, outbound_ips,
outbound_ip_prefixes, outbound_ports, idle_timeout, profile, models):
outbound_ip_prefixes, outbound_ports, idle_timeout, backend_pool_type, profile, models):
"""configure a load balancer with customer supplied values"""
if not profile:
return profile
Expand Down Expand Up @@ -109,17 +109,20 @@ def configure_load_balancer_profile(managed_outbound_ip_count, managed_outbound_
profile.allocated_outbound_ports = outbound_ports
if idle_timeout:
profile.idle_timeout_in_minutes = idle_timeout
if backend_pool_type:
profile.backend_pool_type = backend_pool_type
return profile


def is_load_balancer_profile_provided(managed_outbound_ip_count, managed_outbound_ipv6_count, outbound_ips,
ip_prefixes, outbound_ports, idle_timeout):
ip_prefixes, outbound_ports, backend_pool_type, idle_timeout):
return any([managed_outbound_ip_count,
managed_outbound_ipv6_count,
outbound_ips,
ip_prefixes,
outbound_ports,
idle_timeout])
idle_timeout,
backend_pool_type])


def _get_load_balancer_outbound_ips(load_balancer_outbound_ips, models):
Expand Down
3 changes: 3 additions & 0 deletions src/aks-preview/azext_aks_preview/_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@
validate_k8s_version,
validate_linux_host_name,
validate_load_balancer_idle_timeout,
validate_load_balancer_backend_pool_type,
validate_load_balancer_outbound_ip_prefixes,
validate_load_balancer_outbound_ips,
validate_load_balancer_outbound_ports,
Expand Down Expand Up @@ -212,6 +213,7 @@ def load_arguments(self, _):
c.argument('load_balancer_outbound_ip_prefixes', validator=validate_load_balancer_outbound_ip_prefixes)
c.argument('load_balancer_outbound_ports', type=int, validator=validate_load_balancer_outbound_ports)
c.argument('load_balancer_idle_timeout', type=int, validator=validate_load_balancer_idle_timeout)
c.argument('load_balancer_backend_pool_type', validator=validate_load_balancer_backend_pool_type)
c.argument('nat_gateway_managed_outbound_ip_count', type=int, validator=validate_nat_gateway_managed_outbound_ip_count)
c.argument('nat_gateway_idle_timeout', type=int, validator=validate_nat_gateway_idle_timeout)
c.argument('outbound_type', arg_type=get_enum_type(outbound_types))
Expand Down Expand Up @@ -345,6 +347,7 @@ def load_arguments(self, _):
c.argument('load_balancer_outbound_ip_prefixes', validator=validate_load_balancer_outbound_ip_prefixes)
c.argument('load_balancer_outbound_ports', type=int, validator=validate_load_balancer_outbound_ports)
c.argument('load_balancer_idle_timeout', type=int, validator=validate_load_balancer_idle_timeout)
c.argument('load_balancer_backend_pool_type', validator=validate_load_balancer_backend_pool_type)
c.argument('nat_gateway_managed_outbound_ip_count', type=int, validator=validate_nat_gateway_managed_outbound_ip_count)
c.argument('nat_gateway_idle_timeout', type=int, validator=validate_nat_gateway_idle_timeout)
c.argument('auto_upgrade_channel', arg_type=get_enum_type(auto_upgrade_channels))
Expand Down
14 changes: 13 additions & 1 deletion src/aks-preview/azext_aks_preview/_validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@
from azure.cli.core.util import CLIError
from knack.log import get_logger

from azext_aks_preview._consts import ADDONS
from azext_aks_preview._consts import (
ADDONS,
CONST_LOAD_BALANCER_BACKEND_POOL_TYPE_NODE_IP,
CONST_LOAD_BALANCER_BACKEND_POOL_TYPE_NODE_IPCONFIGURATION,
)
from azext_aks_preview._helpers import _fuzzy_match

logger = get_logger(__name__)
Expand Down Expand Up @@ -309,6 +313,14 @@ def validate_load_balancer_idle_timeout(namespace):
"--load-balancer-idle-timeout must be in the range [4,100]")


def validate_load_balancer_backend_pool_type(namespace):
"""validate load balancer backend pool type"""
if namespace.load_balancer_backend_pool_type is not None:
if namespace.load_balancer_backend_pool_type not in [CONST_LOAD_BALANCER_BACKEND_POOL_TYPE_NODE_IP, CONST_LOAD_BALANCER_BACKEND_POOL_TYPE_NODE_IPCONFIGURATION]:
raise InvalidArgumentValueError(
f"Invalid Load Balancer Backend Pool Type {namespace.load_balancer_backend_pool_type}, supported values are nodeIP and nodeIPConfiguration")


def validate_nat_gateway_managed_outbound_ip_count(namespace):
"""validate NAT gateway profile managed outbound IP count"""
if namespace.nat_gateway_managed_outbound_ip_count is not None:
Expand Down
2 changes: 2 additions & 0 deletions src/aks-preview/azext_aks_preview/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -560,6 +560,7 @@ def aks_create(
load_balancer_outbound_ip_prefixes=None,
load_balancer_outbound_ports=None,
load_balancer_idle_timeout=None,
load_balancer_backend_pool_type=None,
nat_gateway_managed_outbound_ip_count=None,
nat_gateway_idle_timeout=None,
outbound_type=None,
Expand Down Expand Up @@ -716,6 +717,7 @@ def aks_update(
load_balancer_outbound_ip_prefixes=None,
load_balancer_outbound_ports=None,
load_balancer_idle_timeout=None,
load_balancer_backend_pool_type=None,
nat_gateway_managed_outbound_ip_count=None,
nat_gateway_idle_timeout=None,
auto_upgrade_channel=None,
Expand Down
18 changes: 17 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 @@ -356,6 +356,20 @@ def get_load_balancer_managed_outbound_ipv6_count(self) -> Union[int, None]:

return count_ipv6

def get_load_balancer_backend_pool_type(self) -> str:
"""Obtain the value of load_balancer_backend_pool_type.
:return: string
"""
# read the original value passed by the command
load_balancer_backend_pool_type = self.raw_param.get(
"load_balancer_backend_pool_type"
)

# this parameter does not need dynamic completion
# this parameter does not need validation
return load_balancer_backend_pool_type

def _get_enable_pod_security_policy(self, enable_validation: bool = False) -> bool:
"""Internal function to obtain the value of enable_pod_security_policy.
Expand Down Expand Up @@ -2037,14 +2051,15 @@ def set_up_network_profile(self, mc: ManagedCluster) -> ManagedCluster:
network_profile.ip_families = ip_families

# recreate the load balancer profile if load_balancer_managed_outbound_ipv6_count is not None
if self.context.get_load_balancer_managed_outbound_ipv6_count() is not None:
if self.context.get_load_balancer_managed_outbound_ipv6_count() is not None or self.context.get_load_balancer_backend_pool_type() is not None:
network_profile.load_balancer_profile = create_load_balancer_profile(
self.context.get_load_balancer_managed_outbound_ip_count(),
self.context.get_load_balancer_managed_outbound_ipv6_count(),
self.context.get_load_balancer_outbound_ips(),
self.context.get_load_balancer_outbound_ip_prefixes(),
self.context.get_load_balancer_outbound_ports(),
self.context.get_load_balancer_idle_timeout(),
self.context.get_load_balancer_backend_pool_type(),
models=self.models.load_balancer_models,
)

Expand Down Expand Up @@ -2475,6 +2490,7 @@ def update_load_balancer_profile(self, mc: ManagedCluster) -> ManagedCluster:
outbound_ip_prefixes=self.context.get_load_balancer_outbound_ip_prefixes(),
outbound_ports=self.context.get_load_balancer_outbound_ports(),
idle_timeout=self.context.get_load_balancer_idle_timeout(),
backend_pool_type=self.context.get_load_balancer_backend_pool_type(),
profile=mc.network_profile.load_balancer_profile,
models=self.models.load_balancer_models,
)
Expand Down
Loading

0 comments on commit 373cc11

Please sign in to comment.