Skip to content

Conversation

@yitaopan
Copy link
Member

@yitaopan yitaopan commented Jul 29, 2025


This checklist is used to make sure that common guidelines for a pull request are followed.

Related command

General Guidelines

  • Have you run azdev style <YOUR_EXT> locally? (pip install azdev required)
  • Have you run python scripts/ci/test_index.py -q locally? (pip install wheel==0.30.0 required)
  • My extension version conforms to the Extension version schema

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.json automatically.
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.

@azure-client-tools-bot-prd
Copy link

azure-client-tools-bot-prd bot commented Jul 29, 2025

⚠️Azure CLI Extensions Breaking Change Test
⚠️containerapp
rule cmd_name rule_message suggest_message
⚠️ 1006 - ParaAdd containerapp sessionpool create cmd containerapp sessionpool create added parameter lifecycle_type
⚠️ 1006 - ParaAdd containerapp sessionpool create cmd containerapp sessionpool create added parameter max_alive_period
⚠️ 1006 - ParaAdd containerapp sessionpool update cmd containerapp sessionpool update added parameter lifecycle_type
⚠️ 1006 - ParaAdd containerapp sessionpool update cmd containerapp sessionpool update added parameter max_alive_period

@azure-client-tools-bot-prd
Copy link

Hi @yitaopan,
Please write the description of changes which can be perceived by customers into HISTORY.rst.
If you want to release a new extension version, please update the version in setup.py as well.

@yonzhan
Copy link
Collaborator

yonzhan commented Jul 29, 2025

Thank you for your contribution! We will review the pull request and get back to you soon.

@github-actions
Copy link

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).
After that please run the following commands to enable git hooks:

pip install azdev --upgrade
azdev setup -c <your azure-cli repo path> -r <your azure-cli-extensions repo path>

@github-actions
Copy link

CodeGen Tools Feedback Collection

Thank 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

@github-actions
Copy link

github-actions bot commented Jul 29, 2025

Hi @yitaopan

Release Suggestions

Module: containerapp

  • Update VERSION to 1.2.0b4 in src/containerapp/setup.py

Notes

@yitaopan yitaopan changed the title Support lifecycle type [Azure Container Apps] Support session pool onContainerExit lifecycle Jul 30, 2025
@yitaopan yitaopan changed the title [Azure Container Apps] Support session pool onContainerExit lifecycle [Azure Container Apps] Support session pool OnContainerExit lifecycle Jul 30, 2025
@yitaopan yitaopan marked this pull request as ready for review July 30, 2025 08:59
Copilot AI review requested due to automatic review settings July 30, 2025 08:59
Copy link
Contributor

Copilot AI left a 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

@Greedygre
Copy link
Contributor

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 2 pipeline(s).

Comment on lines 540 to 564
# 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}'.")
Copy link
Contributor

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.

Comment on lines 292 to 300
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)
Copy link
Contributor

@Greedygre Greedygre Aug 7, 2025

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")
image

Besides, for containerapp sessionpool update, we can't set the "Timed" as default value for it, because it might override customer's setting.

Comment on lines 180 to 198
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}'.")
Copy link
Contributor

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

@Greedygre
Copy link
Contributor

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 2 pipeline(s).

@Greedygre
Copy link
Contributor

The CI failed due to Microsoft.Network update the api-version from 2024-05-01 to 2024-07-01.
I will raise a PR to update the related recording files.

vcr.errors.CannotOverwriteExistingCassetteException: Can't overwrite existing cassette ('/mnt/vss/_work/1/s/src/containerapp/azext_containerapp/tests/latest/recordings/test_containerappjob_create_with_environment_id.yaml') in your current record mode ('once').
E               No match for the request (<Request (PUT) [https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/clitest.rg000001/providers/Microsoft.Network/virtualNetworks/name000005?api-version=2024-07-01>](https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/clitest.rg000001/providers/Microsoft.Network/virtualNetworks/name000005?api-version=2024-07-01%3E)) was found.
E               Found 3 similar requests with 1 different matcher(s) :
E               
E               1 - (<Request (PUT) [https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/clitest.rg000001/providers/Microsoft.Network/virtualNetworks/name000005?api-version=2024-05-01>).](https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/clitest.rg000001/providers/Microsoft.Network/virtualNetworks/name000005?api-version=2024-05-01%3E).)
E               Matchers succeeded : ['method', 'scheme', 'host', 'port', 'path']
E               Matchers failed :
E               _custom_request_query_matcher - assertion failure :
E               None
E

… into yitaopan/lifecycle-type-oncontainerexit
@yitaopan
Copy link
Member Author

The CI failed due to Microsoft.Network update the api-version from 2024-05-01 to 2024-07-01. I will raise a PR to update the related recording files.

vcr.errors.CannotOverwriteExistingCassetteException: Can't overwrite existing cassette ('/mnt/vss/_work/1/s/src/containerapp/azext_containerapp/tests/latest/recordings/test_containerappjob_create_with_environment_id.yaml') in your current record mode ('once').
E               No match for the request (<Request (PUT) [https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/clitest.rg000001/providers/Microsoft.Network/virtualNetworks/name000005?api-version=2024-07-01>](https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/clitest.rg000001/providers/Microsoft.Network/virtualNetworks/name000005?api-version=2024-07-01%3E)) was found.
E               Found 3 similar requests with 1 different matcher(s) :
E               
E               1 - (<Request (PUT) [https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/clitest.rg000001/providers/Microsoft.Network/virtualNetworks/name000005?api-version=2024-05-01>).](https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/clitest.rg000001/providers/Microsoft.Network/virtualNetworks/name000005?api-version=2024-05-01%3E).)
E               Matchers succeeded : ['method', 'scheme', 'host', 'port', 'path']
E               Matchers failed :
E               _custom_request_query_matcher - assertion failure :
E               None
E

Thank you very much, I've updated with the latest main branch

@Greedygre
Copy link
Contributor

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 2 pipeline(s).

@yanzhudd yanzhudd changed the title [Azure Container Apps] Support session pool OnContainerExit lifecycle [Container App] Support session pool OnContainerExit lifecycle Aug 22, 2025
@yanzhudd yanzhudd merged commit 8f6f15d into Azure:main Aug 22, 2025
24 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants