Skip to content
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

Bugfixes (Help, remove app-subnet-resource-id, removed env-var alias, added help text for --name) #28

Merged
merged 27 commits into from
Mar 21, 2022
Merged
Show file tree
Hide file tree
Changes from 25 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
cbd026a
Moved dapr arguments to env as a subgroup.
Mar 15, 2022
e37a07c
Added env variable options.
Mar 15, 2022
b582910
Changed revision mode set to revision set-mode.
Mar 15, 2022
7b33faa
Added env var options to revision copy.
Mar 15, 2022
35e6ca2
Fixed revision copy bug related to env secret refs.
Mar 15, 2022
43e98f5
Changed registry and secret delete to remove. Added registry param he…
Mar 15, 2022
4c47767
Merge branch 'containerapp' into bugfixes
runefa Mar 15, 2022
7c90ee0
Updating warning text.
Mar 16, 2022
8024682
Updated warning text once more.
Mar 16, 2022
3544c8c
Made name optional for revision copy if from-revision flag is passed.
Mar 16, 2022
0f7d7f2
Fixed whitespace style issues.
Mar 16, 2022
858f828
Styled clients and utils to pass pylint.
Mar 17, 2022
570b6cb
Finished client.py pylint fixes.
Mar 17, 2022
01f1bc3
Fixed pylint issues.
Mar 17, 2022
2893b55
Fixed flake8 commands and custom.
Mar 17, 2022
a63dbc6
Fixed flake issues in src.
Mar 17, 2022
5294ff9
Added license header to _sdk_models.
Mar 17, 2022
82f389c
Added confirmation for containerapp delete.
Mar 17, 2022
75327ff
Merged containerapp.
Mar 18, 2022
04b4705
Update helps for identity, revision. Removed env-var alias for set-en…
Mar 18, 2022
1003727
Removed app-subnet-resource-id.
Mar 18, 2022
ea6f741
Merge containerapp.
Mar 18, 2022
ab81c23
Updated infrastructure subnet param help.
Mar 18, 2022
8aa4e0a
Check if containerapp resource exists before attempting to delete.
Mar 18, 2022
e3b5ef6
Added check before deleting managed env.
Mar 18, 2022
d83e276
Changed error types to be more specific.
Mar 21, 2022
f9e3d96
Removed check before deletion. Removed comments.
Mar 21, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions src/containerapp/azext_containerapp/_help.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@
examples:
- name: Restart a revision.
text: |
az containerapp revision restart -n MyContainerapp -g MyResourceGroup --revision-name MyContainerappRevision
az containerapp revision restart -n MyContainerapp -g MyResourceGroup --revision MyContainerappRevision
"""

helps['containerapp revision activate'] = """
Expand All @@ -133,7 +133,7 @@
examples:
- name: Activate a revision.
text: |
az containerapp revision activate -n MyContainerapp -g MyResourceGroup --revision-name MyContainerappRevision
az containerapp revision activate -g MyResourceGroup --revision MyContainerappRevision
"""

helps['containerapp revision deactivate'] = """
Expand All @@ -142,7 +142,7 @@
examples:
- name: Deactivate a revision.
text: |
az containerapp revision deactivate -n MyContainerapp -g MyResourceGroup --revision-name MyContainerappRevision
az containerapp revision deactivate -g MyResourceGroup --revision MyContainerappRevision
"""

helps['containerapp revision set-mode'] = """
Expand All @@ -158,10 +158,15 @@
type: command
short-summary: Create a revision based on a previous revision.
examples:
- name: Create a revision based on a previous revision.
- name: Create a revision based on the latest revision.
text: |
az containerapp revision copy -n MyContainerapp -g MyResourceGroup \\
--cpu 0.75 --memory 1.5Gi
- name: Create a revision based on a previous revision.
text: |
az containerapp revision copy -g MyResourceGroup \\
--from-revision PreviousRevisionName --cpu 0.75 --memory 1.5Gi

"""

helps['containerapp revision copy'] = """
Expand Down Expand Up @@ -231,7 +236,7 @@

helps['containerapp env dapr-component'] = """
type: group
short-summary: Commands to manage Container App environment dapr components.
short-summary: Commmands to manage dapr components on the Container App environment.
"""

helps['containerapp env dapr-component list'] = """
Expand Down Expand Up @@ -284,6 +289,9 @@
- name: Assign system identity.
text: |
az containerapp identity assign
- name: Assign user identity.
text: |
az containerapp identity assign --identities myAssignedId
- name: Assign system and user identity.
text: |
az containerapp identity assign --identities [system] myAssignedId
Expand Down
6 changes: 3 additions & 3 deletions src/containerapp/azext_containerapp/_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def load_arguments(self, _):

with self.argument_context('containerapp') as c:
# Base arguments
c.argument('name', name_type, metavar='NAME', id_part='name')
c.argument('name', name_type, metavar='NAME', id_part='name', help="The name of the Containerapp.")
c.argument('resource_group_name', arg_type=resource_group_name_type)
c.argument('location', arg_type=get_location_type(self.cli_ctx))

Expand All @@ -43,7 +43,7 @@ def load_arguments(self, _):

# Env vars
with self.argument_context('containerapp', arg_group='Environment variables (Creates new revision)') as c:
c.argument('set_env_vars', options_list=['--set-env-vars, --env-vars'], nargs='*', help="A list of environment variable(s) to add to the container. Space-separated values in 'key=value' format. If stored as a secret, value must start with \'secretref:\' followed by the secret name.")
c.argument('set_env_vars', nargs='*', help="A list of environment variable(s) to add to the container. Space-separated values in 'key=value' format. If stored as a secret, value must start with \'secretref:\' followed by the secret name.")
c.argument('remove_env_vars', nargs='*', help="A list of environment variable(s) to remove from container. Space-separated env var name values.")
c.argument('replace_env_vars', nargs='*', help="A list of environment variable(s) to replace from the container. Space-separated values in 'key=value' format. If stored as a secret, value must start with \'secretref:\' followed by the secret name.")
c.argument('remove_all_env_vars', help="Option to remove all environment variable(s) from the container.")
Expand Down Expand Up @@ -97,7 +97,7 @@ def load_arguments(self, _):
c.argument('instrumentation_key', options_list=['--dapr-instrumentation-key'], help='Azure Monitor instrumentation key used by Dapr to export Service to Service communication telemetry')

with self.argument_context('containerapp env', arg_group='Virtual Network') as c:
c.argument('infrastructure_subnet_resource_id', type=str, options_list=['--infrastructure-subnet-resource-id'], help='Resource ID of a subnet for infrastructure components. This subnet must be in the same VNET as the subnet defined in appSubnetResourceId.')
runefa marked this conversation as resolved.
Show resolved Hide resolved
c.argument('infrastructure_subnet_resource_id', type=str, options_list=['--infrastructure-subnet-resource-id'], help='Resource ID of a subnet for infrastructure components and user app containers.')
c.argument('app_subnet_resource_id', type=str, options_list=['--app-subnet-resource-id'], help='Resource ID of a subnet that Container App containers are injected into. This subnet must be in the same VNET as the subnet defined in infrastructureSubnetResourceId.')
c.argument('docker_bridge_cidr', type=str, options_list=['--docker-bridge-cidr'], help='CIDR notation IP range assigned to the Docker bridge. It must not overlap with any Subnet IP ranges or the IP range defined in Platform Reserved CIDR, if defined')
c.argument('platform_reserved_cidr', type=str, options_list=['--platform-reserved-cidr'], help='IP range in CIDR notation that can be reserved for environment infrastructure IP addresses. It must not overlap with any other Subnet IP ranges')
Expand Down
39 changes: 21 additions & 18 deletions src/containerapp/azext_containerapp/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -717,6 +717,11 @@ def list_containerapp(cmd, resource_group_name=None):
def delete_containerapp(cmd, name, resource_group_name):
_validate_subscription_registered(cmd, "Microsoft.App")

try:
runefa marked this conversation as resolved.
Show resolved Hide resolved
ContainerAppClient.show(cmd=cmd, resource_group_name=resource_group_name, name=name)
except CLIError as e:
handle_raw_exception(e)

try:
return ContainerAppClient.delete(cmd=cmd, name=name, resource_group_name=resource_group_name)
except CLIError as e:
Expand All @@ -731,7 +736,7 @@ def create_managed_environment(cmd,
location=None,
instrumentation_key=None,
infrastructure_subnet_resource_id=None,
app_subnet_resource_id=None,
# app_subnet_resource_id=None,
runefa marked this conversation as resolved.
Show resolved Hide resolved
docker_bridge_cidr=None,
platform_reserved_cidr=None,
platform_reserved_dns_ip=None,
Expand All @@ -745,13 +750,13 @@ def create_managed_environment(cmd,
_ensure_location_allowed(cmd, location, "Microsoft.App", "managedEnvironments")

# Microsoft.ContainerService RP registration is required for vnet enabled environments
if infrastructure_subnet_resource_id is not None or app_subnet_resource_id is not None:
if is_valid_resource_id(app_subnet_resource_id):
parsed_app_subnet_resource_id = parse_resource_id(app_subnet_resource_id)
subnet_subscription = parsed_app_subnet_resource_id["subscription"]
_validate_subscription_registered(cmd, "Microsoft.ContainerService", subnet_subscription)
else:
raise ValidationError('Subnet resource ID is invalid.')
# if infrastructure_subnet_resource_id is not None or app_subnet_resource_id is not None:
# if is_valid_resource_id(app_subnet_resource_id):
runefa marked this conversation as resolved.
Show resolved Hide resolved
# parsed_app_subnet_resource_id = parse_resource_id(app_subnet_resource_id)
# subnet_subscription = parsed_app_subnet_resource_id["subscription"]
# _validate_subscription_registered(cmd, "Microsoft.ContainerService", subnet_subscription)
# else:
# raise ValidationError('Subnet resource ID is invalid.')

if logs_customer_id is None or logs_key is None:
logs_customer_id, logs_key = _generate_log_analytics_if_not_provided(cmd, logs_customer_id, logs_key, location, resource_group_name)
Expand All @@ -773,19 +778,12 @@ def create_managed_environment(cmd,
if instrumentation_key is not None:
managed_env_def["properties"]["daprAIInstrumentationKey"] = instrumentation_key

if infrastructure_subnet_resource_id or app_subnet_resource_id or docker_bridge_cidr or platform_reserved_cidr or platform_reserved_dns_ip:
if infrastructure_subnet_resource_id or docker_bridge_cidr or platform_reserved_cidr or platform_reserved_dns_ip:
vnet_config_def = VnetConfigurationModel

if infrastructure_subnet_resource_id is not None:
if not app_subnet_resource_id:
raise ValidationError('App subnet resource ID needs to be supplied with infrastructure subnet resource ID.')
vnet_config_def["infrastructureSubnetId"] = infrastructure_subnet_resource_id

if app_subnet_resource_id is not None:
if not infrastructure_subnet_resource_id:
raise ValidationError('Infrastructure subnet resource ID needs to be supplied with app subnet resource ID.')
vnet_config_def["runtimeSubnetId"] = app_subnet_resource_id

if docker_bridge_cidr is not None:
vnet_config_def["dockerBridgeCidr"] = docker_bridge_cidr

Expand All @@ -798,8 +796,8 @@ def create_managed_environment(cmd,
managed_env_def["properties"]["vnetConfiguration"] = vnet_config_def

if internal_only:
if not infrastructure_subnet_resource_id or not app_subnet_resource_id:
raise ValidationError('Infrastructure subnet resource ID and App subnet resource ID need to be supplied for internal only environments.')
if not infrastructure_subnet_resource_id:
raise ValidationError('Infrastructure subnet resource ID needs to be supplied for internal only environments.')
managed_env_def["properties"]["internalLoadBalancerEnabled"] = True

try:
Expand Down Expand Up @@ -849,6 +847,11 @@ def list_managed_environments(cmd, resource_group_name=None):
def delete_managed_environment(cmd, name, resource_group_name, no_wait=False):
_validate_subscription_registered(cmd, "Microsoft.App")

try:
runefa marked this conversation as resolved.
Show resolved Hide resolved
ManagedEnvironmentClient.show(cmd=cmd, resource_group_name=resource_group_name, name=name)
except CLIError as e:
handle_raw_exception(e)

try:
return ManagedEnvironmentClient.delete(cmd=cmd, name=name, resource_group_name=resource_group_name, no_wait=no_wait)
except CLIError as e:
Expand Down