-
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
[Container App] Support session pool OnContainerExit lifecycle #9015
Conversation
… into yitaopan/lifecycle-type-oncontainerexit
|
| rule | cmd_name | rule_message | suggest_message |
|---|---|---|---|
| containerapp sessionpool create | cmd containerapp sessionpool create added parameter lifecycle_type |
||
| containerapp sessionpool create | cmd containerapp sessionpool create added parameter max_alive_period |
||
| containerapp sessionpool update | cmd containerapp sessionpool update added parameter lifecycle_type |
||
| containerapp sessionpool update | cmd containerapp sessionpool update added parameter max_alive_period |
|
Hi @yitaopan, |
|
Thank you for your contribution! We will review the pull request and get back to you soon. |
|
The git hooks are available for azure-cli and azure-cli-extensions repos. They could help you run required checks before creating the PR. Please sync the latest code with latest dev branch (for azure-cli) or main branch (for azure-cli-extensions). pip install azdev --upgrade
azdev setup -c <your azure-cli repo path> -r <your azure-cli-extensions repo path>
|
CodeGen Tools Feedback CollectionThank you for using our CodeGen tool. We value your feedback, and we would like to know how we can improve our product. Please take a few minutes to fill our codegen survey |
|
Hi @yitaopan Release SuggestionsModule: containerapp
Notes
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds support for the OnContainerExit lifecycle type in Azure Container Apps session pools, expanding beyond the existing Timed lifecycle. The implementation adds new parameters --lifecycle-type and --max-alive-period to control session lifecycle behavior.
Key changes:
- Added OnContainerExit lifecycle type as an alternative to the existing Timed lifecycle
- Introduced max-alive-period parameter for OnContainerExit lifecycle management
- Enhanced validation to ensure lifecycle parameters are used correctly
Reviewed Changes
Copilot reviewed 5 out of 9 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
_params.py |
Added new CLI parameters for lifecycle-type and max-alive-period with help text |
custom.py |
Extended function signatures to accept the new lifecycle parameters |
containerapp_sessionpool_decorator.py |
Implemented core logic for OnContainerExit lifecycle with validation and configuration |
test_containerapp_sessionpool.py |
Added comprehensive test case for OnContainerExit lifecycle functionality |
HISTORY.rst |
Updated changelog to document the new feature |
src/containerapp/azext_containerapp/containerapp_sessionpool_decorator.py
Show resolved
Hide resolved
src/containerapp/azext_containerapp/containerapp_sessionpool_decorator.py
Show resolved
Hide resolved
src/containerapp/azext_containerapp/containerapp_sessionpool_decorator.py
Outdated
Show resolved
Hide resolved
… into yitaopan/lifecycle-type-oncontainerexit
… into yitaopan/lifecycle-type-oncontainerexit
|
/azp run |
|
Azure Pipelines successfully started running 2 pipeline(s). |
Co-authored-by: Greedygre <[email protected]>
src/containerapp/azext_containerapp/containerapp_sessionpool_decorator.py
Show resolved
Hide resolved
| # 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}'.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's create a function name validate_arguments and set these validation in it.
| 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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @yitaopan
We should set a default value for lifecycle-type in the description, then we don't need this for create:
And we will throw f"--max-alive-period can only be set when --lifecycle-type is '{LifecycleType.OnContainerExit.name}'." error when customer set --max-alive-period base on the validation code, which is as expected.
with self.argument_context('containerapp sessionpool create', arg_group='Configuration') as c:
c.argument('lifecycle_type', arg_type=get_enum_type(["Timed", "OnContainerExit"]), help="The lifecycle type of the Session Pool", default='Timed')
with self.argument_context('containerapp sessionpool update', arg_group='Configuration') as c:
c.argument('lifecycle_type', arg_type=get_enum_type(["Timed", "OnContainerExit"]), help="The lifecycle type of the Session Pool")
Besides, for containerapp sessionpool update, we can't set the "Timed" as default value for it, because it might override customer's setting.
| 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}'.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as https://github.com/Azure/azure-cli-extensions/pull/9015/files#r2259224744
Recommend to add validate_arguments and move the validation logic in it.
Thanks
… into yitaopan/lifecycle-type-oncontainerexit
… into yitaopan/lifecycle-type-oncontainerexit
|
/azp run |
|
Azure Pipelines successfully started running 2 pipeline(s). |
|
The CI failed due to Microsoft.Network update the api-version from 2024-05-01 to 2024-07-01. |
… into yitaopan/lifecycle-type-oncontainerexit
Thank you very much, I've updated with the latest main branch |
|
/azp run |
|
Azure Pipelines successfully started running 2 pipeline(s). |
This checklist is used to make sure that common guidelines for a pull request are followed.
Related command
General Guidelines
azdev style <YOUR_EXT>locally? (pip install azdevrequired)python scripts/ci/test_index.py -qlocally? (pip install wheel==0.30.0required)For new extensions:
About Extension Publish
There is a pipeline to automatically build, upload and publish extension wheels.
Once your pull request is merged into main branch, a new pull request will be created to update
src/index.jsonautomatically.You only need to update the version information in file setup.py and historical information in file HISTORY.rst in your PR but do not modify
src/index.json.