@@ -2053,19 +2053,6 @@ def get_nat_gateway_managed_outbound_ip_count(self) -> Union[int, None]:
20532053 """
20542054 # read the original value passed by the command
20552055 nat_gateway_managed_outbound_ip_count = self .raw_param .get ("nat_gateway_managed_outbound_ip_count" )
2056- # In create mode, try to read the property value corresponding to the parameter from the `mc` object.
2057- if nat_gateway_managed_outbound_ip_count is None and self .decorator_mode == DecoratorMode .UPDATE :
2058- if (
2059- self .mc and
2060- self .mc .network_profile and
2061- self .mc .network_profile .nat_gateway_profile and
2062- self .mc .network_profile .nat_gateway_profile .managed_outbound_ip_profile and
2063- self .mc .network_profile .nat_gateway_profile .managed_outbound_ip_profile .count is not None
2064- ):
2065- nat_gateway_managed_outbound_ip_count = (
2066- self .mc .network_profile .nat_gateway_profile .managed_outbound_ip_profile .count
2067- )
2068-
20692056 # this parameter does not need dynamic completion
20702057 # this parameter does not need validation
20712058 return nat_gateway_managed_outbound_ip_count
@@ -2079,17 +2066,6 @@ def get_nat_gateway_idle_timeout(self) -> Union[int, None]:
20792066 """
20802067 # read the original value passed by the command
20812068 nat_gateway_idle_timeout = self .raw_param .get ("nat_gateway_idle_timeout" )
2082- # In create mode, try to read the property value corresponding to the parameter from the `mc` object.
2083- if nat_gateway_idle_timeout is None and self .decorator_mode == DecoratorMode .UPDATE :
2084- if (
2085- self .mc and
2086- self .mc .network_profile and
2087- self .mc .network_profile .nat_gateway_profile and
2088- self .mc .network_profile .nat_gateway_profile .idle_timeout_in_minutes is not None
2089- ):
2090- nat_gateway_idle_timeout = (
2091- self .mc .network_profile .nat_gateway_profile .idle_timeout_in_minutes
2092- )
20932069
20942070 # this parameter does not need dynamic completion
20952071 # this parameter does not need validation
@@ -2171,23 +2147,19 @@ def _get_outbound_type(
21712147 CONST_OUTBOUND_TYPE_LOAD_BALANCER.
21722148
21732149 This function supports the option of enable_validation. When enabled, if the value of outbound_type is
2174- CONST_OUTBOUND_TYPE_MANAGED_NAT_GATEWAY, CONST_OUTBOUND_TYPE_USER_ASSIGNED_NAT_GATEWAY or
2150+ CONST_OUTBOUND_TYPE_LOAD_BALANCER, CONST_OUTBOUND_TYPE_MANAGED_NAT_GATEWAY, CONST_OUTBOUND_TYPE_USER_ASSIGNED_NAT_GATEWAY or
21752151 CONST_OUTBOUND_TYPE_USER_DEFINED_ROUTING, the following checks will be performed. If load_balancer_sku is set
21762152 to basic, an InvalidArgumentValueError will be raised. If vnet_subnet_id is not assigned,
21772153 a RequiredArgumentMissingError will be raised. If any of load_balancer_managed_outbound_ip_count,
2178- load_balancer_outbound_ips or load_balancer_outbound_ip_prefixes is assigned, a MutuallyExclusiveArgumentError
2179- will be raised.
21802154 This function supports the option of read_only. When enabled, it will skip dynamic completion and validation.
2181- This function supports the option of load_balancer_profile, if provided, when verifying loadbalancer-related
2182- parameters, the value in load_balancer_profile will be used for validation.
21832155
21842156 :return: string or None
21852157 """
21862158 # read the original value passed by the command
21872159 outbound_type = self .raw_param .get ("outbound_type" )
21882160 # try to read the property value corresponding to the parameter from the `mc` object
21892161 read_from_mc = False
2190- if outbound_type is None and self . decorator_mode != DecoratorMode . CREATE :
2162+ if outbound_type is None :
21912163 if (
21922164 self .mc and
21932165 self .mc .network_profile and
@@ -2200,58 +2172,79 @@ def _get_outbound_type(
22002172 if read_only :
22012173 return outbound_type
22022174
2175+ isBasicSKULb = safe_lower (self ._get_load_balancer_sku (enable_validation = False )) == CONST_LOAD_BALANCER_SKU_BASIC
22032176 # dynamic completion
2204- if (
2205- self .decorator_mode == DecoratorMode .CREATE and
2206- not read_from_mc and
2207- outbound_type != CONST_OUTBOUND_TYPE_MANAGED_NAT_GATEWAY and
2208- outbound_type != CONST_OUTBOUND_TYPE_USER_ASSIGNED_NAT_GATEWAY and
2209- outbound_type != CONST_OUTBOUND_TYPE_USER_DEFINED_ROUTING
2210- ):
2177+ if not read_from_mc and not isBasicSKULb and outbound_type is None :
22112178 outbound_type = CONST_OUTBOUND_TYPE_LOAD_BALANCER
22122179
22132180 # validation
22142181 # Note: The parameters involved in the validation are not verified in their own getters.
22152182 if enable_validation :
2216- if outbound_type in [
2217- CONST_OUTBOUND_TYPE_USER_DEFINED_ROUTING ,
2183+ if not read_from_mc and outbound_type is not None and outbound_type not in [
2184+ CONST_OUTBOUND_TYPE_LOAD_BALANCER ,
22182185 CONST_OUTBOUND_TYPE_MANAGED_NAT_GATEWAY ,
22192186 CONST_OUTBOUND_TYPE_USER_ASSIGNED_NAT_GATEWAY ,
2187+ CONST_OUTBOUND_TYPE_USER_DEFINED_ROUTING ,
2188+ "none"
22202189 ]:
2221- if safe_lower (self ._get_load_balancer_sku (enable_validation = False )) == CONST_LOAD_BALANCER_SKU_BASIC :
2190+ raise InvalidArgumentValueError (
2191+ "Invalid outbound type, supported values are loadBalancer, managedNATGateway, userAssignedNATGateway and "
2192+ "userDefinedRouting. Please refer to "
2193+ "https://learn.microsoft.com/en-us/azure/aks/egress-outboundtype#updating-outboundtype-after-cluster-creation " # pylint:disable=line-too-long
2194+ "for more details."
2195+ )
2196+ if isBasicSKULb :
2197+ if outbound_type is not None :
22222198 raise InvalidArgumentValueError (
2223- "userDefinedRouting doesn't support basic load balancer sku"
2199+ "{outbound_type} doesn't support basic load balancer sku" . format ( outbound_type = outbound_type )
22242200 )
2201+ return outbound_type # basic sku lb doesn't support outbound type
22252202
2226- if outbound_type in [
2227- CONST_OUTBOUND_TYPE_USER_DEFINED_ROUTING ,
2228- CONST_OUTBOUND_TYPE_USER_ASSIGNED_NAT_GATEWAY ,
2229- ]:
2230- if self .get_vnet_subnet_id () in ["" , None ]:
2231- raise RequiredArgumentMissingError (
2232- "--vnet-subnet-id must be specified for userDefinedRouting and it must "
2233- "be pre-configured with a route table with egress rules"
2234- )
2235-
2236- if outbound_type != CONST_OUTBOUND_TYPE_LOAD_BALANCER :
2237- if (
2238- self .get_load_balancer_managed_outbound_ip_count () or
2239- self .get_load_balancer_managed_outbound_ipv6_count () or
2240- self .get_load_balancer_outbound_ips () or
2241- self .get_load_balancer_outbound_ip_prefixes ()
2242- ):
2243- raise MutuallyExclusiveArgumentError (
2244- outbound_type + " doesn't support customizing "
2245- "a standard load balancer with IP addresses"
2246- )
2247- if outbound_type != CONST_OUTBOUND_TYPE_MANAGED_NAT_GATEWAY :
2248- if (
2249- self .get_nat_gateway_managed_outbound_ip_count ()
2250- ):
2251- raise MutuallyExclusiveArgumentError (
2252- outbound_type + " doesn't support customizing "
2253- "a standard nat gateway with IP addresses"
2254- )
2203+ if outbound_type == CONST_OUTBOUND_TYPE_USER_DEFINED_ROUTING :
2204+ if self .get_vnet_subnet_id () in ["" , None ]:
2205+ raise RequiredArgumentMissingError (
2206+ "--vnet-subnet-id must be specified for userDefinedRouting and it must "
2207+ "be pre-configured with a route table with egress rules"
2208+ )
2209+ if outbound_type == CONST_OUTBOUND_TYPE_USER_ASSIGNED_NAT_GATEWAY :
2210+ if self .get_vnet_subnet_id () in ["" , None ]:
2211+ raise RequiredArgumentMissingError (
2212+ "--vnet-subnet-id must be specified for userAssignedNATGateway and it must "
2213+ "be pre-configured with a NAT gateway with outbound ips"
2214+ )
2215+ if outbound_type == CONST_OUTBOUND_TYPE_MANAGED_NAT_GATEWAY :
2216+ if self .get_vnet_subnet_id () not in ["" , None ]:
2217+ raise InvalidArgumentValueError (
2218+ "--vnet-subnet-id cannot be specified for managedNATGateway"
2219+ )
2220+ if outbound_type != CONST_OUTBOUND_TYPE_LOAD_BALANCER :
2221+ if (
2222+ self .get_load_balancer_managed_outbound_ip_count () or
2223+ self .get_load_balancer_managed_outbound_ipv6_count () or
2224+ self .get_load_balancer_outbound_ips () or
2225+ self .get_load_balancer_outbound_ip_prefixes ()
2226+ ):
2227+ raise MutuallyExclusiveArgumentError (
2228+ outbound_type + " type doesn't support customizing "
2229+ "the standard load balancer ips"
2230+ )
2231+ if (
2232+ self .get_load_balancer_idle_timeout () or
2233+ self .get_load_balancer_outbound_ports ()
2234+ ):
2235+ raise MutuallyExclusiveArgumentError (
2236+ outbound_type + " type doesn't support customizing "
2237+ "the standard load balancer config"
2238+ )
2239+ if outbound_type != CONST_OUTBOUND_TYPE_MANAGED_NAT_GATEWAY :
2240+ if (
2241+ self .get_nat_gateway_managed_outbound_ip_count () or
2242+ self .get_nat_gateway_idle_timeout ()
2243+ ):
2244+ raise MutuallyExclusiveArgumentError (
2245+ outbound_type + " type doesn't support customizing "
2246+ "the standard nat gateway ips"
2247+ )
22552248 return outbound_type
22562249
22572250 def get_outbound_type (
@@ -2264,16 +2257,6 @@ def get_outbound_type(
22642257 When outbound_type is not assigned, dynamic completion will be triggerd. By default, the value is set to
22652258 CONST_OUTBOUND_TYPE_LOAD_BALANCER.
22662259
2267- This function will verify the parameter by default. If the value of outbound_type is
2268- CONST_OUTBOUND_TYPE_USER_DEFINED_ROUTING, the following checks will be performed. If load_balancer_sku is set
2269- to basic, an InvalidArgumentValueError will be raised. If vnet_subnet_id is not assigned,
2270- a RequiredArgumentMissingError will be raised. If any of load_balancer_managed_outbound_ip_count,
2271- load_balancer_outbound_ips or load_balancer_outbound_ip_prefixes is assigned, a MutuallyExclusiveArgumentError
2272- will be raised.
2273-
2274- This function supports the option of load_balancer_profile, if provided, when verifying loadbalancer-related
2275- parameters, the value in load_balancer_profile will be used for validation.
2276-
22772260 :return: string or None
22782261 """
22792262 return self ._get_outbound_type (
@@ -7189,29 +7172,6 @@ def update_outbound_type_in_network_profile(self, mc: ManagedCluster) -> Managed
71897172
71907173 outboundType = self .context .get_outbound_type ()
71917174 if outboundType :
7192- vnet_subnet_id = self .context .get_vnet_subnet_id ()
7193- if vnet_subnet_id is None and outboundType not in [
7194- CONST_OUTBOUND_TYPE_LOAD_BALANCER ,
7195- CONST_OUTBOUND_TYPE_MANAGED_NAT_GATEWAY ,
7196- CONST_OUTBOUND_TYPE_USER_DEFINED_ROUTING
7197- ]:
7198- raise InvalidArgumentValueError (
7199- "Invalid outbound type, supported values are loadBalancer, managedNATGateway and "
7200- "userDefinedRouting. Please refer to "
7201- "https://learn.microsoft.com/en-us/azure/aks/egress-outboundtype#updating-outboundtype-after-cluster-creation " # pylint:disable=line-too-long
7202- "for more details."
7203- )
7204- if vnet_subnet_id is not None and outboundType not in [
7205- CONST_OUTBOUND_TYPE_LOAD_BALANCER ,
7206- CONST_OUTBOUND_TYPE_USER_ASSIGNED_NAT_GATEWAY ,
7207- CONST_OUTBOUND_TYPE_USER_DEFINED_ROUTING
7208- ]:
7209- raise InvalidArgumentValueError (
7210- "Invalid outbound type, supported values are loadBalancer, userAssignedNATGateway and "
7211- "userDefinedRouting. Please refer to "
7212- "https://learn.microsoft.com/en-us/azure/aks/egress-outboundtype#updating-outboundtype-after-cluster-creation " # pylint:disable=line-too-long
7213- "for more details."
7214- )
72157175 mc .network_profile .outbound_type = outboundType
72167176 return mc
72177177
@@ -7262,9 +7222,9 @@ def update_nat_gateway_profile(self, mc: ManagedCluster) -> ManagedCluster:
72627222 mc .network_profile .nat_gateway_profile = None
72637223 else :
72647224 mc .network_profile .nat_gateway_profile = _update_nat_gateway_profile (
7265- self .context .get_nat_gateway_managed_outbound_ip_count (),
7266- self .context .get_nat_gateway_idle_timeout (),
7267- mc .network_profile .nat_gateway_profile ,
7225+ managed_outbound_ip_count = self .context .get_nat_gateway_managed_outbound_ip_count (),
7226+ idle_timeout = self .context .get_nat_gateway_idle_timeout (),
7227+ profile = mc .network_profile .nat_gateway_profile ,
72687228 models = self .models .nat_gateway_models ,
72697229 )
72707230 return mc
0 commit comments