@@ -2053,19 +2053,6 @@ def get_nat_gateway_managed_outbound_ip_count(self) -> Union[int, None]:
2053
2053
"""
2054
2054
# read the original value passed by the command
2055
2055
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
-
2069
2056
# this parameter does not need dynamic completion
2070
2057
# this parameter does not need validation
2071
2058
return nat_gateway_managed_outbound_ip_count
@@ -2079,17 +2066,6 @@ def get_nat_gateway_idle_timeout(self) -> Union[int, None]:
2079
2066
"""
2080
2067
# read the original value passed by the command
2081
2068
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
- )
2093
2069
2094
2070
# this parameter does not need dynamic completion
2095
2071
# this parameter does not need validation
@@ -2171,23 +2147,19 @@ def _get_outbound_type(
2171
2147
CONST_OUTBOUND_TYPE_LOAD_BALANCER.
2172
2148
2173
2149
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
2175
2151
CONST_OUTBOUND_TYPE_USER_DEFINED_ROUTING, the following checks will be performed. If load_balancer_sku is set
2176
2152
to basic, an InvalidArgumentValueError will be raised. If vnet_subnet_id is not assigned,
2177
2153
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.
2180
2154
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.
2183
2155
2184
2156
:return: string or None
2185
2157
"""
2186
2158
# read the original value passed by the command
2187
2159
outbound_type = self .raw_param .get ("outbound_type" )
2188
2160
# try to read the property value corresponding to the parameter from the `mc` object
2189
2161
read_from_mc = False
2190
- if outbound_type is None and self . decorator_mode != DecoratorMode . CREATE :
2162
+ if outbound_type is None :
2191
2163
if (
2192
2164
self .mc and
2193
2165
self .mc .network_profile and
@@ -2200,58 +2172,79 @@ def _get_outbound_type(
2200
2172
if read_only :
2201
2173
return outbound_type
2202
2174
2175
+ isBasicSKULb = safe_lower (self ._get_load_balancer_sku (enable_validation = False )) == CONST_LOAD_BALANCER_SKU_BASIC
2203
2176
# 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 :
2211
2178
outbound_type = CONST_OUTBOUND_TYPE_LOAD_BALANCER
2212
2179
2213
2180
# validation
2214
2181
# Note: The parameters involved in the validation are not verified in their own getters.
2215
2182
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 ,
2218
2185
CONST_OUTBOUND_TYPE_MANAGED_NAT_GATEWAY ,
2219
2186
CONST_OUTBOUND_TYPE_USER_ASSIGNED_NAT_GATEWAY ,
2187
+ CONST_OUTBOUND_TYPE_USER_DEFINED_ROUTING ,
2188
+ "none"
2220
2189
]:
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 :
2222
2198
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 )
2224
2200
)
2201
+ return outbound_type # basic sku lb doesn't support outbound type
2225
2202
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
+ )
2255
2248
return outbound_type
2256
2249
2257
2250
def get_outbound_type (
@@ -2264,16 +2257,6 @@ def get_outbound_type(
2264
2257
When outbound_type is not assigned, dynamic completion will be triggerd. By default, the value is set to
2265
2258
CONST_OUTBOUND_TYPE_LOAD_BALANCER.
2266
2259
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
-
2277
2260
:return: string or None
2278
2261
"""
2279
2262
return self ._get_outbound_type (
@@ -7189,29 +7172,6 @@ def update_outbound_type_in_network_profile(self, mc: ManagedCluster) -> Managed
7189
7172
7190
7173
outboundType = self .context .get_outbound_type ()
7191
7174
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
- )
7215
7175
mc .network_profile .outbound_type = outboundType
7216
7176
return mc
7217
7177
@@ -7262,9 +7222,9 @@ def update_nat_gateway_profile(self, mc: ManagedCluster) -> ManagedCluster:
7262
7222
mc .network_profile .nat_gateway_profile = None
7263
7223
else :
7264
7224
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 ,
7268
7228
models = self .models .nat_gateway_models ,
7269
7229
)
7270
7230
return mc
0 commit comments