Skip to content

Commit 8c68569

Browse files
authored
[Containerapp] az containerapp sessionpool create/update: Add health probe support (#9139)
1 parent c68bef2 commit 8c68569

File tree

7 files changed

+21779
-3
lines changed

7 files changed

+21779
-3
lines changed

src/containerapp/HISTORY.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ upcoming
99
* 'az containerapp sessionpool create/update': Support `--lifecycle-type` and `--max-alive-period`
1010
* 'az containerapp up': support for `--kind` parameter
1111
* 'az containerapp env premium-ingress': Deprecate `--min-replicas` and `--max-replicas` parameters, use workload profile scale instead.
12+
* 'az containerapp sessionpool create/update': Support `--probe-yaml`
1213

1314
1.2.0b3
1415
++++++

src/containerapp/azext_containerapp/_help.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2010,6 +2010,11 @@
20102010
az containerapp sessionpool create -n mysessionpool -g MyResourceGroup \\
20112011
--environment MyEnvironment --cpu 0.5 --memory 1Gi --target-port 80 --container-type CustomContainer \\
20122012
--cooldown-period 360 --location eastasia
2013+
- name: Create or update a Session Pool with container type CustomContainer with container probes
2014+
text: |
2015+
az containerapp sessionpool create -n mysessionpool -g MyResourceGroup \\
2016+
--environment MyEnvironment --cpu 0.5 --memory 1Gi --target-port 80 --container-type CustomContainer \\
2017+
--probe-yaml config.yaml --location eastasia
20132018
"""
20142019

20152020
helps['containerapp sessionpool update'] = """
@@ -2019,6 +2024,9 @@
20192024
- name: Update a session pool's max concurrent sessions configuration and image.
20202025
text: |
20212026
az containerapp sessionpool update -n mysessionpool -g MyResourceGroup --max-sessions 20 --image MyNewImage
2027+
- name: Update the container probes of a CustomContainer type session pool.
2028+
text: |
2029+
az containerapp sessionpool update -n mysessionpool -g MyResourceGroup --probe-yaml config.yaml
20222030
"""
20232031

20242032
helps['containerapp sessionpool delete'] = """

src/containerapp/azext_containerapp/_params.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -471,6 +471,7 @@ def load_arguments(self, _):
471471
c.argument('startup_command', nargs='*', options_list=['--command'], help="A list of supported commands on the container that will executed during startup. Space-separated values e.g. \"/bin/queue\" \"mycommand\". Empty string to clear existing values")
472472
c.argument('args', nargs='*', help="A list of container startup command argument(s). Space-separated values e.g. \"-c\" \"mycommand\". Empty string to clear existing values")
473473
c.argument('target_port', type=int, validator=validate_target_port_range, help="The session port used for ingress traffic.")
474+
c.argument('probe_yaml', type=file_type, help='Path to a .yaml file with the configuration of the container probes. Only applicable for Custom Container Session Pool', is_preview=True)
474475

475476
with self.argument_context('containerapp sessionpool', arg_group='Registry') as c:
476477
c.argument('registry_server', validator=validate_registry_server, help="The container registry server hostname, e.g. myregistry.azurecr.io.")

src/containerapp/azext_containerapp/containerapp_sessionpool_decorator.py

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
safe_set, safe_get, _ensure_identity_resource_id)
2929
from azure.cli.command_modules.containerapp._clients import ManagedEnvironmentClient
3030
from azure.cli.command_modules.containerapp._client_factory import handle_non_404_status_code_exception
31+
from azure.cli.command_modules.containerapp._decorator_utils import load_yaml_file
3132
from azure.cli.command_modules.containerapp._utils import is_registry_msi_system
3233
from azure.cli.core.commands.client_factory import get_subscription_id
3334

@@ -156,10 +157,43 @@ def get_argument_system_assigned(self):
156157
def get_argument_user_assigned(self):
157158
return self.get_param("mi_user_assigned")
158159

160+
def get_argument_probe_yaml(self):
161+
return self.get_param("probe_yaml")
162+
159163
# pylint: disable=no-self-use
160164
def get_environment_client(self):
161165
return ManagedEnvironmentClient
162166

167+
def set_up_probes(self):
168+
probes_def = load_yaml_file(self.get_argument_probe_yaml())
169+
if not isinstance(probes_def, dict) or 'probes' not in probes_def:
170+
raise ValidationError("The probe YAML file must be a dictionary containing a 'probes' key.")
171+
172+
probes_list = probes_def.get('probes')
173+
if probes_list is None:
174+
return []
175+
if not isinstance(probes_list, list):
176+
raise ValidationError("The 'probes' key in the probe YAML file must be a list of probes.")
177+
178+
return probes_list
179+
180+
def check_container_related_arguments(self):
181+
container_related_args = {
182+
'--args': self.get_argument_args(),
183+
'--command': self.get_argument_startup_command(),
184+
'--container-name': self.get_argument_container_name(),
185+
'--cpu': self.get_argument_cpu(),
186+
'--env-vars': self.get_argument_env_vars(),
187+
'--image or -i': self.get_argument_image(),
188+
'--memory': self.get_argument_memory(),
189+
'--probe-yaml': self.get_argument_probe_yaml(),
190+
'--target-port': self.get_argument_target_port(),
191+
}
192+
193+
for arg_name, arg_value in container_related_args.items():
194+
if arg_value is not None:
195+
raise ValidationError(f"'{arg_name}' can not be set when container type is not 'CustomContainer'.")
196+
163197

164198
class SessionPoolCreateDecorator(SessionPoolPreviewDecorator):
165199
def validate_arguments(self):
@@ -339,6 +373,8 @@ def set_up_container(self):
339373
if self.get_argument_args() is not None:
340374
container_def["args"] = self.get_argument_args()
341375
container_def["resources"] = self.set_up_resource()
376+
if self.get_argument_probe_yaml() is not None:
377+
container_def["probes"] = self.set_up_probes()
342378
return container_def
343379

344380
def set_up_secrets(self):
@@ -475,6 +511,10 @@ def validate_arguments(self):
475511
current_lifecycle_type.lower() != LifecycleType.Timed.name.lower():
476512
raise ValidationError(f"--cooldown-period is not supported for the current --lifecycle-type '{current_lifecycle_type}'.")
477513

514+
# Validate container related arguments
515+
if safe_get(self.existing_pool_def, "properties", "containerType").lower() != ContainerType.CustomContainer.name.lower():
516+
self.check_container_related_arguments()
517+
478518
def update(self):
479519
try:
480520
return self.client.update(
@@ -623,6 +663,8 @@ def set_up_container(self, customer_container_template):
623663
container_def["resources"]["cpu"] = self.get_argument_cpu()
624664
if self.get_argument_memory() is not None:
625665
container_def["resources"]["memory"] = self.get_argument_memory()
666+
if self.get_argument_probe_yaml() is not None:
667+
container_def["probes"] = self.set_up_probes()
626668
return container_def
627669

628670
def set_up_registry_auth_configuration(self, secrets_def, customer_container_template):
@@ -677,7 +719,8 @@ def has_container_change(self):
677719
self.get_argument_memory() is not None or
678720
self.get_argument_env_vars() is not None or
679721
self.get_argument_args() is not None or
680-
self.get_argument_startup_command() is not None)
722+
self.get_argument_startup_command() is not None or
723+
self.get_argument_probe_yaml() is not None)
681724

682725
def has_registry_change(self):
683726
return (self.get_argument_registry_server() is not None or

src/containerapp/azext_containerapp/custom.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3117,7 +3117,8 @@ def create_session_pool(cmd,
31173117
registry_user=None,
31183118
mi_user_assigned=None,
31193119
registry_identity=None,
3120-
mi_system_assigned=False):
3120+
mi_system_assigned=False,
3121+
probe_yaml=None):
31213122
raw_parameters = locals()
31223123
session_pool_decorator = SessionPoolCreateDecorator(
31233124
cmd=cmd,
@@ -3158,7 +3159,8 @@ def update_session_pool(cmd,
31583159
registry_user=None,
31593160
mi_user_assigned=None,
31603161
registry_identity=None,
3161-
mi_system_assigned=False):
3162+
mi_system_assigned=False,
3163+
probe_yaml=None):
31623164
raw_parameters = locals()
31633165
session_pool_decorator = SessionPoolUpdateDecorator(
31643166
cmd=cmd,

0 commit comments

Comments
 (0)