-
Notifications
You must be signed in to change notification settings - Fork 1.5k
[Container App] Support session pool OnContainerExit lifecycle #9015
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
Changes from 24 commits
3db6bc5
bb1b284
7dde7ab
51d4e02
281999d
6d0689b
9176d80
d2ca012
964e9fa
5436ff6
142466b
57b98c6
2ed8341
dcb6ccd
c809691
ec0dd2d
11bd642
4edbfab
a8d72b6
0989654
7d637b4
05547b1
7e79b89
5119df9
f287afd
16ffdc4
918343b
71e704f
da4426e
010ee8e
8ca3b21
6ff2d19
1a52db5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -46,6 +46,11 @@ class ContainerType(Enum): | |
| NodeLTS = 3 | ||
|
|
||
|
|
||
| class LifecycleType(Enum): | ||
| Timed = 0 | ||
| OnContainerExit = 1 | ||
|
|
||
|
|
||
| class SessionPoolPreviewDecorator(BaseResource): | ||
| def __init__(self, cmd: AzCliCommand, client: Any, raw_parameters: Dict, models: str): | ||
| super().__init__(cmd, client, raw_parameters, models) | ||
|
|
@@ -70,6 +75,18 @@ def get_argument_container_type(self): | |
| def set_argument_container_type(self, container_type): | ||
| return self.set_param('container_type', container_type) | ||
|
|
||
| def get_argument_lifecycle_type(self): | ||
| return self.get_param('lifecycle_type') | ||
|
|
||
| def set_argument_lifecycle_type(self, lifecycle_type): | ||
| return self.set_param('lifecycle_type', lifecycle_type) | ||
|
|
||
| def get_argument_max_alive_period(self): | ||
| return self.get_param('max_alive_period') | ||
|
|
||
| def set_argument_max_alive_period(self, max_alive_period): | ||
| return self.set_param('max_alive_period', max_alive_period) | ||
|
|
||
| def get_argument_cooldown_period_in_seconds(self): | ||
| return self.get_param('cooldown_period') | ||
|
|
||
|
|
@@ -160,6 +177,25 @@ def validate_arguments(self): | |
| else: | ||
| if environment_name is not None: | ||
| raise ValidationError(f"Do not pass environment name when using container type {container_type}") | ||
| if self.get_argument_lifecycle_type() is not None and \ | ||
| self.get_argument_lifecycle_type().lower() != LifecycleType.Timed.name.lower(): | ||
| raise ValidationError(f"The container type {container_type} only supports lifecycle type '{LifecycleType.Timed.name}'.") | ||
| if self.get_argument_max_alive_period() is not None: | ||
| raise ValidationError(f"The container type {container_type} does not support --max-alive-period.") | ||
|
|
||
| if self.get_argument_max_alive_period() is not None and \ | ||
| self.get_argument_cooldown_period_in_seconds() is not None: | ||
| raise ValidationError("--max-alive-period and --cooldown-period cannot be set at the same time.") | ||
|
|
||
| if self.get_argument_max_alive_period() is not None and \ | ||
| self.get_argument_lifecycle_type() is not None and \ | ||
| self.get_argument_lifecycle_type().lower() != LifecycleType.OnContainerExit.name.lower(): | ||
| raise ValidationError(f"--max-alive-period can only be set when --lifecycle-type is '{LifecycleType.OnContainerExit.name}'.") | ||
|
|
||
| if self.get_argument_cooldown_period_in_seconds() is not None and \ | ||
| self.get_argument_lifecycle_type() is not None and \ | ||
| self.get_argument_lifecycle_type().lower() != LifecycleType.Timed.name.lower(): | ||
| raise ValidationError(f"--cooldown-period can only be set when --lifecycle-type is '{LifecycleType.Timed.name}'.") | ||
|
||
|
|
||
| def construct_payload(self): | ||
| self.session_pool_def["location"] = self.get_argument_location() | ||
|
|
@@ -253,12 +289,28 @@ def set_up_managed_identity(self): | |
| self.session_pool_def["identity"] = identity_def | ||
|
|
||
| def set_up_dynamic_configuration(self): | ||
| if self.get_argument_cooldown_period_in_seconds() is None: | ||
| if self.get_argument_lifecycle_type() is None: | ||
| # Auto infer lifecycle type | ||
| if self.get_argument_cooldown_period_in_seconds() is not None: | ||
| self.set_argument_lifecycle_type(LifecycleType.Timed.name) | ||
| elif self.get_argument_max_alive_period() is not None: | ||
| self.set_argument_lifecycle_type(LifecycleType.OnContainerExit.name) | ||
| else: | ||
| # Default to 'Timed' | ||
| self.set_argument_lifecycle_type(LifecycleType.Timed.name) | ||
|
||
|
|
||
| if self.get_argument_lifecycle_type().lower() == LifecycleType.Timed.name.lower() and \ | ||
| self.get_argument_cooldown_period_in_seconds() is None: | ||
| self.set_argument_cooldown_period_in_seconds(300) | ||
|
|
||
| if self.get_argument_lifecycle_type().lower() == LifecycleType.OnContainerExit.name.lower() and \ | ||
| self.get_argument_max_alive_period() is None: | ||
| self.set_argument_max_alive_period(3600) | ||
Greedygre marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| dynamic_pool_def = {} | ||
| lifecycle_config_def = {} | ||
| lifecycle_config_def["lifecycleType"] = "Timed" | ||
| lifecycle_config_def["lifecycleType"] = self.get_argument_lifecycle_type() | ||
| lifecycle_config_def["maxAlivePeriodInSeconds"] = self.get_argument_max_alive_period() | ||
yitaopan marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| lifecycle_config_def["cooldownPeriodInSeconds"] = self.get_argument_cooldown_period_in_seconds() | ||
yitaopan marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| dynamic_pool_def["lifecycleConfiguration"] = lifecycle_config_def | ||
|
|
||
|
|
@@ -483,11 +535,45 @@ def set_up_managed_identity_settings(self): | |
| safe_set(self.session_pool_def, "properties", "managedIdentitySettings", value=managed_identity_settings) | ||
|
|
||
| def set_up_dynamic_configuration(self): | ||
| lifecycle_config_def = {} | ||
|
|
||
| # Validate unsupported arguments with a certain lifecycle type | ||
| if self.get_argument_max_alive_period() is not None and \ | ||
| self.get_argument_lifecycle_type() is not None and \ | ||
| self.get_argument_lifecycle_type().lower() != LifecycleType.OnContainerExit.name.lower(): | ||
| raise ValidationError(f"--max-alive-period can only be set when --lifecycle-type is '{LifecycleType.OnContainerExit.name}'.") | ||
| if self.get_argument_cooldown_period_in_seconds() is not None and \ | ||
| self.get_argument_lifecycle_type() is not None and \ | ||
| self.get_argument_lifecycle_type().lower() != LifecycleType.Timed.name.lower(): | ||
| raise ValidationError(f"--cooldown-period can only be set when --lifecycle-type is '{LifecycleType.Timed.name}'.") | ||
|
|
||
| # Validate that max_alive_period and cooldown_period are not set at the same time | ||
| if self.get_argument_max_alive_period() is not None and \ | ||
| self.get_argument_cooldown_period_in_seconds() is not None: | ||
| raise ValidationError("--max-alive-period and --cooldown-period cannot be set at the same time.") | ||
|
|
||
| # Validate unsupported arguments with existing lifecycle type | ||
| current_lifecycle_type = safe_get(self.existing_pool_def, "properties", "dynamicPoolConfiguration", "lifecycleConfiguration", "lifecycleType") | ||
| if self.get_argument_max_alive_period() is not None and \ | ||
| self.get_argument_lifecycle_type() is None and \ | ||
| current_lifecycle_type.lower() != LifecycleType.OnContainerExit.name.lower(): | ||
| raise ValidationError(f"--max-alive-period is not supported for the current --lifecycle-type '{current_lifecycle_type}'.") | ||
| if self.get_argument_cooldown_period_in_seconds() is not None and \ | ||
| self.get_argument_lifecycle_type() is None and \ | ||
| current_lifecycle_type.lower() != LifecycleType.Timed.name.lower(): | ||
| raise ValidationError(f"--cooldown-period is not supported for the current --lifecycle-type '{current_lifecycle_type}'.") | ||
|
||
|
|
||
| if self.get_argument_lifecycle_type() is not None: | ||
| lifecycle_config_def["lifecycleType"] = self.get_argument_lifecycle_type() | ||
|
|
||
| if self.get_argument_cooldown_period_in_seconds() is not None: | ||
| dynamic_pool_def = {} | ||
| lifecycle_config_def = {} | ||
| lifecycle_config_def["lifecycleType"] = "Timed" | ||
Greedygre marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| lifecycle_config_def["cooldownPeriodInSeconds"] = self.get_argument_cooldown_period_in_seconds() | ||
|
|
||
| if self.get_argument_max_alive_period() is not None: | ||
| lifecycle_config_def["maxAlivePeriodInSeconds"] = self.get_argument_max_alive_period() | ||
|
|
||
| if lifecycle_config_def: | ||
| dynamic_pool_def = {} | ||
| dynamic_pool_def["lifecycleConfiguration"] = lifecycle_config_def | ||
| safe_set(self.session_pool_def, "properties", "dynamicPoolConfiguration", value=dynamic_pool_def) | ||
|
|
||
|
|
||

Uh oh!
There was an error while loading. Please reload this page.